Created
January 12, 2021 05:05
-
-
Save sangheonhan/fbd65beff2a6281c544942d65fc39932 to your computer and use it in GitHub Desktop.
터미널 에뮬레이터 256 색상 지원 확인 스크립트
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 | |
# This file was originally taken from iterm2 https://github.com/gnachman/iTerm2/blob/master/tests/24-bit-color.sh | |
# | |
# This file echoes a bunch of 24-bit color codes | |
# to the terminal to demonstrate its functionality. | |
# The foreground escape sequence is ^[38;2;<r>;<g>;<b>m | |
# The background escape sequence is ^[48;2;<r>;<g>;<b>m | |
# <r> <g> <b> range from 0 to 255 inclusive. | |
# The escape sequence ^[0m returns output to default | |
setBackgroundColor() | |
{ | |
#printf '\x1bPtmux;\x1b\x1b[48;2;%s;%s;%sm' $1 $2 $3 | |
printf '\x1b[48;2;%s;%s;%sm' $1 $2 $3 | |
} | |
resetOutput() | |
{ | |
echo -en "\x1b[0m\n" | |
} | |
# Gives a color $1/255 % along HSV | |
# Who knows what happens when $1 is outside 0-255 | |
# Echoes "$red $green $blue" where | |
# $red $green and $blue are integers | |
# ranging between 0 and 255 inclusive | |
rainbowColor() | |
{ | |
let h=$1/43 | |
let f=$1-43*$h | |
let t=$f*255/43 | |
let q=255-t | |
if [ $h -eq 0 ] | |
then | |
echo "255 $t 0" | |
elif [ $h -eq 1 ] | |
then | |
echo "$q 255 0" | |
elif [ $h -eq 2 ] | |
then | |
echo "0 255 $t" | |
elif [ $h -eq 3 ] | |
then | |
echo "0 $q 255" | |
elif [ $h -eq 4 ] | |
then | |
echo "$t 0 255" | |
elif [ $h -eq 5 ] | |
then | |
echo "255 0 $q" | |
else | |
# execution should never reach here | |
echo "0 0 0" | |
fi | |
} | |
for i in `seq 0 127`; do | |
setBackgroundColor $i 0 0 | |
echo -en " " | |
done | |
resetOutput | |
for i in `seq 255 -1 128`; do | |
setBackgroundColor $i 0 0 | |
echo -en " " | |
done | |
resetOutput | |
for i in `seq 0 127`; do | |
setBackgroundColor 0 $i 0 | |
echo -n " " | |
done | |
resetOutput | |
for i in `seq 255 -1 128`; do | |
setBackgroundColor 0 $i 0 | |
echo -n " " | |
done | |
resetOutput | |
for i in `seq 0 127`; do | |
setBackgroundColor 0 0 $i | |
echo -n " " | |
done | |
resetOutput | |
for i in `seq 255 -1 128`; do | |
setBackgroundColor 0 0 $i | |
echo -n " " | |
done | |
resetOutput | |
for i in `seq 0 127`; do | |
setBackgroundColor `rainbowColor $i` | |
echo -n " " | |
done | |
resetOutput | |
for i in `seq 255 -1 128`; do | |
setBackgroundColor `rainbowColor $i` | |
echo -n " " | |
done | |
resetOutput |
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/perl | |
# Author: Todd Larason <[email protected]> | |
# $XFree86: xc/programs/xterm/vttests/256colors2.pl,v 1.1 1999/07/11 08:49:54 dawes Exp $ | |
print "256 color mode\n\n"; | |
# display back ground colors | |
for ($fgbg = 38; $fgbg <= 48; $fgbg +=10) { | |
# first the system ones: | |
print "System colors:\n"; | |
for ($color = 0; $color < 8; $color++) { | |
print "\x1b[${fgbg};5;${color}m::"; | |
} | |
print "\x1b[0m\n"; | |
for ($color = 8; $color < 16; $color++) { | |
print "\x1b[${fgbg};5;${color}m::"; | |
} | |
print "\x1b[0m\n\n"; | |
# now the color cube | |
print "Color cube, 6x6x6:\n"; | |
for ($green = 0; $green < 6; $green++) { | |
for ($red = 0; $red < 6; $red++) { | |
for ($blue = 0; $blue < 6; $blue++) { | |
$color = 16 + ($red * 36) + ($green * 6) + $blue; | |
print "\x1b[${fgbg};5;${color}m::"; | |
} | |
print "\x1b[0m "; | |
} | |
print "\n"; | |
} | |
# now the grayscale ramp | |
print "Grayscale ramp:\n"; | |
for ($color = 232; $color < 256; $color++) { | |
print "\x1b[${fgbg};5;${color}m::"; | |
} | |
print "\x1b[0m\n\n"; | |
} | |
print "Examples for the 3-byte color mode\n\n"; | |
for ($fgbg = 38; $fgbg <= 48; $fgbg +=10) { | |
# now the color cube | |
print "Color cube\n"; | |
for ($green = 0; $green < 256; $green+=51) { | |
for ($red = 0; $red < 256; $red+=51) { | |
for ($blue = 0; $blue < 256; $blue+=51) { | |
print "\x1b[${fgbg};2;${red};${green};${blue}m::"; | |
} | |
print "\x1b[0m "; | |
} | |
print "\n"; | |
} | |
# now the grayscale ramp | |
print "Grayscale ramp:\n"; | |
for ($gray = 8; $gray < 256; $gray+=10) { | |
print "\x1b[${fgbg};2;${gray};${gray};${gray}m::"; | |
} | |
print "\x1b[0m\n\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment