Class: Minder::FilterFrame

Inherits:
Frame
  • Object
show all
Defined in:
lib/minder/cli/filter_frame.rb

Instance Attribute Summary collapse

Attributes inherited from Frame

#height, #left, #lines, #min_height, #pomodoro_runner, #task_manager, #top, #width, #window

Instance Method Summary collapse

Methods inherited from Frame

#build_window, #erase, #focus, #focused?, #handle_keypress, #has_cursor?, #hidden?, #hide, #listen, #move, #parse_template, #print_line, #refresh, #resize, #set_text, #unfocus, #unhide, #window_refresh

Constructor Details

#initializeFilterFrame

Returns a new instance of FilterFrame.



7
8
9
10
# File 'lib/minder/cli/filter_frame.rb', line 7

def initialize(*)
  super
  @filter_string = ''
end

Instance Attribute Details

#filter_stringObject (readonly)

Returns the value of attribute filter_string.



5
6
7
# File 'lib/minder/cli/filter_frame.rb', line 5

def filter_string
  @filter_string
end

Instance Method Details

#desired_heightObject



12
13
14
# File 'lib/minder/cli/filter_frame.rb', line 12

def desired_height
  3
end

#handle_char_keypress(key) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/minder/cli/filter_frame.rb', line 26

def handle_char_keypress(key)
  return unless key

  @filter_string += key
  refresh
  changed
  notify_observers(:update_filter, { text: filter_string })
end

#handle_non_char_keypress(key) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/minder/cli/filter_frame.rb', line 35

def handle_non_char_keypress(key)
  if key == 10
    changed
    notify_observers(:submit_filter, { text: filter_string })
  end

  @filter_string.chop! if [Curses::Key::BACKSPACE, 127].include?(key)

  refresh
  changed
  notify_observers(:update_filter, { text: filter_string })
end

#set_cursor_positionObject



22
23
24
# File 'lib/minder/cli/filter_frame.rb', line 22

def set_cursor_position
  window.setpos(1, filter_string.length + 9)
end

#templateObject



16
17
18
19
20
# File 'lib/minder/cli/filter_frame.rb', line 16

def template
  <<-TEXT
Filter: #{filter_string}
TEXT
end