|
60 | 60 |
|
61 | 61 | (defn- redraw-progress-indicator! |
62 | 62 | "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] |
64 | 64 | ; Make sure this code is non re-entrant |
65 | 65 | (locking lock |
66 | 66 | (let [percent-complete (/ (double new-value) total) |
|
75 | 75 | fill-cols (clamp 0 body-cols (Math/ceil (* percent-complete body-cols))) |
76 | 76 | fill-chars (- (Math/ceil (/ fill-cols (:full style-widths))) tip-chars) |
77 | 77 | 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)))] |
79 | 80 | (when line |
80 | 81 | (ansi/save-cursor!) |
| 82 | + (ansi/hide-cursor!) |
81 | 83 | (jansi/cursor! 1 line)) |
82 | 84 | (print (str ; Go to the start of the line |
83 | 85 | "\r" |
|
122 | 124 | (ansi/apply-colours-and-attrs (:counter-fg-colour style) |
123 | 125 | (:counter-bg-colour style) |
124 | 126 | (:counter-attrs style) |
125 | | - (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) |
126 | 129 | (when-not (s/blank? units) |
127 | 130 | (ansi/apply-colours-and-attrs (:units-fg-colour style) |
128 | 131 | (:units-bg-colour style) |
129 | 132 | (:units-attrs style) |
130 | 133 | (str " " units)))))))) |
131 | 134 | (jansi/erase-line!) |
132 | 135 | (when line (ansi/restore-cursor!)) |
| 136 | + (ansi/show-cursor!) |
133 | 137 | (flush)))) |
134 | 138 |
|
135 | 139 | (defn- poll-atom |
|
208 | 212 | (when (:right style) {:right (valid-width (:right style))}) |
209 | 213 | (when (:tip style) {:tip (valid-width (:tip style))}) |
210 | 214 | (when-not (s/blank? units) {:units (inc (valid-width units))})) ; Include space delimiter |
211 | | - 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) |
212 | 216 | running-promise? (promise) |
213 | 217 | poll-interval-ms (Math/round (double (/ 1000 redraw-rate))) |
214 | 218 | fut (e/future* (poll-atom a running-promise? poll-interval-ms render-fn!))] |
|
0 commit comments