terminal rgb colors in qolop

This commit is contained in:
Ville Rantanen
2020-09-27 10:18:37 +03:00
parent 6f84c2ed1a
commit 2f4cfd196f
2 changed files with 16 additions and 5 deletions

View File

@@ -92,9 +92,9 @@ if __name__ == "__main__":
value = open(value[1:], 'rt').read()
elif value[0:2] == "\\@":
value = value[1:]
l = l.replace(p[0], value)
l = l.replace(p[0].encode('utf-8'), value.encode('utf-8'))
if options.env:
var_list = [m.group(0) for m in re.finditer('\${[^ ]+}', l)]
for v in var_list:
l = l.replace(v, os.environ.get(v[:-1][2:], ""))
sys.stdout.write(l)
sys.stdout.write(l.decode('utf-8'))

View File

@@ -1,5 +1,5 @@
#!/bin/bash
_qColVersion() { echo Version 2019.06.21.0; }
_qColVersion() { echo Version 2020.09.27.0; }
_qColHelp() {
_qColVersion
@@ -13,6 +13,7 @@ Functions:
- _qCode: Print ANSI color codes by number sequence
- _qParse: Print ANSI color by english words ex. "red", "lightgreen", "gray on blue"
- _qPos: Move cursor
- _qRGB, _qRGBbg: Set color with 8bit integer triplet
- _qClr: Clear screen
- _qReset: Reset terminal
@@ -39,8 +40,8 @@ Run qolop as script to print ANSI code table, or evaluate commands
The first command produces string with ANSI commands, the
second will escape the escape characters, so you can copy/paste
it in to another echo -e command.
qolop c G
qolop c G
qolop p green
produce the same output, just the color code
@@ -191,6 +192,15 @@ _qPos() {
return 1
}
_qRGB() {
# Foreground 8-bit RGB triplet
printf '\033[38;2;%d;%d;%dm' "$1" "$2" "$3"
}
_qRGBbg() {
# Background 8-bit RGB triplet
printf '\033[48;2;%d;%d;%dm' "$1" "$2" "$3"
}
_qReset() {
# Reset terminal
@@ -270,6 +280,7 @@ ${_S}====================${_Z}
9 st ${_st}Strike ${_Z} 36 c ${_c}Cyan ${_Z}36;1 C ${_C}Cyan ${_Z}46 bc ${_k}${_bc}Cyan ${_Z}
29 so ${_so}Strike off ${_Z} 37 w ${_w}White ${_Z}37;1 W ${_W}White ${_Z}47 bw ${_k}${_bw}White ${_Z}
Enter raw color code sequence with _qCode function
Use RGB triplets with _qRGB and _qRGBbg functions
${_S}Clearing and movement${_Z} ESC[X or ESC[1X
${_S}=====================${_Z}
2J CLR Clear screen