Class: Potty::WindowManager
- Inherits:
-
Object
- Object
- Potty::WindowManager
- Defined in:
- lib/potty/window_manager.rb
Overview
Manages curses window lifecycle and refresh coordination
Instance Attribute Summary collapse
-
#max_x ⇒ Object
readonly
Returns the value of attribute max_x.
-
#max_y ⇒ Object
readonly
Returns the value of attribute max_y.
-
#stdscr ⇒ Object
readonly
Returns the value of attribute stdscr.
Instance Method Summary collapse
- #clear_all ⇒ Object
-
#create_window(name, height, width, y, x) ⇒ Object
Create a new window.
-
#destroy_window(name) ⇒ Object
Destroy window.
-
#get_window(name) ⇒ Object
Get existing window.
-
#initialize ⇒ WindowManager
constructor
A new instance of WindowManager.
-
#refresh_all ⇒ Object
Refresh all windows efficiently.
-
#setup(stdscr) ⇒ Object
Called during application setup.
- #update_dimensions ⇒ Object
Constructor Details
#initialize ⇒ WindowManager
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_x ⇒ Object (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_y ⇒ Object (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 |
#stdscr ⇒ Object (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_all ⇒ Object
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_all ⇒ Object
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_dimensions ⇒ Object
21 22 23 |
# File 'lib/potty/window_manager.rb', line 21 def update_dimensions @max_y, @max_x = @stdscr.maxy, @stdscr.maxx end |