Last active
September 27, 2022 05:39
-
-
Save SARDONYX-sard/49a34a8c63a1cc9f050010104a096278 to your computer and use it in GitHub Desktop.
Show ansi color
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
#! python3 | |
modes = { | |
"ColorName": 0, | |
" Bold": 1, | |
"Underline": 4, | |
"Invisible": 8, | |
" Reverse": 7, | |
} | |
colors = [ | |
"Black", | |
"Red", | |
"Green", | |
"Yellow", | |
"Blue", | |
"Magenta", | |
"Cyan", | |
"White", | |
] | |
def show_background_color(fore: int, mode: int): | |
for color, back in zip(colors, range(40, 48)): | |
if mode == 0: | |
print( | |
f"\033[{fore};{back};{mode}m BG {color} ", end="\033[0m" | |
) | |
continue | |
print( | |
f"\033[{fore};{back};{mode}m \\033[{fore};{back};{mode}m ", | |
end="\033[0m", | |
) | |
print("") | |
def show_mode_color(fore: int): | |
for name, mode in modes.items(): | |
print( | |
f"{name} \033[{fore};{mode}m \\033[{fore};{mode}m ", end="\033[0m" | |
) | |
show_background_color(fore, mode) | |
print("") | |
def color(): | |
print("color Code:\\033, foreground:[30 ~ 37], background:[40 ~ 47]") | |
print("") | |
for color, fore in zip(colors, range(30, 38)): | |
print(f"\033[{fore}m{color}", end="\033[0m\n") | |
show_mode_color(fore) | |
print("\033[0m\n") | |
if __name__ == "__main__": | |
color() | |
input() |
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
#!/usr/bin/env ruby | |
print ' -- ' | |
(40..47).each do |b| | |
s = b.to_s | |
print "\033[", s, 'm ', s, " \033[0m " | |
end | |
print "\n" | |
[30, 31, 32, 33, 34, 35, 36, 37, 90, 91, 92, 93, 94, 95, 96, 97].each do |c| | |
s = c.to_s | |
print "\033[", s, 'm ', s, " \033[0m " | |
(40..47).each do |b| | |
s = "#{c};#{b}" | |
print "\033[", s, 'm ', s, " \033[0m " | |
end | |
print "\n" | |
[1, 4].each do |a| | |
s = "#{c};#{a}" | |
print "\033[", s, 'm ', s, " \033[0m " | |
(40..47).each do |b| | |
s = "#{c};#{b};#{a}" | |
print "\033[", s, 'm ', s, " \033[0m " | |
end | |
print "\n" | |
end | |
end |
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
#! /bin/bash | |
function color() | |
{ | |
for fore in `seq 30 37` | |
do printf "\e[${fore}m \\\e[${fore}m \e[m\n" | |
for mode in 1 4 5 | |
do printf "\e[${fore};${mode}m \\\e[${fore};${mode}m \e[m" | |
for back in `seq 40 47` | |
do printf "\e[${fore};${back};${mode}m \\\e[${fore};${back};${mode}m \e[m" | |
done | |
echo | |
done | |
echo | |
done | |
printf " \\\e[m\n" | |
} | |
color |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment