aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2025-01-31 15:35:12 -0800
committerKaz Kylheku <kaz@kylheku.com>2025-01-31 15:35:12 -0800
commit5d1cb64e30141c9bcdcae22a01a17cda7bc341b7 (patch)
treea553f63450665f41b00a066e2442ab2c34e7509e
parent4c79207fbe19ce51c82e9be7573641930410718c (diff)
downloadbasta-5d1cb64e30141c9bcdcae22a01a17cda7bc341b7.tar.gz
basta-5d1cb64e30141c9bcdcae22a01a17cda7bc341b7.tar.bz2
basta-5d1cb64e30141c9bcdcae22a01a17cda7bc341b7.zip
Use \e for ESC via Bash $'...' syntax.
- We get rid of 'local esc=$(printf "\033")' everywhere and use the escape sequence.
-rw-r--r--basta.sh30
1 files changed, 12 insertions, 18 deletions
diff --git a/basta.sh b/basta.sh
index 804a2cf..f562cdd 100644
--- a/basta.sh
+++ b/basta.sh
@@ -13,17 +13,15 @@ basta_status_alarm_pid=${basta_status_alarm_pid-}
basta.query_terminal_lines()
{
- local esc=$(printf "\033")
local -n intovar=$1
- printf "${esc}7$esc[999;999H"
+ printf $'\e7\e[999;999H'
local curline=$(basta.get_cur_line)
- printf "${esc}8"
+ printf $'\e8'
intovar=$curline
}
basta.query_termios_lines_cols()
{
- local esc=$(printf "\033")
local -n linesvar=$1
local -n colsvar=$2
local pair=$(stty size)
@@ -52,9 +50,8 @@ basta.prepare_term()
basta.get_cur_line()
{
- local esc=$(printf "\033")
local response=$LINES
- printf "$esc[6n" > /dev/tty
+ printf '\e[6n' > /dev/tty
read -t 3 -s -d R response < /dev/tty
local IFS="[;"
set -- $response
@@ -63,7 +60,6 @@ basta.get_cur_line()
basta.update_status()
{
- local esc=$(printf "\033")
local pwd=$PWD
local dots=
local tio_lines
@@ -76,11 +72,11 @@ basta.update_status()
$LINES -eq $tio_lines -a \
$COLUMNS -eq $tio_cols ] || basta.prepare_term
- local status_esc="$esc[7m$esc[m"
+ local status_esc=$'\e[7m\e[m'
local status_date=$(date +%m-%d/%H:%M)
while true; do
- local status="$esc[7m$status_date$esc[m $HOSTNAME $dots$pwd"
+ local status=$'\e[7m'$status_date$'\e[m '"$HOSTNAME $dots$pwd"
local status_len=$((${#status} - ${#status_esc}))
[ $status_len -le $COLUMNS ] && break
[ "${pwd#/*/}" == "$pwd" ] && break
@@ -93,7 +89,7 @@ basta.update_status()
[ $status_len -gt $COLUMNS ] && status=
- printf "${esc}7$esc[%s;1H$esc[K%s$esc[1;%sr${esc}8" \
+ printf $'\e7\e[%s;1H\e[K%s\e[1;%sr\e8' \
$((basta_scroll_lines + 1)) "$status" $basta_scroll_lines
}
@@ -101,11 +97,10 @@ basta.check_cursor()
{
if ! read -t 0; then
local exit=$?
- local esc=$(printf "\033")
local curln=$(basta.get_cur_line)
if [ $curln -gt $basta_scroll_lines ]; then
- printf "$esc[%s;1H" $basta_scroll_lines
+ printf $'\e[%s;1H' $basta_scroll_lines
fi
fi
}
@@ -169,21 +164,20 @@ basta.remove_hooks()
basta.cleanup()
{
- local esc=$(printf "\033")
local newlines=$((LINES + 1))
- printf "${esc}7"
- printf "$esc[%s;1H$esc[K" $newlines
+ printf $'\e7'
+ printf $'\e[%s;1H\e[K' $newlines
if [ $basta_prev_reserved_rows ] &&
[ $basta_prev_reserved_rows -gt 0 ]
then
- printf "$esc[1;%sr" $newlines
+ printf $'\e[1;%sr' $newlines
else
- printf "$esc[1r"
+ printf $'\e[1r'
fi
- printf "${esc}8"
+ printf $'\e8'
stty rows $newlines
kill -KILL $basta_status_alarm_pid
basta.remove_hooks