Owl.ProgressBar (Owl v0.1.0) View Source
A live progress bar.
Single bar
Owl.ProgressBar.start(id: :users, label: "Creating users", total: 1000)
Enum.each(1..100, fn _ ->
Process.sleep(10)
Owl.ProgressBar.inc(id: :users)
end)
# Wait a bit to give ProgressBar server a time to send last state update to LiveScreen
Process.sleep(1)
Owl.LiveScreen.flush()Multiple bars
1..10
|> Enum.map(fn index ->
Task.async(fn ->
range = 1..Enum.random(100..500)
label = "Demo Progress ##{index}"
Owl.ProgressBar.start(
id: {:demo, index},
label: label,
total: range.last,
timer: true,
bar_width_ratio: 0.3,
filled_symbol: "#",
partial_symbols: []
)
Enum.each(range, fn _ ->
Process.sleep(Enum.random(10..50))
Owl.ProgressBar.inc(id: {:demo, index})
end)
end)
end)
|> Task.await_many(:infinity)
Owl.LiveScreen.flush()
Link to this section Summary
Functions
Increases current value by step.
Renders a progress bar that can be consumed by Owl.IO.puts/2.
Starts a progress bar on Owl.LiveScreen.
Link to this section Types
Link to this section Functions
Specs
Increases current value by step.
When current value becomes equal to total, then progress bar terminates.
Options
:id- an required identifier of the progress bar.:step- a value by whichcurrentvalue should be increased. Defaults to 1.
Examples
Owl.ProgressBar.inc(id: "Creating users")
Owl.ProgressBar.inc(id: "Creating users", step: 10)
Specs
render(%{
optional(:current_time) => nil | integer(),
optional(:start_time) => nil | integer(),
optional(:screen_width) => nil | pos_integer(),
bar_width_ratio: float(),
label: String.t(),
total: pos_integer(),
current: non_neg_integer(),
start_symbol: Owl.Data.t(),
end_symbol: Owl.Data.t(),
filled_symbol: Owl.Data.t(),
partial_symbols: [Owl.Data.t()],
empty_symbol: Owl.Data.t()
}) :: Owl.Data.t()
Renders a progress bar that can be consumed by Owl.IO.puts/2.
Used as a callback for blocks in Owl.LiveScreen.
Examples
iex> Owl.ProgressBar.render(%{
...> label: "Demo",
...> total: 200,
...> current: 60,
...> bar_width_ratio: 0.7,
...> start_symbol: "[",
...> end_symbol: "]",
...> filled_symbol: "#",
...> partial_symbols: [],
...> empty_symbol: ".",
...> screen_width: 40
...> }) |> to_string()
"Demo [########....................] 30%"
iex> Owl.ProgressBar.render(%{
...> label: "Demo",
...> total: 200,
...> current: 8,
...> bar_width_ratio: 0.4,
...> start_symbol: "|",
...> end_symbol: "|",
...> filled_symbol: "█",
...> partial_symbols: ["▏", "▎", "▍", "▌", "▋", "▊", "▉"],
...> empty_symbol: " ",
...> screen_width: 40,
...> start_time: -576460748012758993,
...> current_time: -576460748012729828
...> }) |> to_string()
"Demo 00:29.2 |▋ | 4%"
iex> Owl.ProgressBar.render(%{
...> label: "Demo",
...> total: 200,
...> current: 8,
...> bar_width_ratio: 0.7,
...> start_symbol: "[",
...> end_symbol: "]",
...> filled_symbol: Owl.Tag.new("≡", :cyan),
...> partial_symbols: [Owl.Tag.new("-", :green), Owl.Tag.new("=", :blue)],
...> empty_symbol: " ",
...> screen_width: 40
...> })|> Owl.Data.to_ansidata() |> to_string
"Demo [[36m≡[39m[49m[32m-[39m[49m ] 4%[0m"
Specs
start( label: String.t(), id: id(), total: pos_integer(), timer: boolean(), current: non_neg_integer(), bar_width_ratio: nil | float(), start_symbol: Owl.Data.t(), end_symbol: Owl.Data.t(), filled_symbol: Owl.Data.t(), partial_symbols: [Owl.Data.t()], empty_symbol: Owl.Data.t(), screen_width: pos_integer() ) :: DynamicSupervisor.on_start_child()
Starts a progress bar on Owl.LiveScreen.
Options
:id- an id of the progress bar. Required.:label- a label of the progress bar. Required.:total- a total value. Required.:current- a current value. Defaults to0.:bar_width_ratio- a bar width ratio. Defaults to 0.7.:timer- set totrueto launch a timer. Defaults tofalse.:start_symbol- a symbol that is rendered at the beginning of the progress bar. Defaults to"[".:end_symbol- a symbol that rendered at the end of the progress bar. Defaults to"]".:filled_symbol- a symbol that use used whencurrentvalue is big enough to fill the cell. Defaults to"≡":partial_symbols- a list of symbols that are used whencurrentvalue is too small to renderfilled_symbol. Defaults to["-", "="].:empty_symbol- an empty symbol. Defaults to" ".:screen_width- a width of output data. Defaults to width of the terminal or 80 symbols, if a terminal is not available.