summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Jones <philj56@gmail.com>2022-08-20 10:16:48 +0100
committerPhil Jones <philj56@gmail.com>2022-08-20 10:16:48 +0100
commit7d9a1c9b401e83ea642892535c399f906b2defa6 (patch)
tree8eb6d1337edeb7d1f8e431cc42e78b7690c6782d
parentea64fc43a6a321fcc7417f35d5ce50a2c7ee9d7e (diff)
Add Ctrl-u and Ctrl-w readline bindings.
Ctrl-u is just a whole line delete for now, as there's no sense of a cursor position in tofi (so the whole line is "left" of the cursor).
-rw-r--r--doc/tofi.1.md22
-rw-r--r--doc/tofi.1.scd6
-rw-r--r--src/main.c40
3 files changed, 58 insertions, 10 deletions
diff --git a/doc/tofi.1.md b/doc/tofi.1.md
index 8d3c960..afd507a 100644
--- a/doc/tofi.1.md
+++ b/doc/tofi.1.md
@@ -19,7 +19,7 @@ displays a graphical selection menu. When a selection is made, it is
printed to stdout.
When invoked via the name **tofi-run**, **tofi** will not accept items
-on stdin, instead presenting a list of executables in the user's $PATH.
+on stdin, instead presenting a list of executables in the user's \$PATH.
When invoked via the name **tofi-drun**, **tofi** will not accept items
on stdin, and will generate a list of applications from desktop files as
@@ -55,6 +55,14 @@ the form **--key=value**.
> Move the selection forward one entry.
+\<Ctrl\>-u
+
+> Delete line.
+
+\<Ctrl\>-w
+
+> Delete word.
+
\<Enter\>
> Confirm the current selection and quit.
@@ -69,24 +77,24 @@ the form **--key=value**.
> Example configuration file.
-*$XDG_CONFIG_HOME/tofi/config*
+*\$XDG_CONFIG_HOME/tofi/config*
> The default configuration file location.
-*$XDG_CACHE_HOME/tofi-compgen*
+*\$XDG_CACHE_HOME/tofi-compgen*
-> Cached list of executables under $PATH, regenerated as necessary.
+> Cached list of executables under \$PATH, regenerated as necessary.
-*$XDG_CACHE_HOME/tofi-drun*
+*\$XDG_CACHE_HOME/tofi-drun*
> Cached list of desktop applications, regenerated as necessary.
-*$XDG_STATE_HOME/tofi-history*
+*\$XDG_STATE_HOME/tofi-history*
> Numeric count of commands selected in **tofi-run**, to enable sorting
> results by run count.
-*$XDG_STATE_HOME/tofi-drun-history*
+*\$XDG_STATE_HOME/tofi-drun-history*
> Numeric count of commands selected in **tofi-drun**, to enable sorting
> results by run count.
diff --git a/doc/tofi.1.scd b/doc/tofi.1.scd
index 8b6618d..1de0922 100644
--- a/doc/tofi.1.scd
+++ b/doc/tofi.1.scd
@@ -50,6 +50,12 @@ All config file options described in *tofi*(5) are also accepted, in the form
<Down> | <Right> | <Ctrl>-j | <Tab>
Move the selection forward one entry.
+<Ctrl>-u
+ Delete line.
+
+<Ctrl>-w
+ Delete word.
+
<Enter>
Confirm the current selection and quit.
diff --git a/src/main.c b/src/main.c
index 7d861b4..9f244af 100644
--- a/src/main.c
+++ b/src/main.c
@@ -177,9 +177,26 @@ static void handle_keypress(struct tofi *tofi, xkb_keycode_t keycode)
string_vec_destroy(&tmp);
}
}
- } else if (entry->input_length > 0 && sym == XKB_KEY_BackSpace) {
- entry->input_length--;
- entry->input[entry->input_length] = L'\0';
+ } else if (entry->input_length > 0
+ && (sym == XKB_KEY_BackSpace
+ || (sym == XKB_KEY_w
+ && xkb_state_mod_name_is_active(
+ tofi->xkb_state,
+ XKB_MOD_NAME_CTRL,
+ XKB_STATE_MODS_EFFECTIVE))))
+ {
+ if (sym == XKB_KEY_BackSpace) {
+ entry->input_length--;
+ entry->input[entry->input_length] = L'\0';
+ } else {
+ while (entry->input_length > 0 && iswspace(entry->input[entry->input_length - 1])) {
+ entry->input_length--;
+ }
+ while (entry->input_length > 0 && !iswspace(entry->input[entry->input_length - 1])) {
+ entry->input_length--;
+ }
+ entry->input[entry->input_length] = L'\0';
+ }
const wchar_t *src = entry->input;
size_t siz = wcsrtombs(
entry->input_mb,
@@ -193,6 +210,23 @@ static void handle_keypress(struct tofi *tofi, xkb_keycode_t keycode)
} else {
entry->results = string_vec_filter(&entry->commands, entry->input_mb, tofi->fuzzy_match);
}
+ } else if (sym == XKB_KEY_u
+ && xkb_state_mod_name_is_active(
+ tofi->xkb_state,
+ XKB_MOD_NAME_CTRL,
+ XKB_STATE_MODS_EFFECTIVE)
+ )
+ {
+ entry->input_length = 0;
+ entry->input[0] = L'\0';
+ entry->input_mb_length = 0;
+ entry->input_mb[0] = '\0';
+ string_vec_destroy(&entry->results);
+ if (entry->drun) {
+ entry->results = desktop_vec_filter(&entry->apps, entry->input_mb, tofi->fuzzy_match);
+ } else {
+ entry->results = string_vec_filter(&entry->commands, entry->input_mb, tofi->fuzzy_match);
+ }
} else if (sym == XKB_KEY_Escape
|| (sym == XKB_KEY_c
&& xkb_state_mod_name_is_active(