Created
September 20, 2012 03:35
-
-
Save yoshikaw/3753831 to your computer and use it in GitHub Desktop.
ANSIカラーテーブルを確認するzsh関数
This file contains hidden or 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
# show the color combinations {{{2 | |
# http://www.linuxfocus.org/English/May2004/article335.shtml | |
function ansicolortable() { | |
local -A sgr; sgr=(0 Normal 1 Bright 4 Underline 5 Blink 7 Reverse) | |
local -A a; local -A screen_attr | |
while getopts 01457s arg; do | |
case "$arg" in | |
0|1|4|5|7) a+=($arg $sgr[$arg]);; | |
s) screen_attr=(0 d 1 b 4 u 5 B 7 r);; | |
*);; | |
esac | |
done | |
test $#a -gt 0 && sgr=(${(kv)a}) | |
if [[ -z $screen_attr ]] then | |
local code fore back | |
for code in ${(kon)sgr}; do | |
printf 'ESC[%s;Foreground;Background - %s\n' $code $sgr[$code] | |
for fore in {30..37} {90..97}; do | |
for back in {40..47} {100..107}; do | |
printf '\e[%s;%s;%sm %2s;%-3s ' $code $fore $back $fore $back | |
done | |
printf '\e[0m\n' | |
done | |
printf '\n' | |
done | |
else | |
# output in color which is defined in GNU Screen. | |
local -A label; label=(30 k 31 r 32 g 33 y 34 b 35 m 36 c 37 w) | |
for code in ${(k)label}; do | |
label+=($(( code + 10 )) $label[$code]) # Background | |
label+=($(( code + 60 )) ${(U)label[$code]}) # Foreground high intensity | |
label+=($(( code + 70 )) ${(U)label[$code]}) # Background high intensity | |
done | |
label+=(${(kv)screen_attr}) | |
local attr_escape='\e[1mb\e[22;4mu\e[24;5mB\e[25;7mr\e[27m' | |
local code fore back _code | |
for code in ${(kon)sgr}; do | |
test $code -eq 1 && _code=22 || _code=$(( code + 20 )) | |
printf '(GNU Screen) =%s [Background][Foreground] [Bold][Underline][Blink][Reverse] - %s\n' \ | |
$label[$code] $sgr[$code] | |
for fore in {30..37} {90..97}; do | |
for back in {40..47} {100..107}; do | |
printf "\e[%s;%s;%sm %s%s ${attr_escape/$_code;}" \ | |
$code $back $fore $label[$back] $label[$fore] | |
done | |
printf '\e[0m\n' | |
done | |
printf '\n' | |
done | |
fi | |
} #}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment