commit:     721c22bcd300b9a5d995e3dfbe66e46ca944e08d
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Fri Jun  9 21:21:35 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Jun  9 21:21:51 2023 +0000
URL:        
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=721c22bc

Right-trim messages given to ebegin() and _eprint() where appropriate

Have ebegin() strip all trailing newlines rather than just one at most.
Likewise for _eprint() in the case that a smart terminal is found.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>

 functions.sh.in | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/functions.sh.in b/functions.sh.in
index 673be7d..5141670 100644
--- a/functions.sh.in
+++ b/functions.sh.in
@@ -62,8 +62,13 @@ _eprint() {
                # VT100 and can be considered as a de-facto standard.
                printf ' %s*%s %s%s\0337' "${color}" "${NORMAL}" 
"${genfun_indent}" "${msg}"
        else
-               # Print the message without its trailing LF character.
-               msg=${msg%"${genfun_newline}"}
+               # Strip all trailing LF characters before printing the message.
+               while true; do
+                       msg=${msg%"${genfun_newline}"}
+                       if ! _ends_with_newline "${msg}"; then
+                               break
+                       fi
+               done
                printf ' %s*%s %s%s' "${color}" "${NORMAL}" "${genfun_indent}" 
"${msg}"
 
                # Determine the current position of the cursor
@@ -235,7 +240,9 @@ ebegin()
 
        if ! yesno "${EINFO_QUIET}"; then
                msg=$*
-               msg=${msg%"${genfun_newline}"}
+               while _ends_with_newline "${msg}"; do
+                       msg=${msg%"${genfun_newline}"}
+               done
                _eprint "${GOOD}" "${msg} ..."
        fi
 }
@@ -584,7 +591,8 @@ _has_monochrome_terminal() {
 }
 
 _ends_with_newline() {
-       ! case $1 in *"${genfun_newline}") false ;; esac
+       test "${genfun_newline}" \
+       && ! case $1 in *"${genfun_newline}") false ;; esac
 }
 
 _update_tty_level() {

Reply via email to