Class: Potty::WindowManager

Inherits:
Object
  • Object
show all
Defined in:
lib/potty/window_manager.rb

Overview

Manages curses window lifecycle and refresh coordination

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWindowManager

Returns a new instance of WindowManager.



10
11
12
13
# File 'lib/potty/window_manager.rb', line 10

def initialize
  @windows = {}
  @stdscr = nil
end

Instance Attribute Details

#max_xObject (readonly)

Returns the value of attribute max_x.



8
9
10
# File 'lib/potty/window_manager.rb', line 8

def max_x
  @max_x
end

#max_yObject (readonly)

Returns the value of attribute max_y.



8
9
10
# File 'lib/potty/window_manager.rb', line 8

def max_y
  @max_y
end

#stdscrObject (readonly)

Returns the value of attribute stdscr.



8
9
10
# File 'lib/potty/window_manager.rb', line 8

def stdscr
  @stdscr
end

Instance Method Details

#clear_allObject



50
51
52
53
# File 'lib/potty/window_manager.rb', line 50

def clear_all
  @stdscr.clear
  @windows.values.each(&:clear)
end

#create_window(name, height, width, y, x) ⇒ Object

Create a new window



26
27
28
29
30
# File 'lib/potty/window_manager.rb', line 26

def create_window(name, height, width, y, x)
  win = ::Curses::Window.new(height, width, y, x)
  @windows[name] = win
  win
end

#destroy_window(name) ⇒ Object

Destroy window



38
39
40
41
# File 'lib/potty/window_manager.rb', line 38

def destroy_window(name)
  @windows[name]&.close
  @windows.delete(name)
end

#get_window(name) ⇒ Object

Get existing window



33
34
35
# File 'lib/potty/window_manager.rb', line 33

def get_window(name)
  @windows[name]
end

#refresh_allObject

Refresh all windows efficiently



44
45
46
47
48
# File 'lib/potty/window_manager.rb', line 44

def refresh_all
  @stdscr.noutrefresh
  @windows.values.each(&:noutrefresh)
  ::Curses.doupdate
end

#setup(stdscr) ⇒ Object

Called during application setup



16
17
18
19
# File 'lib/potty/window_manager.rb', line 16

def setup(stdscr)
  @stdscr = stdscr
  update_dimensions
end

#update_dimensionsObject



21
22
23
# File 'lib/potty/window_manager.rb', line 21

def update_dimensions
  @max_y, @max_x = @stdscr.maxy, @stdscr.maxx
end