work correctly in JRuby manually installing the ffi-ncurses gem is the only way to get highline to operate correctly in JRuby. The ncurses library is only present on unix platforms so this is not a solution for using highline in JRuby on windows.
Windows savvy getc().
WARNING: This method ignores input and reads one character from STDIN!
# File lib/highline/system_extensions.rb, line 37 37: def get_character( input = STDIN ) 38: Win32API.new("crtdll", "_getch", [ ], "L").Call 39: end
ncurses savvy getc(). (JRuby choice.)
# File lib/highline/system_extensions.rb, line 100 100: def get_character( input = STDIN ) 101: FFI::NCurses.initscr 102: FFI::NCurses.cbreak 103: begin 104: FFI::NCurses.curs_set 0 105: input.getbyte 106: ensure 107: FFI::NCurses.endwin 108: end 109: end
Unix savvy getc(). (First choice.)
WARNING: This method requires the “termios” library!
# File lib/highline/system_extensions.rb, line 72 72: def get_character( input = STDIN ) 73: old_settings = Termios.getattr(input) 74: 75: new_settings = old_settings.dup 76: new_settings.c_lflag &= ~(Termios::ECHO | Termios::ICANON) 77: new_settings.c_cc[Termios::VMIN] = 1 78: 79: begin 80: Termios.setattr(input, Termios::TCSANOW, new_settings) 81: input.getbyte 82: ensure 83: Termios.setattr(input, Termios::TCSANOW, old_settings) 84: end 85: end
Unix savvy getc(). (Second choice.)
WARNING: This method requires the external “stty” program!
# File lib/highline/system_extensions.rb, line 126 126: def get_character( input = STDIN ) 127: raw_no_echo_mode 128: 129: begin 130: input.getbyte 131: ensure 132: restore_mode 133: end 134: end
Switched the input mode to raw and disables echo.
WARNING: This method requires the external “stty” program!
# File lib/highline/system_extensions.rb, line 141 141: def raw_no_echo_mode 142: @state = `stty -g` 143: system "stty raw -echo -icanon isig" 144: end
Restores a previously saved input mode.
WARNING: This method requires the external “stty” program!
# File lib/highline/system_extensions.rb, line 151 151: def restore_mode 152: system "stty #{@state}" 153: end
A Windows savvy method to fetch the console columns, and rows.
# File lib/highline/system_extensions.rb, line 42 42: def terminal_size 43: m_GetStdHandle = Win32API.new( 'kernel32', 44: 'GetStdHandle', 45: ['L'], 46: 'L' ) 47: m_GetConsoleScreenBufferInfo = Win32API.new( 48: 'kernel32', 'GetConsoleScreenBufferInfo', ['L', 'P'], 'L' 49: ) 50: 51: format = 'SSSSSssssSS' 52: buf = ([0] * format.size).pack(format) 53: stdout_handle = m_GetStdHandle.call(0xFFFFFFF5) 54: 55: m_GetConsoleScreenBufferInfo.call(stdout_handle, buf) 56: bufx, bufy, curx, cury, wattr, 57: left, top, right, bottom, maxx, maxy = buf.unpack(format) 58: return right - left + 1, bottom - top + 1 59: end
A ncurses savvy method to fetch the console columns, and rows.
# File lib/highline/system_extensions.rb, line 160 160: def terminal_size 161: size = [80, 40] 162: FFI::NCurses.initscr 163: begin 164: size = FFI::NCurses.getmaxyx(stdscr).reverse 165: ensure 166: FFI::NCurses.endwin 167: end 168: size 169: end
A Unix savvy method using stty that to fetch the console columns, and rows. … stty does not work in JRuby
# File lib/highline/system_extensions.rb, line 173 173: def terminal_size 174: if /solaris/ =~ RUBY_PLATFORM and 175: `stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/ 176: [$2, $1].map { |c| x.to_i } 177: else 178: `stty size`.split.map { |x| x.to_i }.reverse 179: end 180: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.