110 lines
2.9 KiB
Plaintext
110 lines
2.9 KiB
Plaintext
# Quick shell COLOrizer Package
|
|
# Source in BASH
|
|
|
|
# Examples:
|
|
# As functions:
|
|
# _title(){ _qCol z G; }
|
|
# _z(){ _qCol z; }
|
|
# _title; echo Title; _z
|
|
|
|
# As variables
|
|
# TITLE=$( _qCol z G; )
|
|
# Z=$( _qCol z; )
|
|
# echo ${TITLE}Title${Z}
|
|
|
|
# Export to variables (prefixed with _c. Also the default)
|
|
# _qCol export _c
|
|
# echo -e ${_cG}Title${_cZ}
|
|
|
|
_qCol() {
|
|
# print "easier" mapping of ANSI colors and controls
|
|
local K="\033[1;30m"
|
|
local R="\033[1;31m"
|
|
local G="\033[1;32m"
|
|
local B="\033[1;34m"
|
|
local Y="\033[1;33m"
|
|
local M="\033[1;35m"
|
|
local C="\033[1;36m"
|
|
local W="\033[1;37m"
|
|
|
|
local k="\033[0;30m"
|
|
local r="\033[0;31m"
|
|
local g="\033[0;32m"
|
|
local b="\033[0;34m"
|
|
local y="\033[0;33m"
|
|
local m="\033[0;35m"
|
|
local c="\033[0;36m"
|
|
local w="\033[0;37m"
|
|
|
|
local bk="\033[40m"
|
|
local br="\033[41m"
|
|
local bg="\033[42m"
|
|
local by="\033[43m"
|
|
local bb="\033[44m"
|
|
local bm="\033[45m"
|
|
local bc="\033[46m"
|
|
local bw="\033[47m"
|
|
|
|
local S='\033[1m' #strong
|
|
local s='\033[2m' #strong off
|
|
local U='\033[4m' #underline
|
|
local u='\033[24m' #underline off
|
|
local z='\033[0m' #zero colors
|
|
local Z='\033[0m' #zero colors
|
|
local ic='\033[7m' #inverse colors
|
|
local io='\033[27m' #inverse off
|
|
local st='\033[9m' #strike on
|
|
local so='\033[29m' #strike off
|
|
local CLRLIN='\033[2J' # Clear line
|
|
local CLREND='\033[K' # Clear to end of line
|
|
local CLRBEG='\033[1K' # Clear to beginning of line
|
|
local CLRSCR="$CLRLIN"'\033[0;0H' # Clear screen
|
|
|
|
local color_keys=" K R G B Y M C W k r g b y m c w S s U u z Z ic io st so bk br bg by bb bm bc bw CLRLIN CLREND CLRBEG CLRSCR "
|
|
|
|
[[ "$1" = "export" ]] && {
|
|
local key
|
|
local prefix="$2"
|
|
[[ -z "$2" ]] && prefix=_c
|
|
for key in $color_keys; do
|
|
eval export ${prefix}${key}=\'${!key}\'
|
|
done
|
|
return
|
|
}
|
|
|
|
local arg val
|
|
for ((arg=1;arg<=$#;arg++)) {
|
|
val=${!arg}
|
|
[[ ${color_keys} = *" $val "* ]] || { echo "No such color code '${val}'" >&2; return 1; }
|
|
printf ${!val}
|
|
}
|
|
}
|
|
|
|
_qCode() {
|
|
# Enter numerical ANSI codes directly
|
|
local arg val
|
|
for ((arg=1;arg<=$#;arg++)) {
|
|
val=${!arg}
|
|
printf '\033['"${val}m"
|
|
}
|
|
}
|
|
|
|
_qPos() {
|
|
# Cursor position control
|
|
local n="$2"
|
|
local x="$3"
|
|
[[ -z "$n" ]] && n=1
|
|
[[ -z "$x" ]] && x=1
|
|
[[ "$1" = "save" ]] && { printf '\033[s'; return; }
|
|
[[ "$1" = "restore" ]] && { printf '\033[u'; return; }
|
|
[[ "$1" = "up" ]] && { printf '\033['${n}'A'; return; }
|
|
[[ "$1" = "down" ]] && { printf '\033['${n}'B'; return; }
|
|
[[ "$1" = "right" ]] && { printf '\033['${n}'C'; return; }
|
|
[[ "$1" = "left" ]] && { printf '\033['${n}'D'; return; }
|
|
[[ "$1" = "linedown" ]] && { printf '\033['${n}'E'; return; }
|
|
[[ "$1" = "lineup" ]] && { printf '\033['${n}'F'; return; }
|
|
[[ "$1" = "col" ]] && { printf '\033['${n}'G'; return; }
|
|
[[ "$1" = "pos" ]] && { printf '\033['${n}';'${x}'H'; return; }
|
|
}
|
|
|