class Minder::Frame
Attributes
height[RW]
left[RW]
lines[RW]
min_height[RW]
pomodoro_runner[RW]
task_manager[RW]
top[RW]
width[RW]
window[RW]
Public Class Methods
new(**options)
click to toggle source
# File lib/minder/cli/frame.rb, line 18 def initialize(**options) height = options.fetch(:height, 3) width = options.fetch(:width, 40) top = options.fetch(:top, 0) left = options.fetch(:left, 0) task_manager = options.fetch(:task_manager) pomodoro_runner = options.fetch(:pomodoro_runner) @focused = false @hidden = false @has_cursor = false self.pomodoro_runner = pomodoro_runner self.task_manager = task_manager self.min_height = height self.height = height self.width = width self.top = top self.left = left self.window = build_window window.keypad(true) self.lines = [] end
Public Instance Methods
build_window()
click to toggle source
# File lib/minder/cli/frame.rb, line 43 def build_window Curses::Window.new(min_height, width, top, left) end
erase()
click to toggle source
# File lib/minder/cli/frame.rb, line 135 def erase height.times do |index| window.setpos(index, 0) window.addstr(' ' * width ) end window_refresh end
focus()
click to toggle source
# File lib/minder/cli/frame.rb, line 47 def focus @focused = true @has_cursor = true end
focused?()
click to toggle source
# File lib/minder/cli/frame.rb, line 57 def focused? @focused end
handle_char_keypress(key)
click to toggle source
# File lib/minder/cli/frame.rb, line 171 def handle_char_keypress(key) end
handle_keypress(key)
click to toggle source
# File lib/minder/cli/frame.rb, line 153 def handle_keypress(key) return unless key if key.is_a?(Fixnum) if key == 9 # tab changed notify_observers(:switch_focus) else handle_non_char_keypress(key) end else handle_char_keypress(key) end end
handle_non_char_keypress(key)
click to toggle source
# File lib/minder/cli/frame.rb, line 168 def handle_non_char_keypress(key) end
has_cursor?()
click to toggle source
# File lib/minder/cli/frame.rb, line 82 def has_cursor? @has_cursor end
hide()
click to toggle source
# File lib/minder/cli/frame.rb, line 65 def hide erase @hidden = true end
listen()
click to toggle source
# File lib/minder/cli/frame.rb, line 86 def listen window.timeout = 0 handle_keypress(window.getch) end
move(top, left)
click to toggle source
# File lib/minder/cli/frame.rb, line 78 def move(top, left) window.move(top, left) end
parse_template()
click to toggle source
# File lib/minder/cli/frame.rb, line 102 def parse_template b = binding self.lines = ERB.new(template).result(b).split("\n") end
print_line(text)
click to toggle source
# File lib/minder/cli/frame.rb, line 147 def print_line(text) text = text[0,width - 2] remainder = width - 2 - text.length window.addstr(text + ' ' * remainder) end
refresh()
click to toggle source
# File lib/minder/cli/frame.rb, line 91 def refresh return if @hidden parse_template set_text window_refresh end
resize()
click to toggle source
# File lib/minder/cli/frame.rb, line 107 def resize erase self.width = Curses.cols if lines.length >= min_height - 2 self.height = lines.length + 2 else self.height = min_height end window.resize(height, width) window_refresh end
set_cursor_position()
click to toggle source
# File lib/minder/cli/frame.rb, line 143 def set_cursor_position window.setpos(1, 0) end
set_text()
click to toggle source
# File lib/minder/cli/frame.rb, line 121 def set_text window.box(?|, ?-) height.times do |index| next if index >= height - 2 window.setpos(index + 1, 1) line = lines[index] if line print_line(line) else print_line('') end end end
template()
click to toggle source
# File lib/minder/cli/frame.rb, line 74 def template raise NotImplementedError end
unfocus()
click to toggle source
# File lib/minder/cli/frame.rb, line 52 def unfocus @focused = false @has_cursor = false end
unhide()
click to toggle source
# File lib/minder/cli/frame.rb, line 70 def unhide @hidden = false end
window_refresh()
click to toggle source
# File lib/minder/cli/frame.rb, line 98 def window_refresh window.refresh end