class TTY::Reader::WinConsole
Constants
- ESC
- EXT_HEX
- NUL_HEX
Attributes
escape_codes[R]
Public Class Methods
new(input)
click to toggle source
# File lib/tty/reader/win_console.rb, line 25 def initialize(input) require_relative "win_api" @input = input @keys = Keys.ctrl_keys.merge(Keys.win_keys) @escape_codes = [[NUL_HEX.ord], [ESC.ord], EXT_HEX.bytes.to_a] end
Public Instance Methods
get_char(echo: true, raw: false, nonblock: false)
click to toggle source
Get a character from console blocking for input
@param [Boolean] echo
whether to echo input back or not, defaults to true
@param [Boolean] raw
whether to use raw mode or not, defaults to false
@param [Boolean] nonblock
whether to wait for input or not, defaults to false
@return [String]
@api private
# File lib/tty/reader/win_console.rb, line 44 def get_char(echo: true, raw: false, nonblock: false) if raw && echo if nonblock get_char_echo_non_blocking else get_char_echo_blocking end elsif raw && !echo nonblock ? get_char_non_blocking : get_char_blocking elsif !raw && !echo nonblock ? get_char_non_blocking : get_char_blocking else @input.getc end end
get_char_blocking()
click to toggle source
# File lib/tty/reader/win_console.rb, line 71 def get_char_blocking WinAPI.getch.chr end
get_char_echo_blocking()
click to toggle source
# File lib/tty/reader/win_console.rb, line 75 def get_char_echo_blocking WinAPI.getche.chr end
get_char_echo_non_blocking()
click to toggle source
# File lib/tty/reader/win_console.rb, line 67 def get_char_echo_non_blocking input_ready? ? get_char_echo_blocking : nil end
get_char_non_blocking()
click to toggle source
Get the char for last key pressed, or if no keypress return nil
@api private
# File lib/tty/reader/win_console.rb, line 63 def get_char_non_blocking input_ready? ? get_char_blocking : nil end
input_ready?()
click to toggle source
Check if IO has user input
@return [Boolean]
@api private
# File lib/tty/reader/win_console.rb, line 84 def input_ready? !WinAPI.kbhit.zero? end