static void putb(int byte)
{
+ struct termios tio = {0};
+ tcgetattr(Pty_Fd, &tio);
+
+ if ((tio.c_lflag & ICANON) == ICANON)
+ {
+ char b = byte;
+ write(Pty_Fd, &b, 1);
+ if (byte != '\n')
+ {
+ *((char*)(EditView->buffer.contents.gapstart-1)) = '*';
+ }
+ }
if (byte == '\n' && buf_inpoint(&(EditView->buffer), EditView->buffer.selection.end-1))
{
+ /* get the input string and update the point */
char* str = buf_getsat(&(EditView->buffer), EditView->buffer.point.beg, EditView->buffer.point.end);
+ size_t slen = strlen(str);
EditView->buffer.point.beg = EditView->buffer.point.end;
-// printf("write '%s'\n", str);
- writefd(Pty_Fd, str, strlen(str));
+
+ /* write the data and read back to discard the echoed chars */
+ writefd(Pty_Fd, str, slen);
+ tcflush(Pty_Fd, TCOFLUSH);
+ (void)readfd(Pty_Fd, str, slen+1);
+
free(str);
}
}
+static void writedata(char* buf, long n)
+{
+ char data[16384];
+ int p = 0;
+ for (int i = 0; i < n; i++)
+ {
+ if (buf[i] == '\033')
+ {
+ }
+ else
+ {
+ data[p++] = buf[i];
+ data[p] = '\0';
+ }
+ }
+ view_putraw(EditView, data);
+ EditView->sync_flags |= CURSOR;
+}
+
static void xpty_read(Job* job)
{
char buffer[16385];
EditView->buffer.point = sel;
/* insert the text */
- view_putraw(EditView, buffer);
+ writedata(buffer, nread);
/* adjust the original selection and swap it back */
nread = (EditView->buffer.point.end - start);
view->buffer.oninsert = putb;
view->buffer.point.beg = view->buffer.selection.end;
view->buffer.point.end = view->buffer.selection.end;
- struct termios tio;
- tcgetattr(Pty_Fd, &tio);
- tio.c_lflag &= ~(ECHO | ECHONL);
- tio.c_cc[ VMIN ] = 1;
- tio.c_cc[ VTIME ] = 0;
- tcsetattr(Pty_Fd, TCSANOW, &tio);
+// struct termios tio;
+// tcgetattr(Pty_Fd, &tio);
+// tio.c_lflag &= ~(ECHO | ECHONL);
+// tio.c_cc[ VMIN ] = 1;
+// tio.c_cc[ VTIME ] = 0;
+// tcsetattr(Pty_Fd, TCSANOW, &tio);
job_spawn(Pty_Fd, xpty_read, NULL, NULL);
}
}