Class: Fatty::ModalSession

Inherits:
Session
  • Object
show all
Defined in:
lib/fatty/session/modal_session.rb

Direct Known Subclasses

PopUpSession, PromptSession

Instance Attribute Summary collapse

Attributes inherited from Session

#counter, #keymap, #terminal, #views

Instance Method Summary collapse

Methods inherited from Session

#add_view, #handle_action, #init, #initialize, #inspect, #keymap_contexts, #persist!, #resolve_action, #tick, #update, #view

Methods included from Actionable

included

Constructor Details

This class inherits a constructor from Fatty::Session

Instance Attribute Details

#winObject

Returns the value of attribute win.



5
6
7
# File 'lib/fatty/session/modal_session.rb', line 5

def win
  @win
end

Instance Method Details

#clamp_height(height, max_height:, min_height:) ⇒ Object



57
58
59
# File 'lib/fatty/session/modal_session.rb', line 57

def clamp_height(height, max_height:, min_height:)
  height.clamp(min_height, max_height)
end

#clamp_width(width, max_width:, hard_max: nil) ⇒ Object



51
52
53
54
55
# File 'lib/fatty/session/modal_session.rb', line 51

def clamp_width(width, max_width:, hard_max: nil)
  width = [width, max_width].min
  width = [width, hard_max].min if hard_max
  width
end

#closeObject



8
9
10
11
12
13
14
# File 'lib/fatty/session/modal_session.rb', line 8

def close
  Fatty.debug("#{self.class}#close: object_id=#{object_id}", tag: :session)
  old_win = win
  self.win = nil
  safely_close_window(old_win)
  nil
end

#geometry(cols:, rows:) ⇒ Object

Return the outer width and height of the window for this modal, including any padding and borders.

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/fatty/session/modal_session.rb', line 37

def geometry(cols:, rows:)
  raise NotImplementedError, "#{self.class} must implement #geometry"
end

#handle_resizeObject



16
17
18
19
# File 'lib/fatty/session/modal_session.rb', line 16

def handle_resize
  rebuild_windows!
  []
end

#max_height(rows:, margin:, min_height:) ⇒ Object



47
48
49
# File 'lib/fatty/session/modal_session.rb', line 47

def max_height(rows:, margin:, min_height:)
  [rows - (margin * 2), min_height].max
end

#max_width(cols:, margin:, min_width:) ⇒ Object

Common helpers for computing geometry



43
44
45
# File 'lib/fatty/session/modal_session.rb', line 43

def max_width(cols:, margin:, min_width:)
  [cols - (margin * 2), min_width].max
end

#rebuild_windows!Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fatty/session/modal_session.rb', line 21

def rebuild_windows!
  old_win = win
  self.win = nil
  safely_close_window(old_win)

  cols = ::Curses.cols
  rows = ::Curses.lines
  width, height = geometry(cols: cols, rows: rows)
  x = (cols - width) / 2
  y = (rows - height) / 2
  self.win = ::Curses::Window.new(height, width, y, x)
  nil
end