Skip to content

Commit 89eba34

Browse files
authored
Merge pull request #35 from pmonks/dev
Release 2.0.267
2 parents bf4f643 + acb63a6 commit 89eba34

File tree

9 files changed

+39
-20
lines changed

9 files changed

+39
-20
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ jobs:
2020
matrix:
2121
java-version: [ 8, 11, 17, 21 ]
2222
steps:
23-
- uses: actions/checkout@v4
23+
- uses: actions/checkout@v5
2424
- uses: actions/setup-java@v4
2525
with:
2626
distribution: 'temurin'
2727
java-version: ${{ matrix.java-version }}
28-
- uses: DeLaGuardo/setup-clojure@13.2
28+
- uses: DeLaGuardo/setup-clojure@13.4
2929
with:
3030
cli: latest
3131
- uses: actions/cache@v4

.github/workflows/dependencies.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ jobs:
1111
container:
1212
image: uochan/antq
1313
steps:
14-
- uses: actions/checkout@v4
14+
- uses: actions/checkout@v5
1515
- run: java -jar /tmp/antq/antq.jar --skip=pom --exclude=com.github.pmonks/pbr --error-format="::error file={{file}}::{{message}}"

.github/workflows/deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ jobs:
1010
environment: clojars
1111

1212
steps:
13-
- uses: actions/checkout@v4
13+
- uses: actions/checkout@v5
1414
with:
1515
fetch-depth: 0 # Make sure we get the full history, or else the version number gets screwed up
1616
- uses: actions/setup-java@v4
1717
with:
1818
distribution: 'temurin'
1919
java-version: 21
20-
- uses: DeLaGuardo/setup-clojure@13.2
20+
- uses: DeLaGuardo/setup-clojure@13.4
2121
with:
2222
cli: latest
2323
- uses: actions/cache@v4

.github/workflows/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ jobs:
99
runs-on: ubuntu-latest
1010

