progress.determinate
Determinate progress indicator (aka a “progress bar”), for the case where the progress of a long-running task can be determined.
animate!
macro
(animate! a & body)Equivalent to clojure.core/do, but displays a determinate progress indicator (aka ‘progress bar’) while the forms are executing. Monitors atom a (a number between 0 and (:total opts)), representing progress by those forms. If the first form is the keyword :opts, the second form must be a map, containing any/all of these keys:
:style- a map defining the style (characters, colours, and attributes) to use when printing the progress indicator. Optional, default:(:ascii-basic styles):label- aStringto display before the progress indicator - this could be the filename for a lengthy file download, for example. Optional, default:nil:line- the line number on the screen at which to display the progress indicator (note: 1-based). Optional, default:nil(display at current location):width- the (approximate) desired width of the progress indicator, including any labels and counters. This is approximate because emoji-based styles may not take up an even fraction of the desired width. Optional, default: attempts to determine current console width, or defaults to72if that cannot be determined.:total- the final number that the atom will reach. Optional, default:100(i.e. the atom represents a %age):units- a unit label (String) to display after the counter - this could be a file size unit ("KB","MB", etc.), for example. Optional, default:nil:preserve?- flag indicating whether to preserve the progress indicator on screen after it finishes (vs erasing it). Optional, default:false(erase it):counter?- whether to display a counter to the right of the progress indicator. Optional, default:true(display a counter):redraw-rate- how many times per secondawill be checked for changes, and the progress indicator redrawn if the value ofahas changed. Optional, default10
Notes:
- When the JVM’s stdout stream doesn’t support ANSI escape sequences (e.g. when output is redirected to a file), the forms will be executed without any animation occurring
- When the terminal the JVM is executing within is too small to display the determinate progress indicator, the forms will be executed without any animation occurring
animatef!
(animatef! a f)(animatef! a {:keys [style label line width total units counter? preserve? redraw-rate], :or {style (get styles default-style), total 100, width (if-let [w (jansi/terminal-width)] (- w 2) 72), counter? true, preserve? false, redraw-rate 10}} f)Wraps execution of the given function in a determinate progress indicator, monitoring atom a (a number between 0 and (:total opts), representing progress).
Note: the animate! macro is preferred over this function.
The optional opts map may have an/all of these keys:
:style- a map defining the style (characters, colours, and attributes) to use when printing the progress indicator. Optional, default:(:ascii-basic styles):label- aStringto display before the progress indicator - this could be the filename for a lengthy file download, for example. Optional, default:nil:line- the line number on the screen at which to display the progress indicator (note: 1-based). Optional, default:nil(display at current line):width- the (approximate) desired width of the progress indicator, including any labels and counters. This is approximate because emoji-based styles may not take up an even fraction of the desired width. Optional, default: attempts to determine current console width, or defaults to72if that cannot be determined.:total- the final number that the atom will reach. Optional, default:100(i.e. the atom represents a %age):units- a unit label (String) to display after the counter - this could be a file size unit ("KB","MB", etc.), for example. Optional, default:nil:counter?- whether to display a counter to the right of the progress indicator. Optional, default:true(display a counter):preserve?- flag indicating whether to preserve the progress indicator on screen after it finishes (vs erasing it). Optional, default:false(erase it):redraw-rate- how many times per secondawill be checked for changes, and the progress indicator redrawn if the value ofahas changed. Optional, default10
Notes:
- When the JVM’s stdout stream doesn’t support ANSI escape sequences (e.g. when output is redirected to a file),
fwill be executed without any animation occurring - When the terminal the JVM is executing within is too small to display the determinate progress indicator,
fwill be executed without any animation occurring
default-style
The default determinate progress indicator style used, if one isn’t specified, as a keyword that has an associated entry in styles. This style is known to function on all platforms.
styles
A selection of predefined styles of determinate progress indicators, represented as a map. Only ASCII progress indicators are known to work reliably - other styles depend on the operating system, terminal font & encoding, phase of the moon, and how long since your dog last pooped.