aboutsummaryrefslogtreecommitdiff
path: root/input.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-07-31 15:02:53 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-07-31 15:04:30 +0000
commit639a61abd86c7db3e47f2cd70fc16b7d6c6afaf4 (patch)
tree8693442620f98a0ba8e67dac03868cae62e86435 /input.c
parentinstall: tllist is a *build* dependency, not a *runtime* dependency (diff)
config: add 'pipe-selected' key binding
This works just like pipe-visible and pipe-scrollback, but pipes the user-selected text, if any, to the external tool. Closes #51
Diffstat (limited to 'input.c')
-rw-r--r--input.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/input.c b/input.c
index fcf79111..c3231a09 100644
--- a/input.c
+++ b/input.c
@@ -145,7 +145,8 @@ execute_binding(struct seat *seat, struct terminal *term,
break;
case BIND_ACTION_PIPE_SCROLLBACK:
- case BIND_ACTION_PIPE_VIEW: {
+ case BIND_ACTION_PIPE_VIEW:
+ case BIND_ACTION_PIPE_SELECTED: {
if (pipe_argv == NULL)
break;
@@ -171,9 +172,27 @@ execute_binding(struct seat *seat, struct terminal *term,
goto pipe_err;
}
- bool success = action == BIND_ACTION_PIPE_SCROLLBACK
- ? term_scrollback_to_text(term, &text, &len)
- : term_view_to_text(term, &text, &len);
+ bool success;
+ switch (action) {
+ case BIND_ACTION_PIPE_SCROLLBACK:
+ success = term_scrollback_to_text(term, &text, &len);
+ break;
+
+ case BIND_ACTION_PIPE_VIEW:
+ success = term_view_to_text(term, &text, &len);
+ break;
+
+ case BIND_ACTION_PIPE_SELECTED:
+ text = selection_to_text(term);
+ success = text != NULL;
+ len = text != NULL ? strlen(text) : 0;
+ break;
+
+ default:
+ assert(false);
+ success = false;
+ break;
+ }
if (!success)
goto pipe_err;