rewrite show-colors script in Ruby

master
an 2019-09-05 16:45:56 -04:00
parent 2acc9798de
commit 5ed04a948b
2 changed files with 94 additions and 84 deletions

View File

@ -1,90 +1,7 @@
#!/usr/bin/env fish
function show-colors -d "Displays all of the terminal colors"
# hashmaps? what are those!? :D - fish
set name0 regular
set name1 bold
set name2 faint
set name3 italic
set name4 underline
set name5 blink
set name6 blink2
set name7 reverse
set name8 conceal
set name9 strike
set name11 font1
set name12 font2
set name13 font3
set name14 font4
set name15 font5
set name16 font6
set name17 font7
set name18 font8
set name19 font9
set name20 fraktur
set name21 doubleline
set name51 framed
set name52 encircled
set name53 overlined
set name60 irsline
set name61 idoubleline
set name62 ilsline
set name63 ioverline2
set name64 istress
echo "Terminal modes"
for mode in (seq 0 9) (seq 11 21) (seq 51 53) (seq 60 64)
set name name$mode
printf "Mode %2d: " $mode
for bg in 49 (seq 40 47)
echo -n \e"[$mode;"$bg"mlorem"
end
echo \e"[0m" \($$name\)
end
echo
echo "4 bit color"
for bg in 49 (seq 40 47)
for fg in 39 (seq 30 37)
echo -n \e"[$mode;$bg;"$fg"m$mode;$bg;$fg"
end
echo \e"[0m"
end
echo
echo "8 bit color"
for fg in (seq 0 15)
echo -n \e"[48;5;"$fg"m "
end
echo \e"[0m"
for fg in (seq 232 255)
echo -n \e"[48;5;"$fg"m "
end
echo \e"[0m"
for fg in (seq 16 231)
echo -n \e"[48;5;"$fg"m "
test (math \( $fg - 15 \) % 36) -eq 0
and echo \e"[0m"
end
echo \e"[0m"
set roygcbvp "242;119;119" "242;160;119" "242;217;119" "137;242;119" \
"119;234;242" "119;123;242" "180;119;242" "242;119;236"
set flag "91;207;250" "245;171;185" "255;255;255"
echo "24 bit color"
for fg in $roygcbvp
echo -n \e"[48;2;"$fg"m "
end
echo \e"[0m"
for fg in 1 2 3 2 1
echo -n \e"[48;2;"$flag[$fg]"m "
end
echo \e"[0m"
$_agw_dir_rc/text/show-colors
end
## EOF

93
text/show-colors Executable file
View File

@ -0,0 +1,93 @@
#!/usr/bin/env ruby
def print_flag palette, num, colors
for fg in colors
printf "\e[48;2;%sm%s", palette[fg], ?\s * num
end
printf "\e[m\n"
end
names = {
0 => "regular",
1 => "bold",
2 => "faint",
3 => "italic",
4 => "underline",
5 => "blink",
6 => "blink2",
7 => "reverse",
8 => "conceal",
9 => "strike",
11 => "font1",
12 => "font2",
13 => "font3",
14 => "font4",
15 => "font5",
16 => "font6",
17 => "font7",
18 => "font8",
19 => "font9",
20 => "fraktur",
21 => "doubleline",
51 => "framed",
52 => "encircled",
53 => "overlined",
60 => "irsline",
61 => "idoubleline",
62 => "ilsline",
63 => "ioverline2",
64 => "istress",
}
puts "Terminal modes"
for mode in Enumerator::Chain.new(0..9, 11..21, 51..53, 60..64)
name = names[mode]
printf "Mode %2d: ", mode
for bg in Enumerator::Chain.new([49], 40..47)
printf "\e[%d;%dmlorem", mode, bg
end
printf "\e[m (%s)\n", name
end
puts
puts "4 bit color"
for bg in Enumerator::Chain.new([49], 40..47)
for fg in Enumerator::Chain.new([39], 30..37)
printf "\e[%d;%dm%d %d", bg, fg, bg, fg
end
printf "\e[m\n"
end
puts
puts "8 bit color"
for fg in 0..15
printf "\e[48;5;%dm%3d", fg, fg
printf "\e[m\n" if fg % 8 == 7
end
printf "\e[m\n"
for fg in 16..255
printf "\e[48;5;%dm%4d", fg, fg
printf "\e[m\n" if (fg - 15) % 6 == 0
end
printf "\e[m\n"
puts
roygcbvp = %w(242;119;119 242;160;119 242;217;119 137;242;119
119;234;242 119;123;242 180;119;242 242;119;236)
flag1 = %w(91;207;250 245;171;185 255;255;255)
flag2 = %w(255;244;44 255;255;255 157;89;210 0;0;0)
puts "24 bit color"
print_flag roygcbvp, 10, 0..7
print_flag flag1, 16, [0, 1, 2, 1, 0]
print_flag flag2, 20, 0..3
puts
puts "These colors must not be the same."
puts "If they are, your terminal is not using truecolor."
puts
puts "\e[48;5;134m 8bit\e[m"
puts "\e[48;2;157;89;210m 24bit"
## EOF