class Belajar::Window
Public Class Methods
new(height = Curses.lines, width = Curses.cols, top = 0, left = 0)
click to toggle source
Calls superclass method
# File lib/belajar/window.rb, line 9 def initialize(height = Curses.lines, width = Curses.cols, top = 0, left = 0) super(height, width, top, left) init_colors end
Public Instance Methods
clear_line(options = {})
click to toggle source
clear_line
(options = {}) options: [:color, :text_decoration, :start_pos, :end_pos, :text]
# File lib/belajar/window.rb, line 55 def clear_line(options = {}) color = options[:color] || COLOR_TEXT text_decoration = options[:text_decoration] || Curses::A_NORMAL start = options[:start_pos] || 0 stop = options[:end_pos] || maxx x = curx setpos(cury, start) write((options[:text] || ' ') * (stop - 1), color, text_decoration) setpos(cury, x) refresh end
colored(text, color, text_decoration = Curses::A_NORMAL, options = {})
click to toggle source
# File lib/belajar/window.rb, line 38 def colored(text, color, text_decoration = Curses::A_NORMAL, options = {}) if options[:full_line] clear_line( color: color, text_decoration: Curses::A_STANDOUT, start_pos: 1, end_pos: maxx - 2 ) prefix = ' ' end write("#{prefix}#{text}", color, text_decoration) end
emphasize(text, text_decoration = Curses::A_NORMAL)
click to toggle source
# File lib/belajar/window.rb, line 18 def emphasize(text, text_decoration = Curses::A_NORMAL) write(text, COLOR_TEXT_EMPHASIZE, text_decoration) end
green(text, text_decoration = Curses::A_NORMAL, options = {})
click to toggle source
# File lib/belajar/window.rb, line 34 def green(text, text_decoration = Curses::A_NORMAL, options = {}) colored(text, COLOR_GREEN, text_decoration, options) end
heading(text, text_decoration = Curses::A_UNDERLINE)
click to toggle source
# File lib/belajar/window.rb, line 22 def heading(text, text_decoration = Curses::A_UNDERLINE) write(text, COLOR_HEADING, text_decoration) end
print_indicator(object, text = ' ', text_decoration = Curses::A_STANDOUT)
click to toggle source
# File lib/belajar/window.rb, line 68 def print_indicator(object, text = ' ', text_decoration = Curses::A_STANDOUT) if object.respond_to?(:mastered?) && object.respond_to?(:started?) if object.mastered? green(text, text_decoration) elsif object.started? yellow(text, text_decoration) else red(text, text_decoration) end elsif object.respond_to?(:mastered?) if object.mastered? green(text, text_decoration) else red(text, text_decoration) end end write ' ' end
print_markdown(text)
click to toggle source
# File lib/belajar/window.rb, line 88 def print_markdown(text) clear_line printer = Markdown::Printer.new(window: self) printer.print(text) end
red(text, text_decoration = Curses::A_NORMAL, options = {})
click to toggle source
# File lib/belajar/window.rb, line 26 def red(text, text_decoration = Curses::A_NORMAL, options = {}) colored(text, COLOR_RED, text_decoration, options) end
write(text, color = COLOR_TEXT, text_decoration = Curses::A_NORMAL)
click to toggle source
# File lib/belajar/window.rb, line 14 def write(text, color = COLOR_TEXT, text_decoration = Curses::A_NORMAL) attron(Curses.color_pair(color) | text_decoration) { self << text.to_s } end
yellow(text, text_decoration = Curses::A_NORMAL, options = {})
click to toggle source
# File lib/belajar/window.rb, line 30 def yellow(text, text_decoration = Curses::A_NORMAL, options = {}) colored(text, COLOR_YELLOW, text_decoration, options) end