Class: HighLine::Terminal::UnixStty
- Inherits:
-
HighLine::Terminal
- Object
- HighLine::Terminal
- HighLine::Terminal::UnixStty
- Defined in:
- lib/highline/terminal/unix_stty.rb
Overview
HighLine::Terminal option that uses external "stty" program to control terminal options.
Instance Attribute Summary
Attributes inherited from HighLine::Terminal
Instance Method Summary collapse
-
#get_character(input = STDIN) ⇒ String
Get one character from the terminal.
-
#raw_no_echo_mode ⇒ Object
Enter Raw No Echo mode.
-
#restore_mode ⇒ Object
Restore terminal to its default mode.
-
#terminal_size ⇒ Array<Integer, Integer>
A Unix savvy method using stty to fetch the console columns, and rows.
Methods inherited from HighLine::Terminal
#character_mode, #get_line, #get_line_default, #get_line_with_readline, get_terminal, #initialize, #initialize_system_extensions, #jruby?, #raw_no_echo_mode_exec, #readline_read, #rubinius?, #windows?
Constructor Details
This class inherits a constructor from HighLine::Terminal
Instance Method Details
#get_character(input = STDIN) ⇒ String
Get one character from the terminal
48 49 50 |
# File 'lib/highline/terminal/unix_stty.rb', line 48 def get_character(input = STDIN) input.getc end |
#raw_no_echo_mode ⇒ Object
Enter Raw No Echo mode.
36 37 38 39 |
# File 'lib/highline/terminal/unix_stty.rb', line 36 def raw_no_echo_mode save_stty system "stty raw -echo -icanon isig" if input.tty? end |
#restore_mode ⇒ Object
Restore terminal to its default mode
42 43 44 45 |
# File 'lib/highline/terminal/unix_stty.rb', line 42 def restore_mode restore_stty print "\r" end |
#terminal_size ⇒ Array<Integer, Integer>
A Unix savvy method using stty to fetch the console columns, and rows. ... stty does not work in JRuby
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/highline/terminal/unix_stty.rb', line 11 def terminal_size begin require "io/console" winsize = begin IO.console.winsize.reverse rescue NoMethodError nil end return winsize if winsize rescue LoadError end if !@output.tty? [80, 24] elsif /solaris/ =~ RUBY_PLATFORM && `stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/ [Regexp.last_match(2), Regexp.last_match(1)].map(&:to_i) elsif `stty size` =~ /^(\d+)\s(\d+)$/ [Regexp.last_match(2).to_i, Regexp.last_match(1).to_i] else [80, 24] end end |