Skip to content

Commit

Permalink
kernel: Fix broken wcwidth for wide chars
Browse files Browse the repository at this point in the history
On OSs with old libc, the wcwidth will return -1 for most/all emoji characters
even if they are known to be wide characters. So we add a check that if -1
is returned for something that is known to be wide, we return 2 in size instead
of 0.
  • Loading branch information
garazdawi committed Apr 15, 2024
1 parent 814a3fc commit 0e32395
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/kernel/src/prim_tty.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,14 @@ npwcwidth(Char) ->
npwcwidth(Char, true).
npwcwidth(Char, true) ->
case wcwidth(Char) of
{error, not_printable} -> 0;
{error, not_printable} ->
%% Sometimes libc wcwidth if wrong and returns -1 aka not_printable
%% for something that is a wide character. So we try to make things
%% better by returning 2 for such characters.
case unicode_util:is_wide(Char) of
true -> 2;
false -> 0
end;
{error, enotsup} ->
case unicode_util:is_wide(Char) of
true -> 2;
Expand Down

0 comments on commit 0e32395

Please sign in to comment.