]> git.mdlowis.com Git - projs/tide.git/commitdiff
added shortcuts for kill, eof, and intr
authorMichael D. Lowis <mike@mdlowis.com>
Thu, 21 Nov 2019 04:07:43 +0000 (23:07 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Thu, 21 Nov 2019 04:07:43 +0000 (23:07 -0500)
inc/xpty.h
src/lib/xpty.c
src/tide.c

index 442cc07df1f2a9f97b393e021802d6c9138ac8ff..c70315f3757c15d3e7d9dcf97512ad83f88b3663 100644 (file)
@@ -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);
index 07b60b49f0680c3b589c10bb6ea1974dce546bbc..c165d34dec9ee8fa9ba9d8a5bb872b445030fe81 100644 (file)
@@ -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));
+}
index 6332e95eeab895d9afb94aa3e17f647038fcaf0a..281f7ae8eca93f7d493cd43a723822350cdbf181 100644 (file)
@@ -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 }
 };