From: Michael D. Lowis Date: Tue, 8 Jan 2019 02:59:04 +0000 (-0500) Subject: added Kill tag to kill background job X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=867ee965bbf83d65a32322af53b83d24aed72207;p=projs%2Ftide.git added Kill tag to kill background job --- diff --git a/TODO.md b/TODO.md index 03222f8..ec6aa98 100644 --- 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 diff --git a/inc/edit.h b/inc/edit.h index b94c64c..e6d1578 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -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); diff --git a/src/lib/job.c b/src/lib/job.c index 6072904..1f7e000 100644 --- a/src/lib/job.c +++ b/src/lib/job.c @@ -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 */ diff --git a/src/tide.c b/src/tide.c index e130204..6c3a212 100644 --- a/src/tide.c +++ b/src/tide.c @@ -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 } };