From 613f5b6c6e7fb7e6aa522f0e8023f4f8f6de5528 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 29 Nov 2019 21:31:41 -0500 Subject: [PATCH] added read-back of the echo to state machine --- src/lib/xpty.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/lib/xpty.c b/src/lib/xpty.c index 8efac44..b7dc217 100644 --- a/src/lib/xpty.c +++ b/src/lib/xpty.c @@ -18,13 +18,25 @@ static char ArgsBuf[BUFFERSZ+1] = {0}; static char InputBuf[BUFFERSZ+1] = {0}; static ssize_t ArgsPos = 0; static ssize_t InputPos = 0; +static ssize_t IgnoreCount = 0; static enum { - READ_CHAR = 0, + READ_ECHO = 0, + READ_CHAR, READ_ESC, READ_OSC, READ_OSI, } State = READ_CHAR; +static void read_echo(char c) +{ + (void)c; + IgnoreCount--; + if (IgnoreCount <= 0) + { + State = READ_CHAR; + } +} + static void read_char(char c) { if (c == '\033') @@ -40,12 +52,12 @@ static void read_char(char c) static void read_esc(char c) { + ArgsBuf[(ArgsPos = 0)] = '\0'; if (c == '[') { State = READ_OSI; } - else - if (c == ']') + else if (c == ']') { State = READ_OSC; } @@ -64,8 +76,6 @@ static void read_osc(char c) { chdir(&ArgsBuf[2]); } - ArgsPos = 0; - ArgsBuf[0] = '\0'; } else { @@ -83,6 +93,7 @@ static void read_osi(char c) } static void (*Handlers[])(char c) = { + [READ_ECHO] = read_echo, [READ_CHAR] = read_char, [READ_ESC] = read_esc, [READ_OSC] = read_osc, @@ -120,8 +131,11 @@ static void putb(int byte) EditView->buffer.point.beg = EditView->buffer.point.end; /* write the data and read back to discard the echoed chars */ +// printf("write: '%s'\n", str); writefd(Pty_Fd, str, slen); - (void)readfd(Pty_Fd, str, slen+1); + State = READ_ECHO; + IgnoreCount = slen+1; + InputBuf[(InputPos = 0)] = '\0'; free(str); } @@ -131,6 +145,7 @@ static void writedata(char* buf, long n) { InputBuf[0] = '\0'; InputPos = 0; +// printf("read: '%s'\n", ReadBuf); for (long i = 0; i < n; i++) { Handlers[State](buf[i]); -- 2.52.0