Skip to content

Instantly share code, notes, and snippets.

@talbergs talbergs/stdin.cr

forked from robacarp/stdin.cr
Created Aug 3, 2018
Embed
What would you like to do?
crystal single character read from stdin
print "Type something: "
entered_chars = [] of Char
STDIN.raw do
loop do
char = STDIN.read_char
next if char.nil?
entered_chars << char
print char
# exit when user enters ^d
break if char.ord == 4
end
end
puts
puts "You said: #{entered_chars.map(&.to_s).join("")}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.