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("msvcrt", "_getch", [ ], "L").Call 39: rescue Exception 40: Win32API.new("crtdll", "_getch", [ ], "L").Call 41: end
Unix savvy getc(). (Second choice.)
WARNING: This method requires the external “stty” program!
# File lib/highline/system_extensions.rb, line 122 122: def get_character( input = STDIN ) 123: raw_no_echo_mode 124: 125: begin 126: input.getbyte 127: ensure 128: restore_mode 129: end 130: end
Unix savvy getc(). (First choice.)
WARNING: This method requires the “termios” library!
# File lib/highline/system_extensions.rb, line 73 73: def get_character( input = STDIN ) 74: return input.getbyte if input.is_a? StringIO 75: 76: old_settings = Termios.getattr(input) 77: 78: new_settings = old_settings.dup 79: new_settings.c_lflag &= ~(Termios::ECHO | Termios::ICANON) 80: new_settings.c_cc[Termios::VMIN] = 1 81: 82: begin 83: Termios.setattr(input, Termios::TCSANOW, new_settings) 84: input.getbyte 85: ensure 86: Termios.setattr(input, Termios::TCSANOW, old_settings) 87: end 88: end
ncurses savvy getc().
# File lib/highline/system_extensions.rb, line 103 103: def get_character( input = STDIN ) 104: FFI::NCurses.initscr 105: FFI::NCurses.cbreak 106: begin 107: FFI::NCurses.curs_set 0 108: input.getbyte 109: ensure 110: FFI::NCurses.endwin 111: end 112: 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 137 137: def raw_no_echo_mode 138: @state = `stty -g` 139: system "stty raw -echo -icanon isig" 140: end
Restores a previously saved input mode.
WARNING: This method requires the external “stty” program!
# File lib/highline/system_extensions.rb, line 147 147: def restore_mode 148: system "stty #{@state}" 149: end
A ncurses savvy method to fetch the console columns, and rows.
# File lib/highline/system_extensions.rb, line 156 156: def terminal_size 157: size = [80, 40] 158: FFI::NCurses.initscr 159: begin 160: size = FFI::NCurses.getmaxyx(stdscr).reverse 161: ensure 162: FFI::NCurses.endwin 163: end 164: size 165: end
A Windows savvy method to fetch the console columns, and rows.
# File lib/highline/system_extensions.rb, line 44 44: def terminal_size 45: m_GetStdHandle = Win32API.new( 'kernel32', 46: 'GetStdHandle', 47: ['L'], 48: 'L' ) 49: m_GetConsoleScreenBufferInfo = Win32API.new( 50: 'kernel32', 'GetConsoleScreenBufferInfo', ['L', 'P'], 'L' 51: ) 52: 53: format = 'SSSSSssssSS' 54: buf = ([0] * format.size).pack(format) 55: stdout_handle = m_GetStdHandle.call(0xFFFFFFF5) 56: 57: m_GetConsoleScreenBufferInfo.call(stdout_handle, buf) 58: _, _, _, _, _, 59: left, top, right, bottom, _, _ = buf.unpack(format) 60: return right - left + 1, bottom - top + 1 61: end
# File lib/highline/system_extensions.rb, line 170 170: def terminal_size 171: java_terminal = @java_terminal || Terminal.getTerminal 172: [ java_terminal.getTerminalWidth, java_terminal.getTerminalHeight ] 173: 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 177 177: def terminal_size 178: if /solaris/ =~ RUBY_PLATFORM and 179: `stty` =~ /\brows = (\d+).*\bcolumns = (\d+)/ 180: [$2, $1].map { |c| x.to_i } 181: else 182: `stty size`.split.map { |x| x.to_i }.reverse 183: end 184: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.