From: Michael D. Lowis Date: Thu, 21 Nov 2019 04:07:43 +0000 (-0500) Subject: added shortcuts for kill, eof, and intr X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=edb30092f49dcd0948ddf4d340e573f953a32a8e;p=projs%2Ftide.git added shortcuts for kill, eof, and intr --- diff --git a/inc/xpty.h b/inc/xpty.h index 442cc07..c70315f 100644 --- a/inc/xpty.h +++ b/inc/xpty.h @@ -1,3 +1,4 @@ bool xpty_active(void); int xpty_run(View* view, char** cmd); - +void xpty_send(char* cmd); +void xpty_rawsend(char* cmd); diff --git a/src/lib/xpty.c b/src/lib/xpty.c index 07b60b4..c165d34 100644 --- a/src/lib/xpty.c +++ b/src/lib/xpty.c @@ -103,7 +103,7 @@ int xpty_run(View* view, char** cmd) view->buffer.point.end = view->buffer.selection.end; struct termios tio; tcgetattr(Pty_Fd, &tio); - tio.c_lflag &= ~(ECHO | ECHONL); + tio.c_lflag &= ~(ECHO | ECHONL); tio.c_cc[ VMIN ] = 1; tio.c_cc[ VTIME ] = 0; tcsetattr(Pty_Fd, TCSANOW, &tio); @@ -112,3 +112,22 @@ int xpty_run(View* view, char** cmd) } return fd; } + +void xpty_send(char* cmd) +{ + if (EditView) + { + EditView->buffer.selection.beg = EditView->buffer.point.end; + EditView->buffer.selection.end = EditView->buffer.point.end; + view_putstr(EditView, cmd); + if (*cmd && cmd[strlen(cmd)-1] != '\n') + { + view_insert(EditView, '\n'); + } + } +} + +void xpty_rawsend(char* str) +{ + (void)write(Pty_Fd, str, strlen(str)); +} diff --git a/src/tide.c b/src/tide.c index 6332e95..281f7ae 100644 --- a/src/tide.c +++ b/src/tide.c @@ -440,46 +440,53 @@ static Tag* tag_lookup(char* cmd) static void cmd_exec(char* cmd) { - /* parse the command sigils */ - char op = '\0', **execcmd = NULL; - if (rissigil(*cmd)) op = *(cmd++); - execcmd = (op == ':' ? SedCmd : ShellCmd); - execcmd[2] = cmd; - - /* get the selection that the command will operate on */ - if (op && op != '<' && op != '!' && op != '&' && !view_selsize(win_view(EDIT))) + if (xpty_active()) { - view_selectall(win_view(EDIT)); + xpty_send(cmd); } - char* input = view_getstr(win_view(EDIT)); - size_t len = (input ? strlen(input) : 0); - View *tags = win_view(TAGS), *edit = win_view(EDIT), *curr = win_view(FOCUSED); - - /* execute the job */ - if (op == '!' || op == '&') + else { - free(input); - if (op == '&') + /* parse the command sigils */ + char op = '\0', **execcmd = NULL; + if (rissigil(*cmd)) op = *(cmd++); + execcmd = (op == ':' ? SedCmd : ShellCmd); + execcmd[2] = cmd; + + /* get the selection that the command will operate on */ + if (op && op != '<' && op != '!' && op != '&' && !view_selsize(win_view(EDIT))) + { + view_selectall(win_view(EDIT)); + } + char* input = view_getstr(win_view(EDIT)); + size_t len = (input ? strlen(input) : 0); + View *tags = win_view(TAGS), *edit = win_view(EDIT), *curr = win_view(FOCUSED); + + /* execute the job */ + if (op == '!' || op == '&') + { + free(input); + if (op == '&') + { + xpty_run(win_view(EDIT), execcmd); + } + else + { + job_start(execcmd, NULL, 0, NULL); + } + } + else if (op == '>') { - xpty_run(win_view(EDIT), execcmd); + job_start(execcmd, input, len, tags); + } + else if (op == '|' || op == ':') + { + job_start(execcmd, input, len, edit); } else { - job_start(execcmd, NULL, 0, NULL); + job_start(execcmd, input, len, (op != '<' ? curr : edit)); } } - else if (op == '>') - { - job_start(execcmd, input, len, tags); - } - else if (op == '|' || op == ':') - { - job_start(execcmd, input, len, edit); - } - else - { - job_start(execcmd, input, len, (op != '<' ? curr : edit)); - } } static void exec(char* cmd, char* arg) @@ -770,6 +777,11 @@ static KeyBinding* Bindings = (KeyBinding[]){ { .mods = ModCtrl, .key = ' ', .fn = complete }, { .mods = ModCtrl|ModShift, .key = ' ', .fn = fcomplete }, + /* xpty commands */ + { .mods = ModCtrl|ModShift, .key = 'c', .fn = xpty_rawsend, .arg = "\x03" }, + { .mods = ModCtrl|ModShift, .key = 'd', .fn = xpty_rawsend, .arg = "\x04" }, + { .mods = ModCtrl|ModShift, .key = 'z', .fn = xpty_rawsend, .arg = "\x1A" }, + { 0, 0, 0, 0 } };