Re: [PATCH 06/16] Reset terminal styles

Tom Tromey
2018-12-28T19:01:53Z

>>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:

>> printf_command (const char *arg, int from_tty)
>> {
>> ui_printf (arg, gdb_stdout);
>> + reset_terminal_style (gdb_stdout);
>> + wrap_here ("");

Joel> Can you explain why you added the "wrap_here"?

gdb's pager has the unusual property that it introduces another layer of
buffering that isn't accessible to gdb_flush. So, to properly flush
stdout and I guess stderr, one must first call wrap_here to flush this
buffer.

You can see this most clearly in exceptions.c:print_flush, which is
where this seems to have been documented.

In this particular case, reset_terminal_style might emit an escape
sequence to the wrap buffer. So, wrap_here is needed to be sure this is
flushed. We can't flush in reset_terminal_style because it might be
used in cases where flushing is inappropriate, for example in the middle
of a command when paging is still desired.

I think a better design would be to require nothing more than gdb_flush.
However, this requires some thought and experimentation, and seemed
orthogonal to my goal in this series.

Tom