Sha256: 477321fb76b6d8b09fa3bf5fa981604587c43c255182e127edcaaad422dc63de
Contents?: true
Size: 1.5 KB
Versions: 1
Compression:
Stored size: 1.5 KB
Contents
module Vedeu module Terminal extend self 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 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 def output(stream = '') console.print(stream) stream end def initialize_screen(&block) output Esc.string 'screen_init' yield end def clear_screen output Esc.string 'clear' end def restore_screen output Esc.string 'screen_exit' output clear_last_line end def set_cursor_mode output Esc.string 'show_cursor' unless raw_mode? end def raw_mode? @mode == :raw end def clear_last_line Esc.set_position((height - 1), 1) + Esc.string('clear_line') end def centre [(height / 2), (width / 2)] end # @return [Fixnum] The total width of the current terminal. def width size.last end # @return [Fixnum] The total height of the current terminal. def height size.first end def size console.winsize end def console IO.console end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
vedeu-0.1.15 | lib/vedeu/support/terminal.rb |