Permalink
Switch branches/tags
Nothing to show
Find file
63b2ed0 May 9, 2013
38 lines (32 sloc) 1.06 KB
#! /bin/zsh
# A script to make using 256 colors in zsh less painful.
# P.C. Shyamshankar <sykora@lucentbeing.com>
#
# Spectrum accepts an optional argument, indicating the number of colors the terminal actually
# supports. This allows it to gracefully degrade, so that you don't have to write more than version
# of the same thing. By default, this argument is assumed to be 256, which maintains backwards
# compatibility.
#
# TODO: Degrade gracefully through approximation?
# We define three associative arrays, for effects, foreground colors and background colors.
typeset -Ag FX FG BG
FX=(
reset ""
bold "" no-bold ""
italic "" no-italic ""
underline "" no-underline ""
blink "" no-blink ""
reverse "" no-reverse ""
)
local SUPPORT
# Optionally handle impoverished terminals.
if (( $# == 0 )); then
SUPPORT=256
else
SUPPORT=$1
fi
# Fill the color maps.
for color in {000..$SUPPORT}; do
FG[$color]="[38;5;${color}m"
BG[$color]="[48;5;${color}m"
done