]> git.mdlowis.com Git - projs/tide.git/commitdiff
hooked in tfetch logic for magic right click handling
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 28 Sep 2018 02:34:19 +0000 (22:34 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 28 Sep 2018 02:34:19 +0000 (22:34 -0400)
TODO.md
inc/edit.h
lib/config.c
lib/job.c
lib/x11.c
tide.c

diff --git a/TODO.md b/TODO.md
index 3e3c28b47bc6119054f38e20c1cf734adc18cbd3..c2b03d8c06cd1e8f6bbab03076380245d9db87bd 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -2,7 +2,10 @@
 
 ## STAGING
 
-* no magic right click
+* selecting lines no longer works if cursor is on first char
+* implement new version of tfetch
+* implement tide registrar
+* implement tctl command
 * implement mouse warping on search, jump to line, and focus change
 * gap buffer does not handle UTF-8 currently
 * mouse selection handling when mouse moves outside region
index bffdbe0ec0777629a486cf416d6fde30a3470505..bb1e8b81e63f18751babc30db72c2630066dd46c 100644 (file)
@@ -172,6 +172,7 @@ bool job_poll(int ms);
 void job_spawn(int fd, jobfn_t readfn, jobfn_t writefn, void* data);
 void job_create(char** cmd, jobfn_t readfn, jobfn_t writefn, void* data);
 void job_start(char** cmd, char* data, size_t ndata, View* dest);
+int job_run(char** cmd);
 
 /* Configuration Data
  *****************************************************************************/
@@ -186,7 +187,7 @@ enum { /* Color Names */
     ClrCount
 };
 
-extern char *TagString, *Fonts[2];
+extern char *TagString, *Fonts[2], *FetchCmd[];
 extern int Palette[ClrCount];
 extern int WinWidth, WinHeight, ScrollWidth, Timeout, TabWidth, ScrollBy,
            ClickTime, CopyIndent, TrimOnSave, ExpandTabs, DosLineFeed;
index 145bf831ae00e7e76e2fec14c78421b1b45c2a08..db50379f99b81a86e3aacbfeb93a0419dd4274e8 100644 (file)
@@ -4,7 +4,10 @@
 #include <utf.h>
 #include <edit.h>
 
+char* FetchCmd[] = { "tfetch", NULL, NULL };
+
 char* TagString = "Del Put Undo Redo | Font Tabs Eol | Find ";
+
 char* Fonts[2] = {
     "Verdana:size=11",
 #ifdef __MACH__
index aac1b34b21ad5d8278215c5ca954d601aef22919..c54f6ccca4d052ff7c2fb0d0df934c3714bfacb6 100644 (file)
--- a/lib/job.c
+++ b/lib/job.c
@@ -80,7 +80,7 @@ static void job_process(int fd, int events) {
         job_finish(job);
 }
 
-static int job_exec(char** cmd) {
+static int job_exec(char** cmd, int* p_pid) {
     int pid, fds[2];
     /* create the sockets */
     if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) < 0)
@@ -100,6 +100,7 @@ static int job_exec(char** cmd) {
     } else {
         close(fds[1]);
     }
+    if (p_pid) *p_pid = pid;
     return fds[0];
 }
 
@@ -134,7 +135,7 @@ void job_spawn(int fd, jobfn_t readfn, jobfn_t writefn, void* data) {
 }
 
 void job_start(char** cmd, char* data, size_t ndata, View* dest) {
-    int fd = job_exec(cmd);
+    int fd = job_exec(cmd, 0);
     if (fd >= 0 && (data || dest)) {
         struct PipeData* pipedata = NULL;
         if (data) {
@@ -148,3 +149,12 @@ void job_start(char** cmd, char* data, size_t ndata, View* dest) {
         close(fd);
     }
 }
+
+int job_run(char** cmd) {
+    int pid = -1, status = 0;
+    job_exec(cmd, &pid);
+    do {
+        waitpid(pid, &status, WUNTRACED|WCONTINUED);
+    } while (!WIFEXITED(status) && !WIFSIGNALED(status));
+    return WEXITSTATUS(status);
+}
index fac36324940a879051eba52d2113b944083a5db9..6afd01ab50339fea4ae4c81c4cfb2a4b629b4487 100644 (file)
--- a/lib/x11.c
+++ b/lib/x11.c
@@ -237,10 +237,15 @@ static void mouse_right(WinRegion id, bool pressed, size_t row, size_t col) {
     if (PRESSED(MouseLeft)) {
         paste(NULL);
     } else {
-        SearchDir *= (win_keymodsset(ModShift) ? -1 : +1);
-        free(SearchTerm);
-        SearchTerm = view_fetch(win_view(id), row, col, risfile);
-        view_findstr(win_view(id), SearchDir, SearchTerm);
+        FetchCmd[1] = view_fetch(win_view(id), row, col, risfile);
+        if (job_run(FetchCmd) != 0) {
+            SearchDir *= (win_keymodsset(ModShift) ? -1 : +1);
+            free(SearchTerm);
+            SearchTerm = view_fetch(win_view(id), row, col, risfile);
+            view_findstr(win_view(EDIT), SearchDir, SearchTerm);
+        } else {
+            free(FetchCmd[1]);
+        }
     }
 }
 
diff --git a/tide.c b/tide.c
index 5b4277b8f01bd0e82bdc2a2ae301fb809e5dcc8f..c6d7c3bffef5f87c4063be2d4da569477a523690 100644 (file)
--- a/tide.c
+++ b/tide.c
@@ -20,9 +20,6 @@ char* ShellCmd[] = { NULL, "-c", NULL, NULL };
 /* Sed command used to execute commands marked with ':' sigil */
 char* SedCmd[] = { "sed", "-e", NULL, NULL };
 
-/* Try to fetch the text with tide-fetch */
-char* FetchCmd[] = { "tfetch", NULL, NULL };
-
 #define CMD_TIDE     "!tide"
 #define CMD_PICKFILE "!pickfile ."
 #define CMD_COMPLETE "<picktag print tags"