dvtm

dynamic virtual terminal manager - with my changes
git clone https://pi.duncano.de/git/dvtm.git
Log | Files | Refs | README | LICENSE

commit f0f4aac71876d81d65f9674e1791cb9d1c0b329c
parent a505fcb892e05299fdea72aba87c1cfa5d5dec1d
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Tue,  3 Jan 2017 10:35:15 +0100

Simplify copy mode implementation

Always execute dvtm-editor(1) or dvtm-pager(1) upon MOD+e
and MOD+/ respectively.

Diffstat:
config.def.h | 20++------------------
dvtm.c | 46+++++++++++++---------------------------------
2 files changed, 15 insertions(+), 51 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -114,8 +114,8 @@ static KeyBinding bindings[] = { { { MOD, 'a', }, { togglerunall, { NULL } } }, { { MOD, CTRL('L'), }, { redraw, { NULL } } }, { { MOD, 'r', }, { redraw, { NULL } } }, - { { MOD, 'e', }, { copymode, { NULL } } }, - { { MOD, '/', }, { copymode, { "/" } } }, + { { MOD, 'e', }, { copymode, { "dvtm-editor" } } }, + { { MOD, '/', }, { copymode, { "dvtm-pager", "/" } } }, { { MOD, 'p', }, { paste, { NULL } } }, { { MOD, KEY_PPAGE, }, { scrollback, { "-1" } } }, { { MOD, KEY_NPAGE, }, { scrollback, { "1" } } }, @@ -204,19 +204,3 @@ static Action actions[] = { static char const * const keytable[] = { /* add your custom key escape sequences */ }; - -/* editor to use for copy mode. If neither of DVTM_EDITOR, EDITOR and PAGER is - * set the first entry is chosen. Otherwise the array is consulted for supported - * options. A %d in argv is replaced by the line number at which the file should - * be opened. If filter is true the editor is expected to work even if stdout is - * redirected (i.e. not a terminal). If color is true then color escape sequences - * are generated in the output. - */ -static Editor editors[] = { - { .name = "vis", .argv = { "vis", "+%d", "-", NULL }, .filter = true, .color = false }, - { .name = "sandy", .argv = { "sandy", "-d", "-", NULL }, .filter = true, .color = false }, - { .name = "dvtm-editor", .argv = { "dvtm-editor", "-", NULL }, .filter = true, .color = false }, - { .name = "vim", .argv = { "vim", "+%d", "-", NULL }, .filter = false, .color = false }, - { .name = "less", .argv = { "less", "-R", "+%d", NULL }, .filter = false, .color = true }, - { .name = "more", .argv = { "more", "+%d", NULL }, .filter = false, .color = false }, -}; diff --git a/dvtm.c b/dvtm.c @@ -1086,45 +1086,25 @@ create(const char *args[]) { static void copymode(const char *args[]) { - if (!sel || sel->editor) + if (!args || !args[0] || !sel || sel->editor) return; + + bool colored = strstr(args[0], "pager") != NULL; + if (!(sel->editor = vt_create(sel->h - sel->has_title_line, sel->w, 0))) return; - char *ed = getenv("DVTM_EDITOR"); - int *to = &sel->editor_fds[0], *from = NULL; + int *to = &sel->editor_fds[0]; + int *from = strstr(args[0], "editor") ? &sel->editor_fds[1] : NULL; sel->editor_fds[0] = sel->editor_fds[1] = -1; - if (!ed) - ed = getenv("EDITOR"); - if (!ed) - ed = getenv("PAGER"); - if (!ed) - ed = editors[0].name; - - const char **argv = (const char*[]){ ed, "-", NULL, NULL }; + const char *argv[3] = { args[0], NULL, NULL }; char argline[32]; - bool colored = false; - - for (unsigned int i = 0; i < LENGTH(editors); i++) { - if (!strcmp(editors[i].name, ed)) { - for (int j = 1; editors[i].argv[j]; j++) { - if (strstr(editors[i].argv[j], "%d")) { - int line = vt_content_start(sel->app); - snprintf(argline, sizeof(argline), "+%d", line); - argv[j] = argline; - } else { - argv[j] = editors[i].argv[j]; - } - } - if (editors[i].filter) - from = &sel->editor_fds[1]; - colored = editors[i].color; - break; - } - } + int line = vt_content_start(sel->app); + snprintf(argline, sizeof(argline), "+%d", line); + argv[1] = argline; - if (vt_forkpty(sel->editor, ed, argv, NULL, NULL, to, from) < 0) { + if (vt_forkpty(sel->editor, args[0], argv, NULL, NULL, to, from) < 0) { vt_destroy(sel->editor); sel->editor = NULL; return; @@ -1151,8 +1131,8 @@ copymode(const char *args[]) { sel->editor_fds[0] = -1; } - if (args[0]) - vt_write(sel->editor, args[0], strlen(args[0])); + if (args[1]) + vt_write(sel->editor, args[1], strlen(args[1])); } static void