]> git.mdlowis.com Git - projs/tide.git/commitdiff
added OSC to strip prompts from sent input
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 30 Nov 2019 19:00:28 +0000 (14:00 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 30 Nov 2019 19:00:28 +0000 (14:00 -0500)
src/lib/xpty.c

index a7df1d7f3cf0386cc8f16c03f197cf3272ddb8f8..34342441ac68512e9de3318d4c5d81b6130056e7 100644 (file)
@@ -14,6 +14,7 @@
 static View* EditView = NULL;
 static int Pty_Fd = -1;
 static bool DoScroll = 1;
+static char* PromptStr = NULL;
 static char ReadBuf[BUFFERSZ+1] = {0};
 static char ArgsBuf[BUFFERSZ+1] = {0};
 static char InputBuf[BUFFERSZ+1] = {0};
@@ -77,6 +78,11 @@ static void read_osc(char c)
         {
             chdir(&ArgsBuf[2]);
         }
+        else if (ArgsBuf[0] == '0' && ArgsBuf[1] == ';')
+        {
+            free(PromptStr);
+            PromptStr = strdup(&ArgsBuf[2]);
+        }
     }
     else
     {
@@ -250,6 +256,11 @@ void xpty_send(char* cmd)
     {
         EditView->buffer.selection.beg = EditView->buffer.point.end;
         EditView->buffer.selection.end = EditView->buffer.point.end;
+        size_t plen = strlen(PromptStr);
+        if (PromptStr && !strncmp(PromptStr, cmd, plen))
+        {
+            cmd += plen;
+        }
         view_putstr(EditView, cmd);
         if (*cmd && cmd[strlen(cmd)-1] != '\n')
         {