Module: MultiProgressBar
- Defined in:
- lib/multi_progress_bar.rb,
lib/multi_progress_bar/bar.rb,
lib/multi_progress_bar/total_bar.rb,
lib/multi_progress_bar/bar_renderer.rb
Defined Under Namespace
Classes: Bar, BarRenderer, TotalBar
Class Attribute Summary collapse
-
.bars ⇒ Object
readonly
Returns the value of attribute bars.
Class Method Summary collapse
-
.add_bar(bar) ⇒ Object
:nodoc:.
-
.end ⇒ Object
Restore the terminal to normal function.
-
.log(text) ⇒ Object
Write
text
to the space above the progress bars. - .refresh_window_positions ⇒ Object
-
.start ⇒ Object
Set up the screen.
-
.update_bar(bar, rendered_bar) ⇒ Object
:nodoc:.
-
.width ⇒ Object
:nodoc:.
Class Attribute Details
.bars ⇒ Object (readonly)
Returns the value of attribute bars.
7 8 9 |
# File 'lib/multi_progress_bar.rb', line 7 def @bars end |
Class Method Details
.add_bar(bar) ⇒ Object
:nodoc:
75 76 77 78 |
# File 'lib/multi_progress_bar.rb', line 75 def () #:nodoc: @bars += [] refresh_window_positions end |
.end ⇒ Object
Restore the terminal to normal function. Always call this before exiting.
37 38 39 40 41 42 |
# File 'lib/multi_progress_bar.rb', line 37 def end # Give an extra line below the output for the shell to prompt on. (nil) Ncurses.endwin end |
.log(text) ⇒ Object
Write text
to the space above the progress bars.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/multi_progress_bar.rb', line 45 def log(text) text = text.to_s # Parse ANSI escape codes. text.scan(/([^\e]*)(?:\e\[(\d+.))?/) do |normal_text, code| @log_window.addstr(normal_text) case code when /3(\d)m/ @log_window.attron(Ncurses.COLOR_PAIR($1.to_i)) when /0m/ @log_window.attron(Ncurses.COLOR_PAIR(7)) end end @log_window.addstr("\n") @log_window.refresh end |
.refresh_window_positions ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/multi_progress_bar.rb', line 66 def refresh_window_positions @bars_window.mvwin(Ncurses.LINES-.size, @bars_window.getbegx) @bars_window.resize(.size, @bars_window.getmaxx) @bars_window.refresh @log_window.resize(Ncurses.LINES-.size, @log_window.getmaxx) @log_window.refresh end |
.start ⇒ Object
Set up the screen. Always call MultiProgressBar.start
before using progress bars.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/multi_progress_bar.rb', line 10 def start @bars = [].freeze Ncurses.initscr Ncurses.curs_set(0) Ncurses.start_color (0..7).each { |color_number| Ncurses.init_pair(color_number, color_number, Ncurses::COLOR_BLACK); } @bars_window = Ncurses::WINDOW.new(1, 0, Ncurses.LINES-1, 0) @log_window = Ncurses::WINDOW.new(Ncurses.LINES-1, 0, 0, 0) @log_window.scrollok(true) trap("SIGWINCH") do Ncurses.endwin Ncurses.refresh refresh_window_positions @bars.each do || .width = @bars_window.getmaxx .show end end end |
.update_bar(bar, rendered_bar) ⇒ Object
:nodoc:
80 81 82 83 84 85 86 |
# File 'lib/multi_progress_bar.rb', line 80 def (, ) #:nodoc: @bars_window.move(.index(), 0) @bars_window.attron(Ncurses.COLOR_PAIR(.color)) if .color @bars_window.addstr() @bars_window.attroff(Ncurses.COLOR_PAIR(.color)) if .color @bars_window.refresh end |
.width ⇒ Object
:nodoc:
62 63 64 |
# File 'lib/multi_progress_bar.rb', line 62 def width #:nodoc: @bars_window.getmaxx end |