]> git.mdlowis.com Git - projs/tide.git/commitdiff
added Kill tag to kill background job
authorMichael D. Lowis <mike@mdlowis.com>
Tue, 8 Jan 2019 02:59:04 +0000 (21:59 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Tue, 8 Jan 2019 02:59:04 +0000 (21:59 -0500)
TODO.md
inc/edit.h
src/lib/job.c
src/tide.c

diff --git a/TODO.md b/TODO.md
index 03222f85b214718e1d55a1be68b345393b4690df..ec6aa9890145c9f392bcd52d73ffc93690f16bd2 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -10,7 +10,6 @@
 * tide: Ctrl+D should not pass tag name as arg when executing tag commands
 * tide: should re-register with the registrar when a new registrar is launched
 * tide: Line - Get the current line number(s) containing the selection
-* tide: Kill - add a 'Kill' tag to kill the most recent job
 * tide: gap buffer does not handle UTF-8 currently
 
 ## BACKLOG
index b94c64c4ab72f2ce1c9936694e7b35b9ef942e8e..e6d15780d508bf54604b4f72a122adefb3338e3a 100644 (file)
@@ -172,6 +172,8 @@ struct Job {
     void (*readfn)(Job *job);
 };
 
+Job* job_list(void);
+void job_kill(Job* job);
 bool job_poll(int ms);
 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);
index 60729042903bd4162cb055d24e78c517480a4643..1f7e000554515bafce6290522c75ebb3c5af1158 100644 (file)
@@ -111,6 +111,15 @@ static int job_exec(char** cmd, int* p_pid) {
     return fds[0];
 }
 
+Job* job_list(void) {
+    return JobList;
+}
+
+void job_kill(Job* job) {
+    job->readfn = NULL;
+    job->writefn = NULL;
+}
+
 bool job_poll(int ms) {
     int njobs = 0;
     /* Add jobs from the job list */
index e130204940ab276282c1b21a3c9cdcc92db2b825..6c3a212813484e9002986f756521359dd62adcb0 100644 (file)
@@ -26,7 +26,7 @@ typedef struct {
 } Tag;
 
 char* ARGV0;
-static Tag Builtins[16];
+static Tag Builtins[17];
 static Time Now;
 static struct XConf X;
 static int KeyBtnState;
@@ -780,9 +780,16 @@ static void lnexec(char* cmd) {
     exec(cmd);
 }
 
+static void tag_kill(char* cmd) {
+    (void)cmd;
+    Job* job = job_list();
+    if (job && job->fd != ConnectionNumber(X.display))
+        job_kill(job);
+}
+
 /* Main Routine
  ******************************************************************************/
-static Tag Builtins[16] = {
+static Tag Builtins[17] = {
     { .tag = "Cut",    .action = cut       },
     { .tag = "Copy",   .action = copy      },
     { .tag = "Del",    .action = quit      },
@@ -798,6 +805,7 @@ static Tag Builtins[16] = {
     { .tag = "Tabs",   .action = tabs      },
     { .tag = "Undo",   .action = tag_undo  },
     { .tag = "Font",   .action = win_font  },
+    { .tag = "Kill",   .action = tag_kill  },
     { .tag = NULL,     .action = NULL      }
 };