raw console i/o under Ruby
Seems to me, like there isn't a place on the internet documenting basic, simple, raw console i/o under Ruby.
So here are a few useful bits that have been tested under Linux:
read characters without echo on the cosole:
require 'io/console' # for getch char = STDIN.getch
output character by character:
concatenate characters to string:
string = string + char
check for enter key:
if char == "\\r"
check for CTRL-C:
if char.ord == 3 # is this portable?
check for backspace:
if char.ord == 127 # is this portable?
react to backspace:
print "\\b \\b" # erase last character string.chop
Tomáš Pospíšek, 2016-10-24