Class: CLI::UI::Progress
- Inherits:
-
Object
- Object
- CLI::UI::Progress
- Extended by:
- T::Sig
- Defined in:
- lib/cli/ui/progress.rb
Constant Summary collapse
- FILLED_BAR =
A Cyan filled block
"\e[46m"
- UNFILLED_BAR =
A bright white block
"\e[1;47m"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(width: Terminal.width) ⇒ Progress
constructor
A new instance of Progress.
- #tick(percent: nil, set_percent: nil) ⇒ Object
- #to_s ⇒ Object
Methods included from T::Sig
Constructor Details
Class Method Details
Instance Method Details
#tick(percent: nil, set_percent: nil) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/cli/ui/progress.rb', line 79 def tick(percent: nil, set_percent: nil) raise ArgumentError, 'percent and set_percent cannot both be specified' if percent && set_percent @percent_done += percent || 0.01 @percent_done = set_percent if set_percent @percent_done = [@percent_done, 1.0].min # Make sure we can't go above 1.0 print(self) print(CLI::UI::ANSI.previous_line + "\n") end |
#to_s ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/cli/ui/progress.rb', line 93 def to_s suffix = " #{(@percent_done * 100).floor}%".ljust(5) workable_width = @max_width - Frame.prefix_width - suffix.size filled = [(@percent_done * workable_width.to_f).ceil, 0].max unfilled = [workable_width - filled, 0].max CLI::UI.resolve_text([ FILLED_BAR + ' ' * filled, UNFILLED_BAR + ' ' * unfilled, CLI::UI::Color::RESET.code + suffix, ].join) end |