]> git.mdlowis.com Git - projs/tide.git/commitdiff
fetch now tracks launch commands and continues if a ruleset does not contain a launch...
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 19 Nov 2019 03:24:27 +0000 (22:24 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 19 Nov 2019 03:24:27 +0000 (22:24 -0500)
inc/edit.h
src/fetch.c
src/lib/buf.c
src/lib/xpty.c
src/tide.c

index 41d1447fea743ec73651a86351b13ee1f2fbe0c1..1c61f54a900b1069aceaeeffa88e480d4217e15f 100644 (file)
@@ -40,6 +40,7 @@ typedef struct {
     GapBuf contents;  /* underlying sequence data structure */
     EditLog log;      /* underlying log of edit operations */
     Sel selection;    /* the currently selected text */
+    Sel point;    /* tracks external command I/O */
 } Buf;
 
 enum {
index e10f9153137234fb8794d1fb0f3d963780da8227..12285b7351924c9249b61a0c7ab6b44a64e3a6e5 100644 (file)
@@ -17,6 +17,7 @@ typedef struct {
 char* Matches[10];
 Rule*** Rulesets = NULL;
 size_t NumRulesets = 0;
+bool Launched = false;
 
 static Rule*** BuiltinRules = (Rule**[]){
     (Rule*[]){ /* Match URLS and open them with the browser */
@@ -227,6 +228,7 @@ static bool launch(char* cmd)
     int pid = fork();
     if (pid > 0)
     {
+        Launched = true;
         ret = true;
     }
     else if (pid == 0)
@@ -453,6 +455,7 @@ static void parse_rules(char* path)
 
 static void check_ruleset(Rule** rule)
 {
+    Launched = false;
     for (; (*rule)->type != COMPLETE; rule++)
     {
         telem_send("  RULE(%s '%s' '%s')\n", type2str((*rule)->type), (*rule)->arg1, (*rule)->arg2);
@@ -462,7 +465,7 @@ static void check_ruleset(Rule** rule)
         }
     }
 
-    if ((*rule)->type == COMPLETE)
+    if (Launched && (*rule)->type == COMPLETE)
     {
         telem_send("  ACCEPT\n");
         exit(0);
index ca4d0ecd17a6f5b4e07b393cf259d356ede76dd4..232bfe1ee1352fb20c60152822dd4dad7b27d28f 100644 (file)
@@ -86,18 +86,31 @@ static void selset(Buf* buf, Sel sel)
     getcol(buf);
 }
 
+static void putb(Buf* buf, char b, Sel* p_sel)
+{
+    if (p_sel->end < buf->point.beg)
+    {
+        buf->point.beg++;
+    }
+    if (p_sel->end <= buf->point.end)
+    {
+        buf->point.end++;
+    }
+    gapbuf_putb(&buf->contents, b, p_sel);
+}
+
 static void putch(Buf* buf, char b, Sel* p_sel)
 {
     if (b != '\r')
     {
         if (b == '\n' && DosLineFeed)
         {
-            gapbuf_putb(&buf->contents, '\r', p_sel);
-            gapbuf_putb(&buf->contents, '\n', p_sel);
+            putb(buf, '\r', p_sel);
+            putb(buf, '\n', p_sel);
         }
         else
         {
-            gapbuf_putb(&buf->contents, b, p_sel);
+            putb(buf, b, p_sel);
         }
         buf->status = MODIFIED;
     }
@@ -353,6 +366,14 @@ void buf_del(Buf* buf)
         char* str = buf_gets(buf);
         gapbuf_del(&buf->contents, sel.beg, nbytes);
         sel.end = sel.beg = (sel.beg < sel.end ? sel.beg : sel.end);
+        if (sel.end <= buf->point.beg)
+        {
+            buf->point.beg -= (buf->point.beg - sel.end);
+        }
+        if (sel.end <= buf->point.end)
+        {
+            buf->point.end -= (buf->point.end - sel.end);
+        }
         buf->selection = sel;
         editlog_add(buf, sel.beg, sel.end, str);
     }
index f729ac04904ae3a5397c04cf425de395dd871e19..23b07e9f7eafbb8448a6fda844703ef577534301 100644 (file)
@@ -18,22 +18,49 @@ static void xpty_read(Job* job)
     if (nread <= 0)
     {
         job->readfn = NULL;
-        buf_logstop(&EditView->buffer);
         Pty_Fd = -1;
         EditView = NULL;
     }
     else if (nread > 0)
     {
+// &while [ 1 ]; do sleep 1; echo foo; done
         buffer[nread] = '\0';
-        buf_logstart(&EditView->buffer);
+
+//        printf("B1 - E: %lu P: %lu-%lu S: %lu-%lu\n",
+//            buf_end(&(EditView->buffer)),
+//            EditView->buffer.point.beg, EditView->buffer.point.end,
+//            EditView->buffer.selection.beg, EditView->buffer.selection.end);
+
+        size_t start = EditView->buffer.point.beg;
+        Sel sel = EditView->buffer.selection;
+        EditView->buffer.selection.beg = EditView->buffer.point.beg;
+        EditView->buffer.selection.end = EditView->buffer.point.beg;
+        EditView->buffer.point = sel;
+
+//        printf("B2 - E: %lu P: %lu-%lu S: %lu-%lu\n",
+//            buf_end(&(EditView->buffer)),
+//            EditView->buffer.point.beg, EditView->buffer.point.end,
+//            EditView->buffer.selection.beg, EditView->buffer.selection.end);
+
         view_putstr(EditView, buffer);
-    }
-}
 
-static void xpty_write(Job* job)
-{
-    job->writefn = NULL;
-    shutdown(job->fd, SHUT_WR);
+        if (start <= sel.beg)
+        {
+            sel.beg += nread-1;
+        }
+        if (start <= sel.end)
+        {
+            sel.end += nread-1;
+        }
+        Sel point = EditView->buffer.selection;
+        EditView->buffer.selection = sel;
+        EditView->buffer.point = point;
+
+//        printf("A - E: %lu P: %lu-%lu S: %lu-%lu\n",
+//            buf_end(&(EditView->buffer)),
+//            EditView->buffer.point.beg, EditView->buffer.point.end,
+//            EditView->buffer.selection.beg, EditView->buffer.selection.end);
+    }
 }
 
 bool xpty_active(void)
@@ -60,7 +87,16 @@ int xpty_run(View* view, char** cmd)
         {
             Pty_Fd = fd;
             EditView = view;
-            job_spawn(Pty_Fd, xpty_read, xpty_write, NULL);
+            if (view_selsize(view))
+            {
+//                puts("delete");
+                view_delete(view, LEFT, false);
+            }
+//            printf("S - E: %lu P: %lu-%lu S: %lu-%lu\n",
+//                buf_end(&(EditView->buffer)),
+//                EditView->buffer.point.beg, EditView->buffer.point.end,
+//                EditView->buffer.selection.beg, EditView->buffer.selection.end);
+            job_spawn(Pty_Fd, xpty_read, NULL, NULL);
         }
     }
     return fd;
@@ -68,5 +104,6 @@ int xpty_run(View* view, char** cmd)
 
 void xpty_send(uint32_t key)
 {
-    (void)key;
+    view_insert(EditView, key);
+//    printf("%lu-%lu\n", EditView->buffer.point.beg, EditView->buffer.point.end);
 }
index 3148f70df9a32c14908a6dc4f74d4954ff9c47a6..5d3c9e7c34f41c7c49bd22d26ef08b30112334fb 100644 (file)
@@ -141,7 +141,16 @@ static void xkeypress(XConf* x, XEvent* e)
     uint32_t key = x11_process_key(x, e, Bindings);
     telem_send("KEY(reg: %d, key: 0x%x)\n", Focused, key);
     if (key != RUNE_ERR)
-        view_insert(win_view(FOCUSED), key);
+    {
+        if (Focused == EDIT && xpty_active())
+        {
+            xpty_send(key);
+        }
+        else
+        {
+            view_insert(win_view(FOCUSED), key);
+        }
+    }
 }
 
 static void xmousebtn(XConf* x, XEvent* e)
@@ -445,7 +454,7 @@ static void cmd_exec(char* cmd)
     execcmd[2] = cmd;
 
     /* get the selection that the command will operate on */
-    if (op && op != '<' && op != '!' && !view_selsize(win_view(EDIT)))
+    if (op && op != '<' && op != '!' && op != '&' && !view_selsize(win_view(EDIT)))
     {
         view_selectall(win_view(EDIT));
     }