Align rule table display widths
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user