Module: HighLine::SystemExtensions
- Extended by:
- SystemExtensions
- Included in:
- HighLine, SystemExtensions
- Defined in:
- lib/skylight/vendor/cli/highline/system_extensions.rb
Constant Summary collapse
- JRUBY =
defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
- CHARACTER_MODE =
For Debugging purposes only.
"Win32API"
Instance Method Summary collapse
-
#get_character(input = STDIN) ⇒ Object
Windows savvy getc().
- #initialize_system_extensions ⇒ Object
-
#raw_no_echo_mode ⇒ Object
We do not define a raw_no_echo_mode for Windows as _getch turns off echo.
- #restore_mode ⇒ Object
-
#terminal_size ⇒ Object
A Unix savvy method using stty to fetch the console columns, and rows.
Instance Method Details
#get_character(input = STDIN) ⇒ Object
Windows savvy getc().
WARNING: This method ignores input
and reads one character from STDIN
!
119 120 121 |
# File 'lib/skylight/vendor/cli/highline/system_extensions.rb', line 119 def get_character( input = STDIN ) WinAPI._getch end |
#initialize_system_extensions ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/skylight/vendor/cli/highline/system_extensions.rb', line 15 def initialize_system_extensions require 'java' require 'readline' if JRUBY_VERSION =~ /^1.7/ java_import 'jline.console.ConsoleReader' input = @input && @input.to_inputstream output = @output && @output.to_outputstream @java_console = ConsoleReader.new(input, output) @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 =~ /^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(@input.to_channel) @java_output = OutputStreamWriter.new(Channels.newOutputStream(@output.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 |
#raw_no_echo_mode ⇒ Object
We do not define a raw_no_echo_mode for Windows as _getch turns off echo
124 125 |
# File 'lib/skylight/vendor/cli/highline/system_extensions.rb', line 124 def raw_no_echo_mode end |
#restore_mode ⇒ Object
127 128 |
# File 'lib/skylight/vendor/cli/highline/system_extensions.rb', line 127 def restore_mode end |
#terminal_size ⇒ Object
A Unix savvy method using stty to fetch the console columns, and rows. … stty does not work in JRuby
131 132 133 134 135 136 137 138 139 140 |
# File 'lib/skylight/vendor/cli/highline/system_extensions.rb', line 131 def terminal_size format = 'SSSSSssssSS' buf = ([0] * format.size).pack(format) stdout_handle = WinAPI.GetStdHandle(0xFFFFFFF5) WinAPI.GetConsoleScreenBufferInfo(stdout_handle, buf) _, _, _, _, _, left, top, right, bottom, _, _ = buf.unpack(format) return right - left + 1, bottom - top + 1 end |