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);
}
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));
+}
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)
{ .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 }
};