WARNING: This requires the external "stty" program!
# File lib/highline/system_extensions.rb, line 14 def initialize if JRUBY require 'java' if JRUBY_VERSION =~ %r^1.7/ java_import 'jline.console.ConsoleReader' @java_console = ConsoleReader.new($stdin.to_inputstream, $stdout.to_outputstream) @java_console.set_history_enabled(false) @java_console.set_bell_enabled(true) @java_console.set_pagination_enabled(false) @java_terminal = @java_console.getTerminal elsif JRUBY_VERSION =~ %r^1.6/ java_import 'java.io.OutputStreamWriter' java_import 'java.nio.channels.Channels' java_import 'jline.ConsoleReader' java_import 'jline.Terminal' @java_input = Channels.newInputStream($stdin.to_channel) @java_output = OutputStreamWriter.new(Channels.newOutputStream($stdout.to_channel)) @java_terminal = Terminal.getTerminal @java_console = ConsoleReader.new(@java_input, @java_output) @java_console.setUseHistory(false) @java_console.setBellEnabled(true) @java_console.setUsePagination(false) end end end
# File lib/highline/system_extensions.rb, line 44 def get_character( input = STDIN ) input.getbyte end
We do not define a #raw_no_echo_mode for Windows as _getch turns off echo
# File lib/highline/system_extensions.rb, line 74 def raw_no_echo_mode end
# File lib/highline/system_extensions.rb, line 77 def restore_mode end
A Windows savvy method to fetch the console columns, and rows.
# File lib/highline/system_extensions.rb, line 81 def terminal_size m_GetStdHandle = Win32API.new( 'kernel32', 'GetStdHandle', ['L'], 'L' ) m_GetConsoleScreenBufferInfo = Win32API.new( 'kernel32', 'GetConsoleScreenBufferInfo', ['L', 'P'], 'L' ) format = 'SSSSSssssSS' buf = ([0] * format.size).pack(format) stdout_handle = m_GetStdHandle.call(0xFFFFFFF5) m_GetConsoleScreenBufferInfo.call(stdout_handle, buf) _, _, _, _, _, left, top, right, bottom, _, _ = buf.unpack(format) return right - left + 1, bottom - top + 1 end