Last active
January 28, 2024 11:34
-
-
Save tompng/1d246f565ce662dfa74b3376f6215e27 to your computer and use it in GitHub Desktop.
Preview terminal background and foreground
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
raise 'COLORTERM required' unless ENV['COLORTERM'] | |
# Color table from https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit | |
env_names = %w[VGA WinXP PowerShell6 VSCode Win10 Terminal.app PuTTY mIRC xterm Ubuntu Eclipse] | |
env_colors = <<COLORS.lines.map{|l|l.split(' ').map{_1.scan(/\d+/).join(';')}}.transpose | |
0,0,0 0,0,0 0,0,0 12,12,12 0,0,0 0,0,0 0,0,0 0,0,0 1,1,1 0,0,0 | |
170,0,0 128,0,0 205,49,49 197,15,31 153,0,0 187,0,0 127,0,0 205,0,0 222,56,43 205,0,0 | |
0,170,0 0,128,0 13,188,121 19,161,14 0,166,0 0,187,0 0,147,0 0,205,0 57,181,74 0,205,0 | |
170,85,0 128,128,0 229,229,16 193,156,0 153,153,0 187,187,0 252,127,0 205,205,0 255,199,6 205,205,0 | |
0,0,170 0,0,128 36,114,200 0,55,218 0,0,178 0,0,187 0,0,127 0,0,238 0,111,184 0,0,238 | |
170,0,170 128,0,128 188,63,188 136,23,152 178,0,178 187,0,187 156,0,156 205,0,205 118,38,113 205,0,205 | |
0,170,170 0,128,128 17,168,205 58,150,221 0,166,178 0,187,187 0,147,147 0,205,205 44,181,233 0,205,205 | |
170,170,170 192,192,192 229,229,229 204,204,204 191,191,191 187,187,187 210,210,210 229,229,229 204,204,204 229,229,229 | |
85,85,85 128,128,128 102,102,102 118,118,118 102,102,102 85,85,85 127,127,127 127,127,127 128,128,128 0,0,0 | |
255,85,85 255,0,0 241,76,76 231,72,86 229,0,0 255,85,85 255,0,0 255,0,0 255,0,0 255,0,0 | |
85,255,85 0,255,0 35,209,139 22,198,12 0,217,0 85,255,85 0,252,0 0,255,0 0,255,0 0,255,0 | |
255,255,85 255,255,0 245,245,67 249,241,165 230,230,0 255,255,85 255,255,0 255,255,0 255,255,0 255,255,0 | |
85,85,255 0,0,255 59,142,234 59,120,255 0,0,255 85,85,255 0,0,252 92,92,255 0,0,255 92,92,255 | |
255,85,255 255,0,255 214,112,214 180,0,158 229,0,229 255,85,255 255,0,255 255,0,255 255,0,255 255,0,255 | |
85,255,255 0,255,255 41,184,219 97,214,214 0,229,229 85,255,255 0,255,255 0,255,255 0,255,255 0,255,255 | |
255,255,255 255,255,255 229,229,229 242,242,242 229,229,229 255,255,255 255,255,255 255,255,255 255,255,255 255,255,255 | |
COLORS | |
def color_name(val) | |
return 'gray' if val == 8 | |
"#{val>=8 ? 'bright_' : ''}#{%w[black red green yellow blue magenta cyan white][val%8]}" | |
end | |
black, red, green, yellow, blue, magenta, cyan, white, bright = *0..8 | |
gray = bright | black | |
your_env = ARGV[0] | |
[[cyan, white], [cyan, black], [black, white], [white, black], [gray, white], [gray, black], [magenta, black], [magenta, white]].each do |bg, fg| | |
puts "#{color_name(bg)} - #{color_name(fg)}" | |
msg = "Your env(#{your_env}) #{[*'a'..'z'].join}"[0, 20] | |
puts "\e[#{[40, 100][bg / 8] + bg % 8};#{[30, 90][fg / 8] + fg % 8}m#{msg}\e[m" if your_env | |
env_colors.zip(env_names).each do |colors, name| | |
msg = "#{name} #{[*'a'..'z'].join}"[0, 20] | |
puts "\e[48;2;#{colors[bg]};38;2;#{colors[fg]}m#{msg}\e[m" | |
end | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment