From: Michael D. Lowis Date: Sun, 24 Nov 2019 01:52:31 +0000 (-0500) Subject: added handling for password prompts X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=0630150778fa08a55bde210852be8653b87cacc4;p=projs%2Ftide.git added handling for password prompts --- diff --git a/src/lib/xpty.c b/src/lib/xpty.c index 6d38db4..6c4dfbf 100644 --- a/src/lib/xpty.c +++ b/src/lib/xpty.c @@ -14,16 +14,53 @@ static int Pty_Fd = -1; 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]; @@ -51,7 +88,7 @@ static void xpty_read(Job* job) 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); @@ -100,12 +137,12 @@ int xpty_run(View* view, char** cmd) 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); } }