summaryrefslogtreecommitdiffstats
path: root/remote/lib/print.sh
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2019-08-25 03:49:35 +0200
committerSuren A. Chilingaryan <csa@suren.me>2019-08-25 03:49:35 +0200
commitc8c277200169dfadf88dd176e5c056967550e059 (patch)
treeec1a519ef550c2206c7863503627388e343778a3 /remote/lib/print.sh
parent5e6c83d51d0f52ecb464f137ad68f0bd1a83f5e4 (diff)
downloadconky-c8c277200169dfadf88dd176e5c056967550e059.tar.gz
conky-c8c277200169dfadf88dd176e5c056967550e059.tar.bz2
conky-c8c277200169dfadf88dd176e5c056967550e059.tar.xz
conky-c8c277200169dfadf88dd176e5c056967550e059.zip
Add remote services
Diffstat (limited to 'remote/lib/print.sh')
-rw-r--r--remote/lib/print.sh168
1 files changed, 168 insertions, 0 deletions
diff --git a/remote/lib/print.sh b/remote/lib/print.sh
new file mode 100644
index 0000000..465fce5
--- /dev/null
+++ b/remote/lib/print.sh
@@ -0,0 +1,168 @@
+# underlines 4;30,... blinking 5:30,...
+# backgrounds: 40,...
+
+declare -A colors=(
+ [black]='0;30'
+ [red]='0;31'
+ [green]='0;32'
+ [orange]='0;33'
+ [blue]='0;34'
+ [purple]='0;35'
+ [cyan]='0;36'
+ [lightgray]='0;37'
+ [gray]='1;30'
+ [lightred]='1;31'
+ [lightgreen]='1;32'
+ [yellow]='1;33'
+ [lightblue]='1;34'
+ [lightpurple]='1;35'
+ [lightcyan]='1;36'
+ [white]='1;37'
+)
+
+background=""
+foreground=""
+
+
+
+
+# Fixing color map
+#echo -ne "\e[44m"
+#echo -ne '\x1B[K'
+
+function set_background {
+ if [ -n "$background" ]; then
+ echo -ne "$background"
+ echo -ne '\x1B[K'
+ fi
+}
+
+function set_color {
+ local color=${1:-""}
+ local effect=${2:-""}
+
+ c=${colors[$color]}
+
+
+ case "$effect" in
+ 'u')
+ c=$(echo $c | sed -r "s/^0/4/ ; s/^1/1;4/")
+ ;;
+ esac
+
+ [ -n "$color" ] && echo -ne "\033[${c}m"
+ set_background
+}
+
+function reset_color {
+ echo -ne "\033[0m"
+
+ set_background
+ [ -n "$foreground" ] && set_color "$foreground"
+}
+
+function finish {
+ echo -ne "\033[0m"
+ echo
+}
+
+function configure_palete {
+ case $1 in
+ blue)
+ background="\e[1;44m"
+ foreground="white"
+ ;;
+ *)
+ # Yellow is invisible on white
+ colors[yellow]=${colors[orange]}
+ colors[cyan]=${colors[blue]}
+ ;;
+ esac
+
+ clear
+ set_background
+ reset_color
+}
+
+function decorate {
+ local output="$1"
+ local color=${2:-""}
+ local effect=${3:-""}
+
+ if [ -n "$color" ]; then
+ set_color $color $effect
+ echo -ne "${output}"
+ reset_color
+ else
+ echo -ne "$output"
+ fi
+}
+
+function eol {
+ sed 's/$/\x1B[K/'
+}
+
+function print_eol {
+ echo -e '\x1B[K'
+}
+
+
+
+function print {
+ local output="$1"
+ local color=${2:-""}
+ local char_limit=${3:-$fold}
+ local line_limit=${4:-0}
+
+ local cmd="decorate \"${output}\" \"$color\" | fold -s -w $char_limit"
+ [ $line_limit -gt 0 ] && cmd="$cmd | head -n $line_limit"
+
+ eval "$cmd" | eol
+}
+
+
+function print_hline {
+ local color=${1:-"gray"}
+ local cols=${COLUMNS:-$(tput cols)}
+
+ decorate $(printf '%*s' $cols '' | tr ' ' -) "$color"
+ echo | eol
+}
+
+function print_table {
+ # The problem here is that all escapes for colors are treated as normal visible symbols
+ sed "s/ ::: /@/g" | column -t -s "@" -o " " | eol
+}
+
+function decorate_table {
+ print_hline
+ cat -
+ print_hline
+}
+
+function print_status {
+ local status="$1"
+
+ if [[ $status =~ ^.$ ]]; then
+ case $status in
+ 0)
+ decorate "*" "red"
+ ;;
+ 1)
+ decorate "*" "green"
+ ;;
+ 2)
+ decorate "*" "yellow"
+ ;;
+ *)
+ decorate "$status" "red"
+ ;;
+ esac
+ else
+ decorate "?" "red"
+ fi
+ echo -n " "
+}
+
+
+configure_palete "$palete"