commit 5b6cf09700ac421e2049f6f9d017daf5d368a484
parent cea7bdad121b0a7cc1a79402c104940d53920231
Author: Byron Torres <b@torresjrjr>
Date: Thu, 28 Jan 2021 11:58:35 +0000
Replace clear with precise cursor reset
When redrawing the graphic with the status appended, instead of clearing
the screen, the cursor now moves back to the inital position. This
improves terminal UX, like when logging in via ssh.
Diffstat:
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/fetch b/fetch
@@ -13,6 +13,7 @@ c7=$(printf '\e[37m'); c8=$(printf '\e[38m')
palette=$(printf "\e[7m$c1 $c1 $c2 $c2 $c3 $c3 $c4 $c4 $c5 $c5 $c6 $c6 \e[m")
## Create graphic
+graphic_height=6
d='\t' # delimiter
graphic=$(printf "\
${c2} ~ ${d}
@@ -24,6 +25,11 @@ ${c2} |_| ${d}
${c2} ${d}${c0}
")
+cursor_reset() {
+ printf '\r'
+ for i in $(seq $1); do printf '\e[A'; done
+}
+
printf '%s' "${graphic}" # initial graphic
## Get variables
@@ -64,6 +70,9 @@ ${c6}tmux: ${c0}${tmux_sessions}
## Print fetch
tmpfile=/tmp/fetch_graphic.tmp
printf '%s' "${graphic}" > "${tmpfile}"
-printf '%s\n' "$( clear; printf '%s' "${status}" | paste -d '' "${tmpfile}" - )"
+printf '%s\n' "$(
+ cursor_reset ${graphic_height};
+ printf '%s' "${status}" | paste -d '' "${tmpfile}" -
+)"
# @torresjrjr