Module: Vedeu::Terminal
Instance Method Summary collapse
- #centre ⇒ Object
- #clear_last_line ⇒ Object
- #console ⇒ Object
- #height ⇒ Object
- #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 ⇒ Object
Instance Method Details
#centre ⇒ Object
65 66 67 |
# File 'lib/vedeu/support/terminal.rb', line 65 def centre [(height / 2), (width / 2)] end |
#clear_last_line ⇒ Object
61 62 63 |
# File 'lib/vedeu/support/terminal.rb', line 61 def clear_last_line Esc.set_position((height - 1), 1) + Esc.string('clear_line') end |
#console ⇒ Object
81 82 83 |
# File 'lib/vedeu/support/terminal.rb', line 81 def console IO.console end |
#height ⇒ Object
73 74 75 |
# File 'lib/vedeu/support/terminal.rb', line 73 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
57 58 59 |
# File 'lib/vedeu/support/terminal.rb', line 57 def raw_mode? @mode == :raw end |
#restore_screen ⇒ Object
48 49 50 51 |
# File 'lib/vedeu/support/terminal.rb', line 48 def restore_screen output Esc.string 'screen_exit' output clear_last_line end |
#set_cursor_mode ⇒ Object
53 54 55 |
# File 'lib/vedeu/support/terminal.rb', line 53 def set_cursor_mode output Esc.string 'show_cursor' unless raw_mode? end |
#size ⇒ Object
77 78 79 |
# File 'lib/vedeu/support/terminal.rb', line 77 def size console.winsize end |
#width ⇒ Object
69 70 71 |
# File 'lib/vedeu/support/terminal.rb', line 69 def width size.last end |