summaryrefslogtreecommitdiffstats
path: root/lib/remote/print.sh
diff options
context:
space:
mode:
Diffstat (limited to 'lib/remote/print.sh')
-rw-r--r--lib/remote/print.sh168
1 files changed, 168 insertions, 0 deletions
diff --git a/lib/remote/print.sh b/lib/remote/print.sh
new file mode 100644
index 0000000..a0fdcbe
--- /dev/null
+++ b/lib/remote/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"
+ ;;
+ *)
+ # Lightgray and Yellow are almost invisible on white
+ colors[yellow]=${colors[orange]}
+ colors[white]=${colors[black]}
+ colors[lightgray]=${colors[gray]}
+ colors[cyan]=${colors[blue]}
+ ;;
+ esac
+
+ 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 " "
+}
+
+clear