class Minder::Scene

Constants

ESCDELAY

Attributes

frames[RW]

Public Class Methods

new() click to toggle source
# File lib/minder/cli/scene.rb, line 13
def initialize
  self.frames = []
end

Public Instance Methods

clear() click to toggle source
# File lib/minder/cli/scene.rb, line 110
def clear
  Curses.clear
end
close() click to toggle source
# File lib/minder/cli/scene.rb, line 114
def close
  Curses.close_screen
end
focus_frame(frame) click to toggle source
# File lib/minder/cli/scene.rb, line 41
def focus_frame(frame)
  focused_frame.unfocus
  frame.focus
end
focused_frame() click to toggle source
# File lib/minder/cli/scene.rb, line 26
def focused_frame
  frames.find(&:focused?)
end
help_frame() click to toggle source
# File lib/minder/cli/scene.rb, line 97
def help_frame
  @help_frame ||= frames.find { |frame| frame.is_a?(HelpFrame) }
end
main_frame() click to toggle source
# 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_frame() click to toggle source
# File lib/minder/cli/scene.rb, line 93
def message_frame
  @message_frame ||= frames.find { |frame| frame.is_a?(MessageFrame) }
end
redraw() click to toggle source
# 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() click to toggle source
# File lib/minder/cli/scene.rb, line 46
def refresh
  frames.map(&:refresh)
end
resize_frames() click to toggle source
# 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() click to toggle source
# 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() click to toggle source
# 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