From 604830028e555d2d27604b856e0d180a8e8f1b95 Mon Sep 17 00:00:00 2001 From: Yulin Wu Date: Fri, 25 Jan 2019 15:46:21 +0800 Subject: [PATCH] Fix bug about Controlling the Prompt. Must enclosed not-printable sequences in \[ and \] when use shml in prompt. Or will overwrite the current line of screen and hard to see. Further reading: * https://www.gnu.org/software/bash/manual/bashref.html#Controlling-the-Prompt --- shml.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/shml.sh b/shml.sh index ad4b6e5..d853a5b 100755 --- a/shml.sh +++ b/shml.sh @@ -130,6 +130,8 @@ dialog() { # Foreground (Text) ## fgcolor() { + local __seq_start='\[' + local __seq_end='\]' local __end='\033[39m' local __color=$__end # end by default case "$1" in @@ -151,9 +153,9 @@ fgcolor() { white|ffffff|fff) __color='\033[97m';; esac if test "$2"; then - echo -en "$__color$2$__end" + echo -en "$__seq_start$__color$2$__end$__seq_end" else - echo -en "$__color" + echo -en "$__seq_start$__color$__seq_end" fi } @@ -174,6 +176,8 @@ c() { # Background ## bgcolor() { + local __seq_start='\[' + local __seq_end='\]' local __end='\033[49m' local __color=$__end # end by default case "$1" in @@ -197,9 +201,9 @@ bgcolor() { esac if test "$2"; then - echo -en "$__color$2$__end" + echo -en "$__seq_start$__color$2$__end$__seq_end" else - echo -en "$__color" + echo -en "$__seq_start$__color$__seq_end" fi }