Fix/utf8 log alignment (#2717)
The problem is caused by calculating space used by strings using string.length() which only works if every char in the string is encoded in 1 byte. The wrongly calculated space is then used to truncate the string at the wrong place. Finally, the wrongly calculated space is used to align the log entries which results in misalignment. The fix consists on counting utf-8 characters to calculate the spaces and using a function designed to work on utf-8 strings that returns sub-stings. A further problem with alignment was caused when using CJK chars that are wider than regular half-width characters which throws the space calculations off. This was fixed by detecting when CJK glyphs are being used and adjusting the sizes using a reasonable approximation that 1 CJK char ~ 1.75 half-width chars. Compare the two images. Before the PR: <img width="1665" height="858" alt="zoomit" src="https://github.com/user-attachments/assets/9d1a467d-a0fa-4cf6-882f-51712044234f" /> and after the PR: <img width="1925" height="863" alt="after" src="https://github.com/user-attachments/assets/bb905f79-8bb5-4bd3-85b5-fb36327bc19b" /> Note how the utf-8 strings are truncated more than they should and that for those same entries the alignment is lost but are not with the changes. The image shows how CJK glyphs are handled.
P
paxcut committed
be7b7a8dbf1de5a3ae6a6b172154b69e61dc38b9
Parent: 31c1db8
Committed by GitHub <noreply@github.com>
on 4/21/2026, 2:13:49 AM