-
-
Save talbergs/eb3cd34fff2758c9f1a68071f1347618 to your computer and use it in GitHub Desktop.
crystal single character read from stdin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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