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:
pyr0ball 2026-07-17 16:01:11 -07:00
parent a0d2cc4382
commit 7b63dbca46

View file

@ -56,20 +56,20 @@ if [[ "$TERM" != "linux" ]] ; then
lyl="${ESC}[38;5;228m" # light yellow
lrd="${ESC}[38;5;196m" # light red
gry="${ESC}[38;5;240m" # Grey
norm=$"${ESC}[39m" # default/normal
norm="${ESC}[39m" # default/normal
#
bld="${ESC}[1m" # bold
unb="${ESC}[21m" # un-bold
dim="${ESC}[2m" # dim
und="${ESC}[22m" # un-dim
unl="${ESC}[4m" # underline
nln="${ESC}[24" # not-underline
blk="${ESC}[5" # blinking
unbl="${ESC}[25" # stop blinking
nln="${ESC}[24m" # not-underline
blk="${ESC}[5m" # blinking
unbl="${ESC}[25m" # stop blinking
inv="${ESC}[7m" # invert
rsinv="${ESC}[27" # reset http://www.endmemo.com/unicode/unicodeconverter.phpnvert
hid="${ESC}[8" # hidden
unh="${ESC}[28" # unhide
rsinv="${ESC}[27m" # reset invert
hid="${ESC}[8m" # hidden
unh="${ESC}[28m" # unhide
dfl="${ESC}[0m" # restore default
fi
@ -98,7 +98,8 @@ box_chars_simple() {
set_box_chars() {
if check_unicode_support; then
case "$OSTYPE" in
unicode_supported=true
case "$OSTYPE" in
linux-gnu*|cygwin|msys)
return_arrow=$(echo -e "\u2BAC")
enter_arrow=$(echo -e "\u21B5")
@ -139,6 +140,7 @@ set_box_chars() {
esac
else
# ASCII fallbacks
unicode_supported=false
return_arrow=">"
enter_arrow="<"
green_check="+"
@ -258,28 +260,34 @@ set-boxtype() {
# Ensure characters are defined
set_box_chars
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
case $style in
case $style in
norm) box-norm ;;
double) box-double ;;
heavy) box-heavy ;;
light) box-light ;;
rounded) box-rounded ;;
char) box-singlechar ;;
*)
*)
# Handle unknown box types by falling back to normal
echo "Warning: Unknown box type '$style', falling back to 'norm'" >&2
boxtype="norm"
box-norm
if [[ "$unicode_supported" == true ]]; then
box-norm
fi
;;
esac
}
box-singlechar(){
set_borders "$borderchar" "$borderchar" "$borderchar" "$borderchar" "$borderchar" "$borderchar" "$borderchar" "$borderchar" "-"
}
format_boxborder() {
local alignment="left"
local box_type="norm"