Re: [PATCH 2/2] Allow check-mark to be changed for CLI

Pedro Alves
2025-06-25T17:21:45Z

On 2025-06-25 16:43, Tom Tromey wrote:
> Pedro> So maybe all we need is to base the "current" column's width
> Pedro> depend on the wcwidth of the character used.
>
> I think to do this we'd need something better than wcwidth. See
> appended. Also as Eli points out, the terminal itself can do something
> other than whatever wcwidth reports.
>
> Tom
>
> #define _XOPEN_SOURCE
> #include <wchar.h>
> #include <stdio.h>
>
> #define C L"👉"
>
> int main() {
> printf ("width = %d\n", wcswidth (C, wcslen (C)));
> printf ("of char = %d\n", wcwidth (C[0]));
> return 0;
> }
>
> bapiya. gcc -o q q.c
> bapiya. ./q
> width = -1
> of char = -1
>

That seems to be something with the locale. Yours returns -1 for me too, but the below returns 2:

#define _XOPEN_SOURCE
#include <wchar.h>
#include <stdio.h>
#include <locale.h>

#define C L"👉"

int main()
{
setlocale (LC_CTYPE, "");
printf ("width = %d\n", wcswidth (C, wcslen (C)));
printf ("of char = %d\n", wcwidth (C[0]));
return 0;
}

$ gcc wcwidth.c -o wcwidth
$ ./wcwidth
width = 2
of char = 2