Sha256: 2a704be2a2ba059843fc85ae0902b088e74ea2bce0a4db3c6fec0c876fb970e5

Contents?: true

Size: 347 Bytes

Versions: 7

Compression:

Stored size: 347 Bytes

Contents

require_relative '../lib/tty-reader'

reader = TTY::Reader.new

puts "Press a key (or Ctrl-X to exit)"

loop do
  print reader.cursor.clear_line
  print "=> "
  char = reader.read_keypress(nonblock: true)
  if ?\C-x == char
    puts "Exiting..."
    exit
  elsif char
    puts "#{char.inspect} [#{char.ord}] (hex: #{char.ord.to_s(16)})"
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
pokedex-terminal-0.2.8 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/examples/keypress_nonblock.rb
pokedex-terminal-0.2.7 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/examples/keypress_nonblock.rb
pokedex-terminal-0.2.6 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/examples/keypress_nonblock.rb
pokedex-terminal-0.2.5 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/examples/keypress_nonblock.rb
pokedex-terminal-0.2.4 vendor/bundle/ruby/2.7.0/gems/tty-reader-0.7.0/examples/keypress_nonblock.rb
tty-reader-0.7.0 examples/keypress_nonblock.rb
tty-reader-0.6.0 examples/keypress_nonblock.rb