Module: Vedeu::Terminal
Instance Method Summary collapse
- #centre ⇒ Object
- #clear_last_line ⇒ Object
- #clear_screen ⇒ Object
- #console ⇒ Object
-
#height ⇒ Fixnum
The total height of the current terminal.
- #initialize_screen(&block) ⇒ Object
- #input ⇒ Object
- #open(mode, &block) ⇒ Object
- #output(stream = '') ⇒ Object
- #raw_mode? ⇒ Boolean
- #restore_screen ⇒ Object
- #set_cursor_mode ⇒ Object
- #size ⇒ Object
-
#width ⇒ Fixnum
The total width of the current terminal.
Instance Method Details
#centre ⇒ Object
69 70 71 |
# File 'lib/vedeu/support/terminal.rb', line 69 def centre [(height / 2), (width / 2)] end |
#clear_last_line ⇒ Object
65 66 67 |
# File 'lib/vedeu/support/terminal.rb', line 65 def clear_last_line Esc.set_position((height - 1), 1) + Esc.string('clear_line') end |
#clear_screen ⇒ Object
48 49 50 |
# File 'lib/vedeu/support/terminal.rb', line 48 def clear_screen output Esc.string 'clear' end |
#console ⇒ Object
87 88 89 |
# File 'lib/vedeu/support/terminal.rb', line 87 def console IO.console end |
#height ⇒ Fixnum
Returns The total height of the current terminal.
79 80 81 |
# File 'lib/vedeu/support/terminal.rb', line 79 def height size.first end |
#initialize_screen(&block) ⇒ Object
42 43 44 45 46 |
# File 'lib/vedeu/support/terminal.rb', line 42 def initialize_screen(&block) output Esc.string 'screen_init' yield end |
#input ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/vedeu/support/terminal.rb', line 21 def input if raw_mode? keys = console.getch if keys.ord == 27 keys << console.read_nonblock(3) rescue nil keys << console.read_nonblock(2) rescue nil end keys else console.gets.chomp end end |
#open(mode, &block) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/vedeu/support/terminal.rb', line 5 def open(mode, &block) @mode = mode if block_given? if raw_mode? console.raw { initialize_screen { yield } } else console.cooked { initialize_screen { yield } } end end ensure restore_screen end |
#output(stream = '') ⇒ Object
36 37 38 39 40 |
# File 'lib/vedeu/support/terminal.rb', line 36 def output(stream = '') console.print(stream) stream end |
#raw_mode? ⇒ Boolean
61 62 63 |
# File 'lib/vedeu/support/terminal.rb', line 61 def raw_mode? @mode == :raw end |
#restore_screen ⇒ Object
52 53 54 55 |
# File 'lib/vedeu/support/terminal.rb', line 52 def restore_screen output Esc.string 'screen_exit' output clear_last_line end |
#set_cursor_mode ⇒ Object
57 58 59 |
# File 'lib/vedeu/support/terminal.rb', line 57 def set_cursor_mode output Esc.string 'show_cursor' unless raw_mode? end |
#size ⇒ Object
83 84 85 |
# File 'lib/vedeu/support/terminal.rb', line 83 def size console.winsize end |
#width ⇒ Fixnum
Returns The total width of the current terminal.
74 75 76 |
# File 'lib/vedeu/support/terminal.rb', line 74 def width size.last end |