summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKerin Millar <kfm@plushkava.net>2024-05-14 09:33:09 +0100
committerSam James <sam@gentoo.org>2024-05-15 11:28:30 +0100
commitf3e254127ebad7c8774081e3834653effe1966d0 (patch)
tree53ab25b461b251703e73c740ffeb0ba8059c116c
parentmeson.build: prepare for gentoo-functions-1.1 (diff)
downloadgentoo-functions-f3e254127ebad7c8774081e3834653effe1966d0.tar.gz
gentoo-functions-f3e254127ebad7c8774081e3834653effe1966d0.tar.bz2
gentoo-functions-f3e254127ebad7c8774081e3834653effe1966d0.zip
Have _eend() remember the cursor position before printing
The act of printing a LF character after the indicator moves the cursor back to the row beneath - as intended - but also results in the cursor being positioned at the first column, even though it may have been elsewhere initially. Address this by using the DECSC sequence to save the cursor position prior to printing the indicator, then the DECRC sequence to restore it afterwards. My testing shows no measurable performance impact. Consider the following script as a test case. #!/bin/sh . ./functions.sh ebegin Testing einfon more output eend 0 Below is a depicted invocation which clearly demonstrates the beneficial effect of this change. $ /.testcase; printf done * Testing ... [ ok ] * more outputdone$ ▉ Whereas, previously, the outcome would have been as shown below. $ /.testcase; printf done * Testing ... [ ok ] done$ ▉ output Signed-off-by: Kerin Millar <kfm@plushkava.net> Signed-off-by: Sam James <sam@gentoo.org>
-rw-r--r--functions.sh8
1 files changed, 4 insertions, 4 deletions
diff --git a/functions.sh b/functions.sh
index 6d77f59..7bd4b11 100644
--- a/functions.sh
+++ b/functions.sh
@@ -227,10 +227,10 @@ _eend()
fi
if [ "${genfun_tty}" -eq 2 ]; then
- # Move the cursor up by one line with CUU before positioning it
- # horizontally with CHA. Both are formal ECMA-48 CSI sequences.
- # Print the indicator afterwards.
- printf '\033[1A\033[%dG %s\n' "$(( genfun_cols - 6 + genfun_offset ))" "${msg}"
+ # Save the cursor position with DECSC, move it up by one line
+ # with CUU, position it horizontally with CHA, print the
+ # indicator, then restore the cursor position with DECRC.
+ printf '\0337\033[1A\033[%dG %s\0338' "$(( genfun_cols - 6 + genfun_offset ))" "${msg}"
else
# The standard output does not refer to a sufficiently capable
# terminal. Print only the indicator.