Class: Legion::TTY::ScreenManager
- Inherits:
-
Object
- Object
- Legion::TTY::ScreenManager
- Defined in:
- lib/legion/tty/screen_manager.rb
Instance Attribute Summary collapse
-
#overlay ⇒ Object
readonly
Returns the value of attribute overlay.
Instance Method Summary collapse
- #active_screen ⇒ Object
- #dismiss_overlay ⇒ Object
- #drain_queue ⇒ Object
- #enqueue(update) ⇒ Object
-
#initialize ⇒ ScreenManager
constructor
A new instance of ScreenManager.
- #pop ⇒ Object
- #push(screen) ⇒ Object
- #show_overlay(overlay_obj) ⇒ Object
- #teardown_all ⇒ Object
Constructor Details
#initialize ⇒ ScreenManager
Returns a new instance of ScreenManager.
8 9 10 11 12 13 |
# File 'lib/legion/tty/screen_manager.rb', line 8 def initialize @stack = [] @overlay = nil @render_queue = Queue.new @mutex = Mutex.new end |
Instance Attribute Details
#overlay ⇒ Object (readonly)
Returns the value of attribute overlay.
6 7 8 |
# File 'lib/legion/tty/screen_manager.rb', line 6 def @overlay end |
Instance Method Details
#active_screen ⇒ Object
33 34 35 |
# File 'lib/legion/tty/screen_manager.rb', line 33 def active_screen @mutex.synchronize { @stack.last } end |
#dismiss_overlay ⇒ Object
41 42 43 |
# File 'lib/legion/tty/screen_manager.rb', line 41 def @mutex.synchronize { @overlay = nil } end |
#drain_queue ⇒ Object
49 50 51 52 53 |
# File 'lib/legion/tty/screen_manager.rb', line 49 def drain_queue updates = [] updates << @render_queue.pop until @render_queue.empty? updates end |
#enqueue(update) ⇒ Object
45 46 47 |
# File 'lib/legion/tty/screen_manager.rb', line 45 def enqueue(update) @render_queue.push(update) end |
#pop ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/legion/tty/screen_manager.rb', line 23 def pop @mutex.synchronize do return if @stack.size <= 1 screen = @stack.pop screen.teardown @stack.last&.activate end end |
#push(screen) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/legion/tty/screen_manager.rb', line 15 def push(screen) @mutex.synchronize do @stack.last&.deactivate @stack.push(screen) screen.activate end end |
#show_overlay(overlay_obj) ⇒ Object
37 38 39 |
# File 'lib/legion/tty/screen_manager.rb', line 37 def () @mutex.synchronize { @overlay = } end |
#teardown_all ⇒ Object
55 56 57 58 59 60 |
# File 'lib/legion/tty/screen_manager.rb', line 55 def teardown_all @mutex.synchronize do @stack.reverse_each(&:teardown) @stack.clear end end |