Class: TuiTui::TerminalSession
- Inherits:
-
Object
- Object
- TuiTui::TerminalSession
- Defined in:
- lib/tui_tui/terminal_session.rb
Overview
Owns raw mode, alternate screen, and restoration traps for one TUI session.
Constant Summary collapse
- RESTORE_SIGNALS =
%w[TERM HUP INT].freeze
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(console:, output:, events:, mouse:) ⇒ TerminalSession
constructor
A new instance of TerminalSession.
- #start ⇒ Object
Constructor Details
#initialize(console:, output:, events:, mouse:) ⇒ TerminalSession
Returns a new instance of TerminalSession.
10 11 12 13 14 15 16 |
# File 'lib/tui_tui/terminal_session.rb', line 10 def initialize(console:, output:, events:, mouse:) @console = console @output = output @events = events @mouse = mouse @closed = false end |
Instance Method Details
#close ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tui_tui/terminal_session.rb', line 27 def close # Close is called from ensure, at_exit, and signal traps. return if @closed @closed = true @output.write((@mouse ? Ansi::MOUSE_OFF : "") + Ansi::SHOW + Ansi::ALT_OFF) @output.flush begin @console.cooked! rescue StandardError nil end trap("WINCH", @prev_winch || "DEFAULT") if defined?(@prev_winch) restore_signal_traps end |
#start ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/tui_tui/terminal_session.rb', line 18 def start @console.raw! @output.write(Ansi::ALT_ON + Ansi::HIDE + Ansi::CLEAR + (@mouse ? Ansi::MOUSE_ON : "")) @output.flush @prev_winch = trap("WINCH") { @events.resized! } install_restore_traps at_exit { close } end |