From a68356432542c5a8e82442bd5fc0442dc43555c7 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Wed, 28 Aug 2024 21:54:21 -0400 Subject: color fix --- src/write-tty | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'src/write-tty') diff --git a/src/write-tty b/src/write-tty index 5de700a..60046e1 100644 --- a/src/write-tty +++ b/src/write-tty @@ -27,7 +27,7 @@ colorize() declare -i c=16#"${REPLY#??}" ;; * ) - printf '%s\n' "$REPLY" + printf '0 %s\n' "$REPLY" continue ;; esac @@ -44,7 +44,7 @@ colorize() then REPLY=^$(chr c + 64) fi - printf $'\e[106m%s\e[m\n' "$REPLY" + printf '106 %s\n' "$REPLY" done } @@ -102,10 +102,19 @@ soft_cursor() echo -n "$0" >/proc/$BASHPID/comm FMT=$'\e[m %s\b%s\e[%sm \b\e[m' REPLY= - color=105 - while printf "$FMT" "$(padding ${#REPLY})" "$REPLY" "$color" + declare -i replylen=0 replycolor + promptcolor=105 + while printf "$FMT" "$(padding $replylen)" "$REPLY" "$promptcolor" do - read -r || break + read -r replycolor REPLY || break + replylen=${#REPLY} + case "$replycolor" in + 0 ) + ;; + * ) + REPLY=$'\e['"$replycolor"'m'"$REPLY"$'\e[m' + ;; + esac done } -- cgit v1.2.3