-
Notifications
You must be signed in to change notification settings - Fork 0
/
speedo-vars.el
194 lines (168 loc) · 7.49 KB
/
speedo-vars.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
;;; speedo-vars.el --- Settings and variables -*- lexical-binding: t; -*-
;; Copyright (C) 2021-2024 Nicholas Vollmer
;; Author: Nicholas Vollmer
;; Keywords:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(defgroup speedo nil
"Speedo: lightweight split timer."
:group 'applications
:prefix "speedo-")
;;; Customizations
(defcustom speedo-buffer "*speedo*"
"Buffer to display splits."
:type 'string
:group 'speedo)
(defcustom speedo-compact-separator ?-
"Separates last segment when symbol `speedo-compact-mode' is non-nil.
It may be any of the following values:
- a character
The character is repeated across the length of the split table line.
- a string
The literal string is inserted on a line before the last segment.
- a function
The function is called with no arguments and must return a string."
:type (or 'character 'string 'function)
:group 'speedo)
(defcustom speedo-comparison-targets '(("Personal Best" . speedo-target-personal-best)
("Best Segments" . speedo-target-best-segments)
("World Record" . speedo-target-world-record)
("Last Attempt" . speedo-target-last-attempt)
("Last Run" . speedo-target-last-run)
("Personal Worst" . speedo-target-personal-worst)
("None" . ignore))
;;best-split-times, average-segments, median-segments, balanced-pb
"Alist of comparison targets.
Each element's car is a cons cell of form: \\=(FN . DESCRIPTION)
FN is a function called with no arguments which returns an attempt.
DESCRIPTION is either a string or a function which returns a string to display
in the UI footer.
`speedo-next-comparison' and `speedo-previous-comparsion' cycle these in order."
:type 'list
:group 'speedo)
(defcustom speedo-confirm-evaluate t
"If non-nil, confirm evaluation of `:config` `speedo--data'."
:type 'boolean
:group 'speedo)
(defcustom speedo-default-splits-file nil
"The default splits file to load when `speedo' is run.
If it is not an absolute path, it is expanded relative to `speedo-directory'."
:type 'file
:group 'speedo)
(defcustom speedo-directory user-emacs-directory
"Default directory to search for and save splits."
:type 'directory
:group 'speedo)
(defcustom speedo-footer-format
'((speedo-global-timer . "%it \n")
(speedo-target . "Comparing Against: %it\n")
(speedo-projected-best . " Projected Best: %it\n")
(speedo-pb-chance . " PB Chance: %it\n")
(speedo-previous-segment . " Previous: %it\n")
(speedo-mistakes . " Mistakes: %it\n"))
"An alist representing the structure of the UI footer.
Each member is of the form (FUNCTION . FORMAT).
Function is a unary function which accepts a timer env object.
It should return a string.
If FORMAT is a string the return value can be interpolated in the string
via the shorthand `%it`.
Alternatively, FORMAT may be a function which accepts the output of
FUNCTION and returns a string."
:type 'alist
:group 'speedo)
(declare-function speedo-footer-colorized-mistakes "speedo")
(defcustom speedo-footer-mistakes-format #'speedo-footer-colorized-mistakes
"Format string for the mistake counter UI.
It may contain one %-escaped reference to the mistake count.
It may aslo be a function which takes the count as it's sole argument and
returns a string."
:type (or 'string 'function)
:group 'speedo)
(defcustom speedo-footer-want-live-segment t
"When non-nil, display time current segment time loss in the footer."
:type 'boolean
:group 'speedo)
(defcustom speedo-footer-live-segment-format " Live Segment: %s\n"
"Format string for current segment time UI.
It may contain one %-escaped reference to the relative time comparing the
current segment's time to the target's time for that segement."
:type 'string
:group 'speedo)
(defcustom speedo-hide-cursor t
"If non-nil, hide the cursor in `speedo-buffer'."
:type 'boolean
:group 'speedo)
(defcustom speedo-highlight-line t
"If non-nil, highlight the current UI line."
:type 'boolean
:group 'speedo)
(defcustom speedo-pre-ui-display-hook nil
"Hook run just before UI display is udpated.
`speedo-buffer' is current."
:type 'hook
:group 'speedo)
(defcustom speedo-post-ui-display-hook nil
"Hook run after UI display is udpated.
`speedo-buffer' is current."
:type 'hook
:group 'speedo)
(defcustom speedo-text-place-holder "-"
"Placeholder text used when no data is available for a field."
:type 'string
:group 'speedo)
(defcustom speedo-compact-segment-limit 10
"Limit of segments to display in command `speedo-compact-mode'.
Note this includes the last segment."
:type 'integer)
;;; Variables
(defvar speedo--state ' "Keeps track of timer/ui state.
Should be any of the following symbols:
- pre
- running
- post")
(defvar speedo--best-segments nil "List of lowest durations for each segment.")
(defvar speedo--comparison-target (car speedo-comparison-targets)
"The current `speedo-comparison-targets' cell.")
(defvar speedo--current-attempt nil "The current attempt.")
(defvar speedo--data nil "Split database.")
(defvar speedo--data-file nil "The filepath of the loaded splits database.")
(defvar speedo-display-functions '(speedo-live-segment)
"Hook run on every tick of the redisplay timer.
Each element is passed a timer env object produced by `speedo--timer-env'.
`speedo-buffer' is current.")
(defvar speedo-footer-display-functions nil
"Hook run on every tick of the redisplay timer.
Each element is passed a timer env object produced by `speedo--timer-env'.
`speedo-buffer' is current.
It is run prior to `speedo-display-functions'.
It is set via `speedo-footer-format' when `speedo--footer' is called.")
(defvar speedo-footer-interpolation-regexp
"\\(?:\\(%[^%]+?\\)\\([[:space:]]\\|\n\\|$\\)\\)"
"Regexp used to interpolate `speedo-footer-format' string.")
(defvar speedo--review nil "Non-nil after run complete, before clear/init.")
(defvar speedo--segment-index -1 "Index of the current segment.")
(defvar speedo--segment-start nil "Timestamp marking new segment start.")
(defvar speedo--target-attempt nil "The cached target attempt.")
(defvar speedo--target-attempts nil "Cache for target attempts.")
(declare-function speedo--formatter-compact "speedo")
(defvar speedo--time-formatter #'speedo--formatter-compact
"Function to format time from timer.
It must accept four arguments: hours, minutes, seconds, milliseconds.")
(defvar speedo--time nil "The global timer.")
(defvar speedo--timer-start nil "When the timer was started.")
(defvar speedo--timer-object nil "Internal timer object. Used for cancelling timer.")
(defvar speedo--ui-timer-object nil "Display timer object.")
(defconst speedo--file-extension ".spd")
(provide 'speedo-vars)
;;; speedo-vars.el ends here