From 5e464afa775b163b39deeaf73f111897e5615b07 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Thu, 15 Sep 2022 18:14:08 +0700 Subject: [PATCH] WIP: Identify a basic Control Sequence Introducer --- bt.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/bt.c b/bt.c index 4fb02d3..bfccddd 100644 --- a/bt.c +++ b/bt.c @@ -193,6 +193,30 @@ int main(void) { DrawTextEx(*fontDefault, row_buf, pos, fontsize, 0, RAYWHITE); nrow++; ncol = 0; + } if (sb.buf[c] == '\x1b') { + int c2 = c + 1; + // Control Sequence Introducer + int csi_args[16]; + char csi_code; + int nargs = 0; + if (sb.buf[c2] == '[') { + char *esc_buf = sb.buf + c2 + 1; + while (true) { + char *substr; + long num = strtol(esc_buf, &substr, 10); + if (esc_buf != substr) { + csi_args[nargs++] = num; + esc_buf = substr; + if (substr[0] == ';') { + esc_buf++; + } + continue; + } + csi_code = substr[0]; + break; + } + } + printf("Found an escape sequence. Code: %c.\n", csi_code); } else { row_buf[ncol] = sb.buf[c]; ncol++;