Class: Minder::Scene
- Inherits:
-
Object
- Object
- Minder::Scene
- Defined in:
- lib/minder/cli/scene.rb
Instance Attribute Summary collapse
-
#frames ⇒ Object
Returns the value of attribute frames.
Instance Method Summary collapse
- #clear ⇒ Object
- #close ⇒ Object
- #focus_frame(frame) ⇒ Object
- #focused_frame ⇒ Object
- #help_frame ⇒ Object
-
#initialize ⇒ Scene
constructor
A new instance of Scene.
- #main_frame ⇒ Object
- #message_frame ⇒ Object
- #redraw ⇒ Object
- #refresh ⇒ Object
- #resize_frames ⇒ Object
- #setup ⇒ Object
- #switch_focus ⇒ Object
Constructor Details
#initialize ⇒ Scene
Returns a new instance of Scene.
13 14 15 |
# File 'lib/minder/cli/scene.rb', line 13 def initialize self.frames = [] end |
Instance Attribute Details
#frames ⇒ Object
Returns the value of attribute frames.
11 12 13 |
# File 'lib/minder/cli/scene.rb', line 11 def frames @frames end |
Instance Method Details
#clear ⇒ Object
110 111 112 |
# File 'lib/minder/cli/scene.rb', line 110 def clear Curses.clear end |
#close ⇒ Object
114 115 116 |
# File 'lib/minder/cli/scene.rb', line 114 def close Curses.close_screen end |
#focus_frame(frame) ⇒ Object
41 42 43 44 |
# File 'lib/minder/cli/scene.rb', line 41 def focus_frame(frame) focused_frame.unfocus frame.focus end |
#focused_frame ⇒ Object
26 27 28 |
# File 'lib/minder/cli/scene.rb', line 26 def focused_frame frames.find(&:focused?) end |
#help_frame ⇒ Object
97 98 99 |
# File 'lib/minder/cli/scene.rb', line 97 def help_frame @help_frame ||= frames.find { |frame| frame.is_a?(HelpFrame) } end |
#main_frame ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/minder/cli/scene.rb', line 83 def main_frame return if .hidden? && help_frame.hidden? if .hidden? help_frame else end end |
#message_frame ⇒ Object
93 94 95 |
# File 'lib/minder/cli/scene.rb', line 93 def @message_frame ||= frames.find { |frame| frame.is_a?(MessageFrame) } end |
#redraw ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/minder/cli/scene.rb', line 101 def redraw refresh resize_frames refresh Curses.curs_set(1) focused_frame.set_cursor_position focused_frame.window_refresh end |
#refresh ⇒ Object
46 47 48 |
# File 'lib/minder/cli/scene.rb', line 46 def refresh frames.map(&:refresh) end |
#resize_frames ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/minder/cli/scene.rb', line 50 def resize_frames frames.map(&:resize) first_frame = frames.first first_frame.move(0, 0) next_height = first_frame.height other_frames = (frames.reject(&:hidden?) - [main_frame]).compact if main_frame other_height = other_frames.reduce(0) do |num, frame| num += frame.height num end available_height = Curses.lines - other_height if available_height > main_frame.desired_height main_frame.height = main_frame.desired_height else main_frame.height = available_height end main_frame.move(next_height, 0) next_height += main_frame.height end (other_frames - [first_frame]).each do |frame| frame.move(next_height, 0) next_height += frame.height end end |
#setup ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/minder/cli/scene.rb', line 17 def setup Curses.ESCDELAY = 0 Curses.noecho Curses.init_screen Curses.timeout = 0 clear Curses.refresh end |
#switch_focus ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/minder/cli/scene.rb', line 30 def switch_focus current_index = frames.find_index(focused_frame) focused_frame.unfocus next_frame = frames[current_index + 1..-1].find { |frame| !frame.hidden? } if next_frame next_frame.focus else frames[0].focus end end |