Align rule table display widths

This commit is contained in:
2026-04-17 12:17:00 +08:00
parent 87ee5283c8
commit 818c52c10d
6 changed files with 29 additions and 16 deletions

View File

@@ -57,18 +57,16 @@ log_ok() { _log_with_color "${CLR_GREEN}" OK "$@"; }
display_width() {
local input=${1-}
awk -v str="${input}" 'BEGIN {
n = split(str, chars, "")
width = 0
for (i = 1; i <= n; i++) {
if (chars[i] ~ /[ -~]/) {
width += 1
} else {
width += 2
}
}
print width
}'
local char code width=0
while IFS= read -r -n1 char; do
code=$(printf '%d' "'${char}")
if (( code >= 32 && code <= 126 )); then
((width += 1))
else
((width += 2))
fi
done < <(printf '%s' "${input}")
printf '%s\n' "${width}"
}
repeat_char() {