vtgl

terminal emulator implemented in OpenGL
git clone anongit@rnpnr.xyz:vtgl.git
Log | Files | Refs | Feed | LICENSE

Commit: ee916f134c6c34eb080b89ece95aba84d48d58f3
Parent: 78d8a7d85407d7efc803a8e2598424ae6e76b37c
Author: Randy Palamar
Date:   Wed, 22 Jan 2025 22:08:24 -0700

terminal: convert dump_csi to a more generic stream_push_csi

Diffstat:
Mterminal.c | 68+++++++++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 39 insertions(+), 29 deletions(-)

diff --git a/terminal.c b/terminal.c @@ -438,42 +438,40 @@ term_reset(Term *t) } static void -dump_csi(CSI *csi, Stream *err) +stream_push_csi(Stream *s, CSI *csi) { - stream_push_s8(err, s8("raw: ESC[")); + stream_push_s8(s, s8("ESC [")); for (size i = 0; i < csi->raw.len; i++) { u8 c = csi->raw.data[i]; if (ISPRINT(c)) { - stream_push_byte(err, csi->raw.data[i]); + stream_push_byte(s, csi->raw.data[i]); } else if (c == '\n') { - stream_push_s8(err, s8("\\n")); + stream_push_s8(s, s8("\\n")); } else if (c == '\r') { - stream_push_s8(err, s8("\\r")); + stream_push_s8(s, s8("\\r")); } else { - stream_push_s8(err, s8("\\x")); - stream_push_hex_u64(err, c); + stream_push_s8(s, s8("\\x")); + stream_push_hex_u64(s, c); } } - stream_push_s8(err, s8("\n\tparsed = { .priv = ")); - stream_push_u64(err, csi->priv); - stream_push_s8(err, s8(" .mode = ")); + stream_push_s8(s, s8("\n\t{ .priv = ")); + stream_push_u64(s, csi->priv); + stream_push_s8(s, s8(" .mode = ")); if (ISPRINT(csi->mode)) { - stream_push_byte(err, csi->mode); + stream_push_byte(s, csi->mode); } else { - stream_push_s8(err, s8("\\x")); - stream_push_hex_u64(err, csi->mode); + stream_push_s8(s, s8("\\x")); + stream_push_hex_u64(s, csi->mode); } - stream_push_s8(err, s8(", .argc = ")); - stream_push_u64(err, csi->argc); - stream_push_s8(err, s8(", .argv = {")); + + stream_push_s8(s, s8(", .argc = ")); + stream_push_u64(s, csi->argc); + stream_push_s8(s, s8(", .argv = {")); for (i32 i = 0; i < csi->argc; i++) { - stream_push_byte(err, ' '); - stream_push_i64(err, csi->argv[i]); + stream_push_byte(s, ' '); + stream_push_i64(s, csi->argv[i]); } - - stream_push_s8(err, s8(" } }\n")); - os_write_err_msg(stream_to_s8(err)); - err->widx = 0; + stream_push_s8(s, s8(" } }\n")); } /* ED/DECSED: Erase in Display */ @@ -656,8 +654,10 @@ set_mode(Term *t, CSI *csi, b32 set, ModeState src, ModeState *dest) * fast enough */ break; default: - os_write_err_msg(s8("set_mode: unhandled mode: ")); - dump_csi(csi, &t->error_stream); + stream_push_s8(&t->error_stream, s8("set_mode: unhandled mode: ")); + stream_push_csi(&t->error_stream, csi); + os_write_err_msg(stream_to_s8(&t->error_stream)); + t->error_stream.widx = 0; } } #undef PRIV @@ -777,7 +777,9 @@ set_colours(Term *t, CSI *csi) cs->fg = dcr.colour; } else { stream_push_s8(&t->error_stream, s8("set_colours: ")); - dump_csi(csi, &t->error_stream); + stream_push_csi(&t->error_stream, csi); + os_write_err_msg(stream_to_s8(&t->error_stream)); + t->error_stream.widx = 0; } break; @@ -789,7 +791,9 @@ set_colours(Term *t, CSI *csi) cs->bg = dcr.colour; } else { stream_push_s8(&t->error_stream, s8("set_colours: ")); - dump_csi(csi, &t->error_stream); + stream_push_csi(&t->error_stream, csi); + os_write_err_msg(stream_to_s8(&t->error_stream)); + t->error_stream.widx = 0; } break; @@ -808,7 +812,9 @@ set_colours(Term *t, CSI *csi) stream_push_s8(&t->error_stream, s8("unhandled colour arg: ")); stream_push_i64(&t->error_stream, csi->argv[i]); stream_push_byte(&t->error_stream, '\n'); - dump_csi(csi, &t->error_stream); + stream_push_csi(&t->error_stream, csi); + os_write_err_msg(stream_to_s8(&t->error_stream)); + t->error_stream.widx = 0; } } } @@ -839,7 +845,9 @@ window_manipulation(Term *t, CSI *csi) stream_push_s8(&t->error_stream, s8("unhandled xtwinops: ")); stream_push_i64(&t->error_stream, csi->argv[0]); stream_push_byte(&t->error_stream, '\n'); - dump_csi(csi, &t->error_stream); + stream_push_csi(&t->error_stream, csi); + os_write_err_msg(stream_to_s8(&t->error_stream)); + t->error_stream.widx = 0; } } @@ -972,7 +980,9 @@ handle_csi(Term *t, CSI *csi) default: unknown: stream_push_s8(&t->error_stream, s8("unknown csi: ")); - dump_csi(csi, &t->error_stream); + stream_push_csi(&t->error_stream, csi); + os_write_err_msg(stream_to_s8(&t->error_stream)); + t->error_stream.widx = 0; } END_TIMED_BLOCK(); }