Class: TTY::Prompt::Reader::WinConsole Private

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/prompt/reader/win_console.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

ESC =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"\e".freeze
NUL_HEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"\x00".freeze
EXT_HEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"\xE0".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ WinConsole

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of WinConsole.



27
28
29
30
31
32
# File 'lib/tty/prompt/reader/win_console.rb', line 27

def initialize(input)
  require_relative 'win_api'
  @input = input
  @keys = Codes.win_keys
  @escape_codes = [[NUL_HEX.ord], [ESC.ord], EXT_HEX.bytes.to_a]
end

Instance Attribute Details

#escape_codesArray[Integer] (readonly)

Escape codes

Returns:

  • (Array[Integer])


25
26
27
# File 'lib/tty/prompt/reader/win_console.rb', line 25

def escape_codes
  @escape_codes
end

#keysHash[Symbol] (readonly)

Key codes

Returns:

  • (Hash[Symbol])


18
19
20
# File 'lib/tty/prompt/reader/win_console.rb', line 18

def keys
  @keys
end

Instance Method Details

#get_char(options) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get a character from console with echo

Parameters:

  • options (Hash[Symbol])

Options Hash (options):

  • :echo (Symbol)

    the echo toggle

Returns:

  • (String)


43
44
45
46
47
48
49
# File 'lib/tty/prompt/reader/win_console.rb', line 43

def get_char(options)
  if options[:raw]
    WinAPI.getch.chr
  else
    options[:echo] ? @input.getc : WinAPI.getch.chr
  end
end