module MultiProgressBar
Constants
- VERSION
Attributes
bars[R]
Public Class Methods
end()
click to toggle source
Restore the terminal to normal function. Always call this before exiting.
# File lib/ruby-multi-progressbar.rb, line 37 def end # Give an extra line below the output for the shell to prompt on. add_bar(nil) Ncurses.endwin end
log(text)
click to toggle source
Write text
to the space above the progress bars.
# File lib/ruby-multi-progressbar.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()
click to toggle source
# File lib/ruby-multi-progressbar.rb, line 66 def refresh_window_positions @bars_window.mvwin(Ncurses.LINES-bars.size, @bars_window.getbegx) @bars_window.resize(bars.size, @bars_window.getmaxx) @bars_window.refresh @log_window.resize(Ncurses.LINES-bars.size, @log_window.getmaxx) @log_window.refresh end
start()
click to toggle source
Set up the screen. Always call MultiProgressBar.start
before using progress bars.
# File lib/ruby-multi-progressbar.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 |bar| bar.width = @bars_window.getmaxx bar.show end end end