Class: Thaum::Terminal
- Inherits:
-
Object
- Object
- Thaum::Terminal
- Defined in:
- lib/thaum/terminal.rb
Overview
Manages terminal setup and teardown: alternate screen, cursor, mouse, and bracketed paste.
Instance Method Summary collapse
-
#initialize(input: $stdin, output: $stdout) ⇒ Terminal
constructor
A new instance of Terminal.
- #setup ⇒ Object
- #size ⇒ Object
- #teardown ⇒ Object
Constructor Details
#initialize(input: $stdin, output: $stdout) ⇒ Terminal
Returns a new instance of Terminal.
8 9 10 11 |
# File 'lib/thaum/terminal.rb', line 8 def initialize(input: $stdin, output: $stdout) @input = input @output = output end |
Instance Method Details
#setup ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/thaum/terminal.rb', line 13 def setup @original_stty = stty_save @input.raw! write Seq::ALT_SCREEN_ON write Seq::CURSOR_HIDE write Seq::BRACKETED_PASTE_ON write Seq::SGR_MOUSE_ON write Seq::CELL_MOTION_ON end |
#size ⇒ Object
32 33 34 35 |
# File 'lib/thaum/terminal.rb', line 32 def size rows, cols = @input.winsize [cols, rows] end |
#teardown ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/thaum/terminal.rb', line 23 def teardown write Seq::CELL_MOTION_OFF write Seq::SGR_MOUSE_OFF write Seq::BRACKETED_PASTE_OFF write Seq::CURSOR_SHOW write Seq::ALT_SCREEN_OFF stty_restore(@original_stty) end |