Center the installer logo in a locale without a charset
logo_width measured the logo with awk's `length`, which counts bytes unless the locale is UTF-8. The logo is drawn in box-drawing glyphs, three bytes each, so the answer was 197 columns rather than 81 anywhere LANG went unset — a console booting before locale.conf applies, a shell that never inherited one. A width wider than the terminal makes left_padding clamp its pad to zero, so the logo sat flush left while the title, bar, and tip centered against a phantom 197-wide box and drifted right of it. The 81 this function already falls back to when logo.txt is missing is the character count, so the intent was never in question, only the measurement. Count bytes deliberately under LC_ALL=C and drop the UTF-8 continuation bytes before measuring. That is the same answer in every locale rather than the right one only in those that have a charset. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
e5f2b466ef
commit
a6a442b9a0
1 file changed
+10
-1
@@ -123,7 +123,16 @@ repeat() {
|
||||
|
||||
logo_width() {
|
||||
if [[ -f $LOGO_PATH ]]; then
|
||||
awk '{ if (length > max) max = length } END { print max+0 }' "$LOGO_PATH"
|
||||
# The logo is drawn in box-drawing glyphs, three bytes each in UTF-8, so
|
||||
# awk's `length` returns 197 rather than 81 unless the locale happens to be
|
||||
# UTF-8 — and a width wider than the console makes left_padding clamp to
|
||||
# zero, which puts the logo flush left. Count bytes deliberately (LC_ALL=C)
|
||||
# and drop the continuation bytes instead, so the answer is columns in every
|
||||
# locale rather than only in the ones that have a charset.
|
||||
LC_ALL=C awk '
|
||||
{ gsub(/[\200-\277]/, ""); if (length > max) max = length }
|
||||
END { print max+0 }
|
||||
' "$LOGO_PATH"
|
||||
else
|
||||
printf '81\n'
|
||||
fi
|
||||
|
||||
Reference in new issue
Block a user