qolop parser
This commit is contained in:
@@ -1,15 +1,17 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
_qColVersion() { echo Version 2019.04.12.0; }
|
_qColVersion() { echo Version 2019.05.07.0; }
|
||||||
|
|
||||||
_qColHelp() {
|
_qColHelp() {
|
||||||
_qColVersion
|
_qColVersion
|
||||||
echo 'Quick shell COLOrizer Package
|
echo 'Quick shell COLOrizer Package
|
||||||
Source me in BASH!
|
Source me in BASH!
|
||||||
|
Why the name qolop? Place a mirror next to it!
|
||||||
|
|
||||||
Functions:
|
Functions:
|
||||||
- _qCol: Print ANSI color codes by letter codes.
|
- _qCol: Print ANSI color codes by letter codes.
|
||||||
Can export all letter codes as varibles.
|
Can export all letter codes as varibles.
|
||||||
- _qCode: Print ANSI color codes by number sequence
|
- _qCode: Print ANSI color codes by number sequence
|
||||||
|
- _qParse: Print ANSI color by english words ex. "red", "lightgreen", "gray on blue"
|
||||||
- _qPos: Move cursor
|
- _qPos: Move cursor
|
||||||
- _qClr: Clear screen
|
- _qClr: Clear screen
|
||||||
- _qReset: Reset terminal
|
- _qReset: Reset terminal
|
||||||
@@ -40,6 +42,12 @@ Run qolop as script to print ANSI code table, or evaluate commands
|
|||||||
'
|
'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_qClr() {
|
||||||
|
# Clear screen
|
||||||
|
_qCol "CLR"
|
||||||
|
_qPos abs 0 0
|
||||||
|
}
|
||||||
|
|
||||||
_qCol() {
|
_qCol() {
|
||||||
# print "easier" mapping of ANSI colors and controls
|
# print "easier" mapping of ANSI colors and controls
|
||||||
local K="\033[1;30m"
|
local K="\033[1;30m"
|
||||||
@@ -84,7 +92,9 @@ _qCol() {
|
|||||||
local CLRBEG='\033[1K' # Clear to beginning of line
|
local CLRBEG='\033[1K' # Clear to beginning of line
|
||||||
local CLRSCR="$CLR"'\033[0;0H' # Clear screen, reset cursor
|
local CLRSCR="$CLR"'\033[0;0H' # Clear screen, reset cursor
|
||||||
|
|
||||||
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 CLR 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 \
|
||||||
|
CLR CLREND CLRBEG CLRSCR "
|
||||||
|
|
||||||
[[ "$1" = "export" ]] && {
|
[[ "$1" = "export" ]] && {
|
||||||
local key
|
local key
|
||||||
@@ -113,6 +123,48 @@ _qCode() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_qParse() {
|
||||||
|
# Parse written colors to codes: 'help' to get help
|
||||||
|
local val codes
|
||||||
|
val="${@,,}"
|
||||||
|
if [[ ${#val} -lt 3 ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [[ ${val} = *"help"* ]]; then
|
||||||
|
echo "Parse format [light][colorname], or '[light][colorname] on [colorcolorname]'" >&2
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
if [[ ${val} = "light"* ]]; then
|
||||||
|
codes="${codes} S"
|
||||||
|
val=${val#light}
|
||||||
|
fi
|
||||||
|
case "$val" in
|
||||||
|
"black"*) codes="${codes} k";;
|
||||||
|
"red"*) codes="${codes} r";;
|
||||||
|
"green"*) codes="${codes} g";;
|
||||||
|
"yellow"*) codes="${codes} y";;
|
||||||
|
"blue"*) codes="${codes} b";;
|
||||||
|
"magenta"*) codes="${codes} m";;
|
||||||
|
"cyan"*) codes="${codes} c";;
|
||||||
|
"gray"*) codes="${codes} w";;
|
||||||
|
"white"*) codes="${codes} W";;
|
||||||
|
esac
|
||||||
|
if [[ ${val} = *" on "* ]]; then
|
||||||
|
case "$val" in
|
||||||
|
*"black") codes="${codes} bk";;
|
||||||
|
*"red") codes="${codes} br";;
|
||||||
|
*"green") codes="${codes} bg";;
|
||||||
|
*"yellow") codes="${codes} by";;
|
||||||
|
*"blue") codes="${codes} bb";;
|
||||||
|
*"magenta") codes="${codes} bm";;
|
||||||
|
*"cyan") codes="${codes} bc";;
|
||||||
|
*"gray") codes="${codes} bk";;
|
||||||
|
*"white") codes="${codes} bw";;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
_qCol $codes
|
||||||
|
}
|
||||||
|
|
||||||
_qPos() {
|
_qPos() {
|
||||||
# Cursor position control
|
# Cursor position control
|
||||||
local n="$2"
|
local n="$2"
|
||||||
@@ -134,11 +186,6 @@ _qPos() {
|
|||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
_qClr() {
|
|
||||||
# Clear screen
|
|
||||||
_qCol "CLR"
|
|
||||||
_qPos abs 0 0
|
|
||||||
}
|
|
||||||
|
|
||||||
_qReset() {
|
_qReset() {
|
||||||
# Reset terminal
|
# Reset terminal
|
||||||
@@ -194,8 +241,8 @@ if [[ "$0" = "${BASH_SOURCE[0]}" ]]; then
|
|||||||
[[ "$1" = *"help" ]] && exit
|
[[ "$1" = *"help" ]] && exit
|
||||||
[[ "$1" = "-h" ]] && exit
|
[[ "$1" = "-h" ]] && exit
|
||||||
_qCol export "_"
|
_qCol export "_"
|
||||||
printf "${_S}ANSI CODES AND QOLOP VARIABLES
|
printf "${_S}ANSI CODES AND QOLOP VARIABLES FOR _qCol FUNCTION
|
||||||
==============================${_Z}
|
=================================================${_Z}
|
||||||
${_R}Co${_G}lo${_B}rs${_W} and ${_S}Mo${_U}di${_st}fi${_u}er${_ic}s${_Z} \\\033[Xm or \\\033[X;Y;Zm
|
${_R}Co${_G}lo${_B}rs${_W} and ${_S}Mo${_U}di${_st}fi${_u}er${_ic}s${_Z} \\\033[Xm or \\\033[X;Y;Zm
|
||||||
${_S}====================${_Z}
|
${_S}====================${_Z}
|
||||||
0 z Z Clear format
|
0 z Z Clear format
|
||||||
|
|||||||
Reference in New Issue
Block a user