fe

terminal file explorer and picker

git clone https://9o.is/git/fe.git

commit 1ab215102959e9cb22de7c0ca8056a19f08d78b1
parent b0cea28277733ea9961cb79bf12ed834409f3105
Author: Jul <jul@9o.is>
Date:   Tue, 20 Jan 2026 05:08:13 -0500

move keybindings to options_t

Diffstat:
Mconfig.def.h | 25++++++++++---------------
Moptions.h | 9+++++++++
Mtty_interface.c | 1+
Mtty_interface.h | 2+-
4 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -22,21 +22,6 @@ #define KEYTIMEOUT 25 -static const options_t default_options = { - .num_files = 25, - .tty_filename = "/dev/tty", - .sort_dir = 0, - .sort_icase = 0, - .sort_mtime = 0, - .show_hidden = 0, -}; - -typedef struct { - const char *key; - void (*action)(tty_interface_t *, const char *); - const char *argv; -} keybinding_t; - #define KEY(key) ((const char[]){key, '\0'}) #define KEY_CTRL(key) ((const char[]){((key) - ('@')), '\0'}) @@ -72,5 +57,15 @@ static const keybinding_t keybindings[] = { {"\x1b[201~", action_ignore, NULL}, {NULL, NULL, NULL}}; +static const options_t default_options = { + .num_files = 25, + .tty_filename = "/dev/tty", + .sort_dir = 0, + .sort_icase = 0, + .sort_mtime = 0, + .show_hidden = 0, + .keybindings = keybindings, +}; + #undef KEY_CTRL #undef KEY diff --git a/options.h b/options.h @@ -1,6 +1,14 @@ #ifndef OPTIONS_H #define OPTIONS_H OPTIONS_H +struct tty_interface; + +typedef struct { + const char *key; + void (*action)(struct tty_interface *, const char *); + const char *argv; +} keybinding_t; + typedef struct { unsigned int num_files; const char *tty_filename; @@ -10,6 +18,7 @@ typedef struct { int sort_icase; int sort_mtime; int show_hidden; + const keybinding_t *keybindings; } options_t; void options_parse(options_t *options, int argc, char *argv[]); diff --git a/tty_interface.c b/tty_interface.c @@ -96,6 +96,7 @@ static void handle_input(tty_interface_t *state, const char *s, int handle_ambig * middle of one (both can happen, because of Esc). */ int found_keybinding = -1; int in_middle = 0; + const keybinding_t *keybindings = state->options->keybindings; for (int i = 0; keybindings[i].key; i++) { if (!strcmp(input, keybindings[i].key)) found_keybinding = i; diff --git a/tty_interface.h b/tty_interface.h @@ -5,7 +5,7 @@ #include "options.h" #include "tty.h" -typedef struct { +typedef struct tty_interface { tty_t *tty; entries_t *entries; options_t *options;