Skip to content

Commit acb63a6

Browse files
authored
Merge pull request #34 from pmonks/issue-32
Fix issue 32
2 parents 582cf9a + 3905997 commit acb63a6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/progress/determinate.clj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060

6161
(defn- redraw-progress-indicator!
6262
"Redraws the progress indicator."
63-
[style style-widths label line width counter? total units new-value]
63+
[style style-widths label line width counter? total digits-in-total units new-value]
6464
; Make sure this code is non re-entrant
6565
(locking lock
6666
(let [percent-complete (/ (double new-value) total)
@@ -75,7 +75,8 @@
7575
fill-cols (clamp 0 body-cols (Math/ceil (* percent-complete body-cols)))
7676
fill-chars (- (Math/ceil (/ fill-cols (:full style-widths))) tip-chars)
7777
empty-cols (- body-cols (* fill-chars (:full style-widths))) ; We do it this way due to rounding
78-
empty-chars (Math/floor (/ empty-cols (:empty style-widths)))]
78+
empty-chars (Math/floor (/ empty-cols (:empty style-widths)))
79+
counter-pad (- digits-in-total (count (str new-value)))]
7980
(when line
8081
(ansi/save-cursor!)
8182
(ansi/hide-cursor!)
@@ -123,7 +124,8 @@
123124
(ansi/apply-colours-and-attrs (:counter-fg-colour style)
124125
(:counter-bg-colour style)
125126
(:counter-attrs style)
126-
(str " " (int new-value) "/" (int total)
127+
(str (s/join (repeat (inc counter-pad) " ")) ; Left pad current counter value
128+
(int new-value) "/" (int total)
127129
(when-not (s/blank? units)
128130
(ansi/apply-colours-and-attrs (:units-fg-colour style)
129131
(:units-bg-colour style)
@@ -210,7 +212,7 @@
210212
(when (:right style) {:right (valid-width (:right style))})
211213
(when (:tip style) {:tip (valid-width (:tip style))})
212214
(when-not (s/blank? units) {:units (inc (valid-width units))})) ; Include space delimiter
213-
render-fn! (partial redraw-progress-indicator! style style-widths label line width counter? total units)
215+
render-fn! (partial redraw-progress-indicator! style style-widths label line width counter? total (count (str total)) units)
214216
running-promise? (promise)
215217
poll-interval-ms (Math/round (double (/ 1000 redraw-rate)))
216218
fut (e/future* (poll-atom a running-promise? poll-interval-ms render-fn!))]

0 commit comments

Comments
 (0)