Created
December 21, 2018 21:09
-
-
Save justinhj/43cacd13de0d0ef847f18f9cd966e9ee to your computer and use it in GitHub Desktop.
vt100 in ruby
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
# http://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html | |
# Colours | |
print "\u001b[30m A \u001b[31m B \u001b[32m C \u001b[33m D \u001b[0m\n" | |
print "\u001b[34m E \u001b[35m F \u001b[36m G \u001b[37m H \u001b[0m\n" | |
print "\n" | |
# Bright colours | |
print "\u001b[30;1m A \u001b[31;1m B \u001b[32;1m C \u001b[33;1m D \u001b[0;1m\n" | |
print "\u001b[34;1m E \u001b[35;1m F \u001b[36;1m G \u001b[37;1m H \u001b[0;1m\n" | |
print "\n" | |
# 256 Colours | |
(0...16).each do |i| | |
(0...16).each do |j| | |
code = (i * 16 + j).to_s | |
printf("\u001b[38;5;%sm%4s", code, code.ljust(4)) | |
end | |
print "\u001b[0m" | |
print "\n" | |
end | |
print "\n" | |
# Background colours | |
print "\u001b[40m A \u001b[41m B \u001b[42m C \u001b[43m D \u001b[0m" | |
print "\u001b[44m A \u001b[45m B \u001b[46m C \u001b[47m D \u001b[0m" | |
print "\u001b[40;1m A \u001b[41;1m B \u001b[42;1m C \u001b[43;1m D \u001b[0m" | |
print "\u001b[44;1m A \u001b[45;1m B \u001b[46;1m C \u001b[47;1m D \u001b[0m" | |
print "\n" | |
print "\n" | |
# Background colours 256 | |
(0...16).each do |i| | |
(0...16).each do |j| | |
code = (i * 16 + j).to_s | |
printf("\u001b[48;5;%sm%4s", code, code.ljust(4)) | |
end | |
print "\u001b[0m" | |
print "\n" | |
end | |
print "\n" | |
# bold italic and underline | |
print "\u001b[1m BOLD \u001b[0m\u001b[4m Underline \u001b[0m\u001b[7m Reversed \u001b[0m\n\n" | |
# Movement | |
move_up = "\u001b[1A" | |
move_down = "\u001b[1B" | |
move_right = "\u001b[1C" | |
move_left = "\u001b[1D" | |
print "Merry Christmas!" | |
sleep 1 | |
print "\u001b[16DHappy New Year!\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment