Determinate progress indicator (aka a "progress bar"), for the case where the progress of a long-running task can be determined.
Determinate progress indicator (aka a "progress bar"), for the case where the progress of a long-running task can be determined.
(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 - a String to 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 to 72 if 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 second a will be checked for changes,
and the progress indicator redrawn if the value of a has
changed. Optional, default 10Notes:
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` - a `String` to 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 to `72` if 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 second `a` will be checked for changes,
and the progress indicator redrawn if the value of `a` has
changed. Optional, default `10`
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! a f)(animatef!
a
{:keys [style label line width total units counter? preserve? redraw-rate]
:or {style (get styles default-style)
total 100
width (let [console-width
(org.fusesource.jansi.AnsiConsole/getTerminalWidth)]
(if (pos? console-width) (- console-width 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 - a String to 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 to 72 if 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 second a will be checked for changes,
and the progress indicator redrawn if the value of a has
changed. Optional, default 10Notes:
f will be executed without any
animation occurringf will be executed without any
animation occurringWraps 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` - a `String` to 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 to `72` if 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 second `a` will be checked for changes,
and the progress indicator redrawn if the value of `a` has
changed. Optional, default `10`
Notes:
* When the JVM's stdout stream doesn't support ANSI escape sequences (e.g.
when output is redirected to a file), `f` will be executed without any
animation occurring
* When the terminal the JVM is executing within is too small to display the
determinate progress indicator, `f` will be executed without any
animation occurringThe 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.
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.
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.
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.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |