Class: Minder::Scene

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScene

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

#framesObject

Returns the value of attribute frames.



11
12
13
# File 'lib/minder/cli/scene.rb', line 11

def frames
  @frames
end

Instance Method Details

#clearObject



110
111
112
# File 'lib/minder/cli/scene.rb', line 110

def clear
  Curses.clear
end

#closeObject



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_frameObject



26
27
28
# File 'lib/minder/cli/scene.rb', line 26

def focused_frame
  frames.find(&:focused?)
end

#help_frameObject



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_frameObject



83
84
85
86
87
88
89
90
91
# File 'lib/minder/cli/scene.rb', line 83

def main_frame
  return if message_frame.hidden? && help_frame.hidden?

  if message_frame.hidden?
    help_frame
  else
    message_frame
  end
end

#message_frameObject



93
94
95
# File 'lib/minder/cli/scene.rb', line 93

def message_frame
  @message_frame ||= frames.find { |frame| frame.is_a?(MessageFrame) }
end

#redrawObject



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

#refreshObject



46
47
48
# File 'lib/minder/cli/scene.rb', line 46

def refresh
  frames.map(&:refresh)
end

#resize_framesObject



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

#setupObject



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_focusObject



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