position control for qolop

This commit is contained in:
ville rantanen
2017-08-08 14:35:40 +03:00
parent 2be99338c5
commit 04d8085035

View File

@@ -12,8 +12,12 @@
# Z=$( _qCol z; ) # Z=$( _qCol z; )
# echo ${TITLE}Title${Z} # echo ${TITLE}Title${Z}
# Export to variables (prefixed with _c. Also the default)
# _qCol export _c
# echo -e ${_cG}Title${_cZ}
_qCol() { _qCol() {
# print "easier" mapping of ANSI colors and controls
local K="\033[1;30m" local K="\033[1;30m"
local R="\033[1;31m" local R="\033[1;31m"
local G="\033[1;32m" local G="\033[1;32m"
@@ -51,13 +55,23 @@ _qCol() {
local io='\033[27m' #inverse off local io='\033[27m' #inverse off
local st='\033[9m' #strike on local st='\033[9m' #strike on
local so='\033[29m' #strike off local so='\033[29m' #strike off
local CLRLIN='\033[2J' local CLRLIN='\033[2J' # Clear line
local CLREND='\033[K' local CLREND='\033[K' # Clear to end of line
local CLRBEG='\033[1K' local CLRBEG='\033[1K' # Clear to beginning of line
local CLRSCR="$CLRLIN"'\033[0;0H' 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 " 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 local arg val
for ((arg=1;arg<=$#;arg++)) { for ((arg=1;arg<=$#;arg++)) {
val=${!arg} val=${!arg}
@@ -67,9 +81,29 @@ _qCol() {
} }
_qCode() { _qCode() {
# Enter numerical ANSI codes directly
local arg val local arg val
for ((arg=1;arg<=$#;arg++)) { for ((arg=1;arg<=$#;arg++)) {
val=${!arg} val=${!arg}
printf '\033['"${val}m" 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; }
}