Class: TTY::Prompt::Reader::Console Private

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/prompt/reader/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
CSI =

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Console

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 Console.



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

def initialize(input)
  @input = input
  @mode  = Mode.new(input)
  @keys  = Codes.keys
  @escape_codes = [[ESC.ord], CSI.bytes.to_a]
end

Instance Attribute Details

#escape_codesArray[Integer] (readonly)

Escape codes

Returns:

  • (Array[Integer])


25
26
27
# File 'lib/tty/prompt/reader/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/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
# File 'lib/tty/prompt/reader/console.rb', line 43

def get_char(options)
  mode.raw(options[:raw]) do
    mode.echo(options[:echo]) { input.getc }
  end
end