1111
steps:
12-
- uses: actions/checkout@v4
12+
- uses: actions/checkout@v5
1313
- uses: actions/setup-java@v4
1414
with:
1515
distribution: 'temurin'
1616
java-version: 21
17-
- uses: DeLaGuardo/setup-clojure@13.2
17+
- uses: DeLaGuardo/setup-clojure@13.4
1818
with:
1919
cli: latest
2020
- uses: actions/cache@v4

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
| | | |
2-
|---:|:---:|:---:|
3-
| [**release**](https://github.com/pmonks/spinner/tree/release) | [![CI](https://github.com/pmonks/spinner/actions/workflows/ci.yml/badge.svg?branch=release)](https://github.com/pmonks/spinner/actions?query=workflow%3ACI+branch%3Arelease) | [![Dependencies](https://github.com/pmonks/spinner/actions/workflows/dependencies.yml/badge.svg?branch=release)](https://github.com/pmonks/spinner/actions?query=workflow%3Adependencies+branch%3Arelease) |
4-
| [**dev**](https://github.com/pmonks/spinner/tree/dev) | [![CI](https://github.com/pmonks/spinner/actions/workflows/ci.yml/badge.svg?branch=dev)](https://github.com/pmonks/spinner/actions?query=workflow%3ACI+branch%3Adev) | [![Dependencies](https://github.com/pmonks/spinner/actions/workflows/dependencies.yml/badge.svg?branch=dev)](https://github.com/pmonks/spinner/actions?query=workflow%3Adependencies+branch%3Adev) |
5-
6-
[![Latest Version](https://img.shields.io/clojars/v/com.github.pmonks/spinner)](https://clojars.org/com.github.pmonks/spinner/) [![Open Issues](https://img.shields.io/github/issues/pmonks/spinner.svg)](https://github.com/pmonks/spinner/issues) [![License](https://img.shields.io/github/license/pmonks/spinner.svg)](https://github.com/pmonks/spinner/blob/release/LICENSE)
7-
81
# spinner
92

3+
[![CI](https://github.com/pmonks/spinner/actions/workflows/ci.yml/badge.svg?branch=dev)](https://github.com/pmonks/spinner/actions?query=workflow%3ACI+branch%3Adev)
4+
[![Dependencies](https://github.com/pmonks/spinner/actions/workflows/dependencies.yml/badge.svg?branch=dev)](https://github.com/pmonks/spinner/actions?query=workflow%3Adependencies+branch%3Adev)
5+
<br/>
6+
[![Latest Version](https://img.shields.io/clojars/v/com.github.pmonks/spinner)](https://clojars.org/com.github.pmonks/spinner/)
7+
[![Open Issues](https://img.shields.io/github/issues/pmonks/spinner.svg)](https://github.com/pmonks/spinner/issues)
8+
[![License](https://img.shields.io/github/license/pmonks/spinner.svg)](https://github.com/pmonks/spinner/blob/release/LICENSE)
9+
![Maintained](https://badges.ws/badge/?label=maintained&value=yes,+at+author's+discretion)
10+
1011
Progress indicators for command line Clojure apps, including support for indeterminate tasks (those where progress cannot be measured) and determinate tasks (those where progress can be measured). The former are represented using "spinners", while the latter are represented using "progress bars".
1112

1213
## What is it useful for?

deps.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
;
1010

1111
{:deps
12-
{jansi-clj/jansi-clj {:mvn/version "1.0.3"}
12+
{jansi-clj/jansi-clj {:mvn/version "1.0.5"}
1313
com.github.pmonks/clj-wcwidth {:mvn/version "1.0.103"}
1414
com.github.pmonks/embroidery {:mvn/version "1.0.44"}}
1515
:aliases

src/progress/ansi.clj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,27 @@
3030
(print "\u001B8") ; So we manually send a DEC code too
3131
(flush))
3232

33+
(defn hide-cursor!
34+
[]
35+
(print "\u001B[25l")
36+
(flush))
37+
38+
(defn show-cursor!
39+
[]
40+
(print "\u001B[25h")
41+
(flush))
42+
3343
(defn print-at
3444
"Send text output to the specified screen locations (note: ANSI screen
3545
coordinates are 1-based). msgs may include jansi formatting."
3646
[x y & msgs]
3747
(save-cursor!)
48+
(hide-cursor!)
3849
(jansi/cursor! x y)
3950
(jansi/erase-line!)
4051
(apply print msgs)
41-
(restore-cursor!))
52+
(restore-cursor!)
53+
(show-cursor!))
4254

4355
(defn debug-print-at
4456
"Send debug output to the specified screen location (note: ANSI screen

src/progress/determinate.clj

Lines changed: 8 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,9 +75,11 @@
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!)
82+
(ansi/hide-cursor!)
8183
(jansi/cursor! 1 line))
8284
(print (str ; Go to the start of the line
8385
"\r"
@@ -122,14 +124,16 @@
122124
(ansi/apply-colours-and-attrs (:counter-fg-colour style)
123125
(:counter-bg-colour style)
124126
(: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)
126129
(when-not (s/blank? units)
127130
(ansi/apply-colours-and-attrs (:units-fg-colour style)
128131
(:units-bg-colour style)
129132
(:units-attrs style)
130133
(str " " units))))))))
131134
(jansi/erase-line!)
132135
(when line (ansi/restore-cursor!))
136+
(ansi/show-cursor!)
133137
(flush))))
134138

135139
(defn- poll-atom
@@ -208,7 +212,7 @@
208212
(when (:right style) {:right (valid-width (:right style))})
209213
(when (:tip style) {:tip (valid-width (:tip style))})
210214
(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)
212216
running-promise? (promise)
213217
poll-interval-ms (Math/round (double (/ 1000 redraw-rate)))
214218
fut (e/future* (poll-atom a running-promise? poll-interval-ms render-fn!))]

src/progress/indeterminate.clj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,14 @@
127127
attributes [:default]}}]
128128
(let [delay-in-ms (long (Math/round (double delay-in-ms)))] ; Coerce delay-in-ms to a long
129129
(ansi/save-cursor!)
130+
(ansi/hide-cursor!)
130131
(loop [i 0]
131132
(clojure.core/print (str (ansi/apply-colours-and-attrs fg-colour bg-colour attributes (nth frames (mod i (count frames))))
132133
" "))
133134
(flush)
134135
(when (pos? delay-in-ms) (Thread/sleep delay-in-ms)) ; Thread/sleep throws on negative values, and sleeping for 0ms makes no sense
135136
(ansi/restore-cursor!)
137+
(ansi/show-cursor!)
136138
(jansi/erase-line!)
137139
(print-pending-messages)
138140
(when (active?)

0 commit comments

Comments
 (0)