fix: terminate truncated ANSI codes, honor ASCII fallback in box borders
- blk/nln/unbl/rsinv/hid/unh were missing the trailing 'm', producing
invalid escape sequences. Concatenated with text (e.g. temperature
readouts using ${blk}), strict-parsing terminals would read the
digits/letters that followed as CSI parameters, causing garbled
output or unwanted cursor movement.
- norm used bash's $"..." locale-translation syntax on an ANSI code
instead of a plain string.
- set-boxtype() always ran box-norm/double/heavy/light/rounded, which
draw with hardcoded Unicode corner glyphs, even when
check_unicode_support() determined the terminal/locale couldn't
render Unicode. This defeated box_chars_simple()'s ASCII fallback
entirely. Now the Unicode style dispatch is skipped when
unicode_supported is false.
- Removed a duplicate box-singlechar() definition.
This commit is contained in:
parent
a0d2cc4382
commit
7b63dbca46
1 changed files with 24 additions and 16 deletions
40
functions
40
functions
|
|
@ -56,20 +56,20 @@ if [[ "$TERM" != "linux" ]] ; then
|
||||||
lyl="${ESC}[38;5;228m" # light yellow
|
lyl="${ESC}[38;5;228m" # light yellow
|
||||||
lrd="${ESC}[38;5;196m" # light red
|
lrd="${ESC}[38;5;196m" # light red
|
||||||
gry="${ESC}[38;5;240m" # Grey
|
gry="${ESC}[38;5;240m" # Grey
|
||||||
norm=$"${ESC}[39m" # default/normal
|
norm="${ESC}[39m" # default/normal
|
||||||
#
|
#
|
||||||
bld="${ESC}[1m" # bold
|
bld="${ESC}[1m" # bold
|
||||||
unb="${ESC}[21m" # un-bold
|
unb="${ESC}[21m" # un-bold
|
||||||
dim="${ESC}[2m" # dim
|
dim="${ESC}[2m" # dim
|
||||||
und="${ESC}[22m" # un-dim
|
und="${ESC}[22m" # un-dim
|
||||||
unl="${ESC}[4m" # underline
|
unl="${ESC}[4m" # underline
|
||||||
nln="${ESC}[24" # not-underline
|
nln="${ESC}[24m" # not-underline
|
||||||
blk="${ESC}[5" # blinking
|
blk="${ESC}[5m" # blinking
|
||||||
unbl="${ESC}[25" # stop blinking
|
unbl="${ESC}[25m" # stop blinking
|
||||||
inv="${ESC}[7m" # invert
|
inv="${ESC}[7m" # invert
|
||||||
rsinv="${ESC}[27" # reset http://www.endmemo.com/unicode/unicodeconverter.phpnvert
|
rsinv="${ESC}[27m" # reset invert
|
||||||
hid="${ESC}[8" # hidden
|
hid="${ESC}[8m" # hidden
|
||||||
unh="${ESC}[28" # unhide
|
unh="${ESC}[28m" # unhide
|
||||||
dfl="${ESC}[0m" # restore default
|
dfl="${ESC}[0m" # restore default
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -98,7 +98,8 @@ box_chars_simple() {
|
||||||
|
|
||||||
set_box_chars() {
|
set_box_chars() {
|
||||||
if check_unicode_support; then
|
if check_unicode_support; then
|
||||||
case "$OSTYPE" in
|
unicode_supported=true
|
||||||
|
case "$OSTYPE" in
|
||||||
linux-gnu*|cygwin|msys)
|
linux-gnu*|cygwin|msys)
|
||||||
return_arrow=$(echo -e "\u2BAC")
|
return_arrow=$(echo -e "\u2BAC")
|
||||||
enter_arrow=$(echo -e "\u21B5")
|
enter_arrow=$(echo -e "\u21B5")
|
||||||
|
|
@ -139,6 +140,7 @@ set_box_chars() {
|
||||||
esac
|
esac
|
||||||
else
|
else
|
||||||
# ASCII fallbacks
|
# ASCII fallbacks
|
||||||
|
unicode_supported=false
|
||||||
return_arrow=">"
|
return_arrow=">"
|
||||||
enter_arrow="<"
|
enter_arrow="<"
|
||||||
green_check="+"
|
green_check="+"
|
||||||
|
|
@ -258,28 +260,34 @@ set-boxtype() {
|
||||||
# Ensure characters are defined
|
# Ensure characters are defined
|
||||||
set_box_chars
|
set_box_chars
|
||||||
update_terminal_width
|
update_terminal_width
|
||||||
|
|
||||||
|
# box-norm/double/heavy/light/rounded all draw with hardcoded Unicode corner
|
||||||
|
# glyphs; on a terminal without Unicode support, box_chars_simple() (called
|
||||||
|
# from set_box_chars above) already set full ASCII borders/corners, so skip
|
||||||
|
# the style dispatch entirely rather than clobbering them.
|
||||||
|
if [[ "$unicode_supported" != true && "$style" != "char" ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
# Set the box style
|
# Set the box style
|
||||||
case $style in
|
case $style in
|
||||||
norm) box-norm ;;
|
norm) box-norm ;;
|
||||||
double) box-double ;;
|
double) box-double ;;
|
||||||
heavy) box-heavy ;;
|
heavy) box-heavy ;;
|
||||||
light) box-light ;;
|
light) box-light ;;
|
||||||
rounded) box-rounded ;;
|
rounded) box-rounded ;;
|
||||||
char) box-singlechar ;;
|
char) box-singlechar ;;
|
||||||
*)
|
*)
|
||||||
# Handle unknown box types by falling back to normal
|
# Handle unknown box types by falling back to normal
|
||||||
echo "Warning: Unknown box type '$style', falling back to 'norm'" >&2
|
echo "Warning: Unknown box type '$style', falling back to 'norm'" >&2
|
||||||
boxtype="norm"
|
boxtype="norm"
|
||||||
box-norm
|
if [[ "$unicode_supported" == true ]]; then
|
||||||
|
box-norm
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
box-singlechar(){
|
|
||||||
set_borders "$borderchar" "$borderchar" "$borderchar" "$borderchar" "$borderchar" "$borderchar" "$borderchar" "$borderchar" "-"
|
|
||||||
}
|
|
||||||
|
|
||||||
format_boxborder() {
|
format_boxborder() {
|
||||||
local alignment="left"
|
local alignment="left"
|
||||||
local box_type="norm"
|
local box_type="norm"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue