]> git.mdlowis.com Git - projs/tide.git/commitdiff
added handling for password prompts
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 24 Nov 2019 01:52:31 +0000 (20:52 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 24 Nov 2019 01:52:31 +0000 (20:52 -0500)
src/lib/xpty.c

index 6d38db41f635cf0a1947846c9704b9b702b5044e..6c4dfbfd458f926d1cf2f5a439c671dee959afe3 100644 (file)
@@ -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);
         }
     }