summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2024-08-28 13:35:45 -0400
committerAndrew Cady <d@jerkface.net>2024-08-28 13:35:45 -0400
commit600db046935b122d72f2b595f95649e41584cd81 (patch)
treee644a90a6fb4712e2bdf9f8cf55b6f6af30f5a7a
parent6232b624e10c91c8dd37206147c3672cdccd4836 (diff)
variable-width padding
Padding prevents line-wrap during output from coloring the background of the whole line with the escape character color. It works by ensuring line-wrap occurs with color set to defaults. After printing blank spaces, backspaces are printed to move cursor back to the starting point.
-rw-r--r--src/write-tty16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/write-tty b/src/write-tty
index 62ff4f4..5de700a 100644
--- a/src/write-tty
+++ b/src/write-tty
@@ -84,14 +84,26 @@ tokenize()
84 done 84 done
85} 85}
86 86
87padding()
88{
89 for ((i=0; i<$1; ++i))
90 do
91 echo -n ' '
92 done
93 for ((i=0; i<$1; ++i))
94 do
95 echo -en '\b'
96 done
97}
98
87soft_cursor() 99soft_cursor()
88{ 100{
89 BASH_ARGV0=soft_cursor 101 BASH_ARGV0=soft_cursor
90 echo -n "$0" >/proc/$BASHPID/comm 102 echo -n "$0" >/proc/$BASHPID/comm
91 FMT=$'%s \b\e[%sm \e[m \b\b' 103 FMT=$'\e[m %s\b%s\e[%sm \b\e[m'
92 REPLY= 104 REPLY=
93 color=105 105 color=105
94 while printf "$FMT" "$REPLY" "$color" 106 while printf "$FMT" "$(padding ${#REPLY})" "$REPLY" "$color"
95 do 107 do
96 read -r || break 108 read -r || break
97 done 109 done