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')
static void read_esc(char c)
{
+ ArgsBuf[(ArgsPos = 0)] = '\0';
if (c == '[')
{
State = READ_OSI;
}
- else
- if (c == ']')
+ else if (c == ']')
{
State = READ_OSC;
}
{
chdir(&ArgsBuf[2]);
}
- ArgsPos = 0;
- ArgsBuf[0] = '\0';
}
else
{
}
static void (*Handlers[])(char c) = {
+ [READ_ECHO] = read_echo,
[READ_CHAR] = read_char,
[READ_ESC] = read_esc,
[READ_OSC] = read_osc,
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);
}
{
InputBuf[0] = '\0';
InputPos = 0;
+// printf("read: '%s'\n", ReadBuf);
for (long i = 0; i < n; i++)
{
Handlers[State](buf[i]);