Skip to content

Commit 4420a82

Browse files
committed
🆕 Add :space-after-indicator? option to indeterminate progress indicator
1 parent bbd1a2b commit 4420a82

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

src/progress/indeterminate.clj

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,13 @@
117117
"Indeterminate progress indicator logic, for use in a `future` or `Thread` or
118118
wotnot."
119119
([] (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}}]
126127
(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)
127128
; Setup logic
128129
(ansi/save-cursor!)
@@ -131,8 +132,8 @@
131132
(flush) ; Flush any outstanding I/O to stdout before we start animating
132133
; Main animation loop
133134
(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 " "))
136137
(ansi/show-cursor!)
137138
(flush) ; Flush I/O to stdout at least once per loop
138139
(when (pos? delay-in-ms) (Thread/sleep delay-in-ms))
@@ -195,7 +196,12 @@
195196
* `:attributes` - the attributes of the indeterminate progress indicator
196197
(default is `[:default]`) - see [the `jansi-clj`
197198
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`)"
199205
([f] (animatef! nil f))
200206
([opts f]
201207
(when f
@@ -227,7 +233,12 @@
227233
* `:attributes` - the attributes of the indeterminate progress indicator
228234
(default is `[:default]`) - see [the `jansi-clj`
229235
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`)"
231242
[& body]
232243
(if (= :opts (first body))
233244
`(animatef! ~(second body) (fn [] ~@(rest (rest body))))

test/progress/indeterminate_test.clj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@
6969
(testing "Custom attributes"
7070
(is (= nil (pi/animate! :opts {:attributes [:strikethrough :bold :underline]} (Thread/sleep 250)))))
7171

72+
(testing "No space after indicator"
73+
(is (= nil (pi/animate! :opts {:space-after-indicator? false} (Thread/sleep 250)))))
74+
7275
(testing "Custom everything"
7376
(is (= nil (pi/animate! :opts {:frames (:box-fade pi/styles)
7477
:delay-in-ms (/ pi/default-delay-ms 4) ; Hyperspeed!

0 commit comments

Comments
 (0)