Class: Przn::Terminal
- Inherits:
-
Object
- Object
- Przn::Terminal
- Defined in:
- lib/przn/terminal.rb
Constant Summary collapse
- MOUSE_OFF =
"\e[?1006l\e[?1003l\e[?1002l\e[?1000l"
Instance Method Summary collapse
- #cell_pixel_size ⇒ Object
- #clear ⇒ Object
- #enter_alt_screen ⇒ Object
- #flush ⇒ Object
- #getch ⇒ Object
- #height ⇒ Object
- #hide_cursor ⇒ Object
-
#initialize(input: $stdin, output: $stdout) ⇒ Terminal
constructor
A new instance of Terminal.
- #leave_alt_screen ⇒ Object
- #move_to(row, col) ⇒ Object
- #raw(&block) ⇒ Object
- #show_cursor ⇒ Object
- #width ⇒ Object
- #write(str) ⇒ Object
Constructor Details
#initialize(input: $stdin, output: $stdout) ⇒ Terminal
Returns a new instance of Terminal.
9 10 11 12 |
# File 'lib/przn/terminal.rb', line 9 def initialize(input: $stdin, output: $stdout) @in = input @out = output end |
Instance Method Details
#cell_pixel_size ⇒ Object
17 18 19 |
# File 'lib/przn/terminal.rb', line 17 def cell_pixel_size @cell_pixel_size ||= query_cell_pixel_size || [10, 20] end |
#clear ⇒ Object
32 33 34 |
# File 'lib/przn/terminal.rb', line 32 def clear write "\e[2J\e[H" end |
#enter_alt_screen ⇒ Object
48 49 50 51 |
# File 'lib/przn/terminal.rb', line 48 def enter_alt_screen write "\e[?1049h" write MOUSE_OFF end |
#flush ⇒ Object
28 29 30 |
# File 'lib/przn/terminal.rb', line 28 def flush @out.flush end |
#getch ⇒ Object
22 |
# File 'lib/przn/terminal.rb', line 22 def getch = @in.getch |
#height ⇒ Object
15 |
# File 'lib/przn/terminal.rb', line 15 def height = @in.winsize[0] |
#hide_cursor ⇒ Object
40 41 42 |
# File 'lib/przn/terminal.rb', line 40 def hide_cursor write "\e[?25l" end |
#leave_alt_screen ⇒ Object
53 54 55 56 |
# File 'lib/przn/terminal.rb', line 53 def leave_alt_screen write MOUSE_OFF write "\e[?1049l" end |
#move_to(row, col) ⇒ Object
36 37 38 |
# File 'lib/przn/terminal.rb', line 36 def move_to(row, col) write "\e[#{row};#{col}H" end |
#raw(&block) ⇒ Object
21 |
# File 'lib/przn/terminal.rb', line 21 def raw(&block) = @in.raw(&block) |
#show_cursor ⇒ Object
44 45 46 |
# File 'lib/przn/terminal.rb', line 44 def show_cursor write "\e[?25h" end |
#width ⇒ Object
14 |
# File 'lib/przn/terminal.rb', line 14 def width = @in.winsize[1] |
#write(str) ⇒ Object
24 25 26 |
# File 'lib/przn/terminal.rb', line 24 def write(str) @out.write(str) end |