|
117 | 117 | "Indeterminate progress indicator logic, for use in a `future` or `Thread` or |
118 | 118 | wotnot." |
119 | 119 | ([] (indeterminate-progress-indicator nil)) |
120 | | - ([{:keys [delay-in-ms frames fg-colour bg-colour attributes] |
121 | | - :or {delay-in-ms default-delay-ms |
122 | | - frames (default-style styles) |
123 | | - fg-colour :default |
124 | | - bg-colour :default |
125 | | - attributes [:default]}}] |
| 120 | + ([{:keys [delay-in-ms frames fg-colour bg-colour attributes space-after-indicator?] |
| 121 | + :or {delay-in-ms default-delay-ms |
| 122 | + frames (default-style styles) |
| 123 | + fg-colour :default |
| 124 | + bg-colour :default |
| 125 | + attributes [:default] |
| 126 | + space-after-indicator? true}}] |
126 | 127 | (let [delay-in-ms (long (Math/round (double delay-in-ms)))] ; Coerce delay-in-ms to a long (especially if it's a Clojure ratio) |
127 | 128 | ; Setup logic |
128 | 129 | (ansi/save-cursor!) |
|
131 | 132 | (flush) ; Flush any outstanding I/O to stdout before we start animating |
132 | 133 | ; Main animation loop |
133 | 134 | (loop [i 0] |
134 | | - (clojure.core/print (str (ansi/apply-colours-and-attrs fg-colour bg-colour attributes (nth frames i)) |
135 | | - " ")) |
| 135 | + (clojure.core/print (str (ansi/apply-colours-and-attrs fg-colour bg-colour attributes (nth frames i)))) |
| 136 | + (when space-after-indicator? (clojure.core/print " ")) |
136 | 137 | (ansi/show-cursor!) |
137 | 138 | (flush) ; Flush I/O to stdout at least once per loop |
138 | 139 | (when (pos? delay-in-ms) (Thread/sleep delay-in-ms)) |
|
195 | 196 | * `:attributes` - the attributes of the indeterminate progress indicator |
196 | 197 | (default is `[:default]`) - see [the `jansi-clj` |
197 | 198 | docs](https://github.com/xsc/jansi-clj#attributes) for |
198 | | - allowed values" |
| 199 | + allowed values |
| 200 | + * `:space-after-indicator?` - whether a single space character should be |
| 201 | + printed after the indeterminate progress indicator. This |
| 202 | + can be more visually appealing when using Unicode frames as |
| 203 | + it creates some separation with the cursor. |
| 204 | + (default is `true`)" |
199 | 205 | ([f] (animatef! nil f)) |
200 | 206 | ([opts f] |
201 | 207 | (when f |
|
227 | 233 | * `:attributes` - the attributes of the indeterminate progress indicator |
228 | 234 | (default is `[:default]`) - see [the `jansi-clj` |
229 | 235 | docs](https://github.com/xsc/jansi-clj#attributes) for |
230 | | - allowed values" |
| 236 | + allowed values |
| 237 | + * `:space-after-indicator?` - whether a single space character should be |
| 238 | + printed after the indeterminate progress indicator. This |
| 239 | + can be more visually appealing when using Unicode frames as |
| 240 | + it creates some separation with the cursor. |
| 241 | + (default is `true`)" |
231 | 242 | [& body] |
232 | 243 | (if (= :opts (first body)) |
233 | 244 | `(animatef! ~(second body) (fn [] ~@(rest (rest body)))) |
|
0 commit comments