]> git.mdlowis.com Git - projs/tide.git/commitdiff
added escape code for updating working directory from shell
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 20 Jul 2017 01:12:33 +0000 (21:12 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 20 Jul 2017 01:12:33 +0000 (21:12 -0400)
lib/pty.c

index ad95b4eb61b4e826f8ac25af2d1d1777528adbf1..fd1a532402430dc361c45650761df4d3757679cd 100644 (file)
--- a/lib/pty.c
+++ b/lib/pty.c
@@ -86,17 +86,29 @@ void pty_send_rune(Rune rune) {
     }
 }
 
+static void read_escape(char* data, long* i, long n) {
+    /* only one escape code supported and that is to change the working dir */
+    if (data[*i] != 'P') return;
+    size_t sz = strlen(&data[*i + 1]);
+    chdir(&data[*i + 1]);
+    *i = *i + 1 + sz;
+}
+
 static void update(int fd, void* data) {
     /* Read from command if we have one */
     long n = 0, i = 0;
     static char cmdbuf[8192];
-    if ((n = read(PtyFD, cmdbuf, sizeof(cmdbuf))) < 0)
+    if ((n = read(PtyFD, cmdbuf, sizeof(cmdbuf)-1)) < 0)
         PtyFD = -1;
+    cmdbuf[n] = '\0';
     while (i < n) {
         Rune rune = 0;
         size_t length = 0;
         while (!utf8decode(&rune, &length, cmdbuf[i++]));
-        view_insert(win_view(EDIT), false, rune);
+        if (rune == '\033')
+            read_escape(cmdbuf, &i, n);
+        else
+            view_insert(win_view(EDIT), false, rune);
     }
     win_buf(EDIT)->outpoint = win_view(EDIT)->selection.end;
 }