[PATCH] [gdb/tui] Handle unicode chars in prompt
Tom de Vries
tdevries@suse.de
Fri Jun 9 09:48:57 GMT 2023
On 5/30/23 19:03, Tom Tromey wrote:
>>> In TUI, the prompt is written out by tui_puts_internal, which outputs one byte
>>> at a time using waddch, which apparantly breaks multi-byte char support.
>>> Fix this by detecting multi-byte chars in tui_puts_internal, and
>>> printing them using
>>> waddnstr.
>
>> FWIW, I just came across this commit, which seems relevant:
>
> Tom> Note that tui_puts_internal remains. It is needed to handle computing
> Tom> the start line of the readline prompt, which is difficult to do
> Tom> properly in the case where redisplaying can also cause the command
> Tom> window to scroll. This might be possible to implement by reverting to
> Tom> single "character" output, by using mbsrtowcs for its side effects to
> Tom> find character boundaries in the input. I have not attempted this.
> Tom> ...
>
> I no longer remember what made this difficult. I wonder if it's
> possible to simply emit as many characters as possible in a single call,
> and then use getyx to figure out the length of the prompt after it has
> been fully displayed. If the prompt wraps or if it takes multiple
> lines, offhand it seems fine to just pick whatever the final column
> happens to be.
>
>
> Using wchar functions in gdb is a pain; at least in the past,
> gdb_wchar.h was written to support systems that don't support these at
> all (DJGPP - not sure if that host even builds any more).
>
> Some characters may take multiple columns (see 'wcwidth'). I'd hope
> that the display-and-getyx approach would avoid having to have gdb
> understand this; though I suppose gdb's pager probably already gets this
> wrong.
Thanks for the pointer.
In v2 I've used #ifdef HAVE_BTOWC to guard the use of mbrtowc, with a
reference to gdb_wchar.h.
[ Though I do wonder whether we could rely on the c++ stdlib instead and
just use std::mbrtowc. ]
I've also fixed a bug, the v1 version didn't take care of wrapping due
to printing a multi-byte character.
I've added a simplification patch to make the structure of the function
easier to understand, making that bug easier to spot.
Thanks,
- Tom
More information about the Gdb-patches
mailing list