Skip to content

Instantly share code, notes, and snippets.

@talbergs
Forked from robacarp/stdin.cr
Created August 3, 2018 15:27
Show Gist options
  • Save talbergs/eb3cd34fff2758c9f1a68071f1347618 to your computer and use it in GitHub Desktop.
Save talbergs/eb3cd34fff2758c9f1a68071f1347618 to your computer and use it in GitHub Desktop.
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