Method: CLI::UI::Progress#to_s
- Defined in:
- lib/cli/ui/progress.rb
#to_s ⇒ Object
Format the progress bar to be printed to terminal
: -> String
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/cli/ui/progress.rb', line 113 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 title = CLI::UI.resolve_text(@title, truncate_to: @max_width - Frame.prefix_width) if @title = CLI::UI.resolve_text([ FILLED_BAR + ' ' * filled, UNFILLED_BAR + ' ' * unfilled, CLI::UI::Color::RESET.code + suffix, ].join) [title, ].compact.join("\n") end |