Last active
May 6, 2022 06:30
-
-
Save lucascaton/9faa81fcfad80bf7393e93c7f2dd23a4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
require "io/console" | |
COLORS = { | |
black: 0, | |
red: 31, | |
green: 32, | |
blue: 34 | |
} | |
loop do | |
print "❯ " | |
command = "" | |
loop do | |
char = $stdin.getch | |
break if char == "\r" # User pressed <enter> | |
color = char == "e" ? COLORS[:red] : COLORS[:black] # Letter "e" will show up in red | |
printf "\033[#{color}m#{char}\033[#{COLORS[:black]}m" | |
command << char | |
end | |
break if command == "exit" | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment