diff options
author | Phil Jones <philj56@gmail.com> | 2022-12-01 20:24:35 +0000 |
---|---|---|
committer | Phil Jones <philj56@gmail.com> | 2022-12-01 20:24:35 +0000 |
commit | fff5211d2776185348d6b813f2a16cedd5f485d0 (patch) | |
tree | 2a4c7f38491e3168c14db4c6fc633210950cbd04 | |
parent | dd36bf1c53216e1828d136cb735d65816575571f (diff) |
Add --ascii-input option.
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | completions/tofi | 1 | ||||
-rw-r--r-- | doc/config | 5 | ||||
-rw-r--r-- | doc/tofi.5.md | 8 | ||||
-rw-r--r-- | doc/tofi.5.scd | 7 | ||||
-rw-r--r-- | src/config.c | 5 | ||||
-rw-r--r-- | src/main.c | 16 | ||||
-rw-r--r-- | src/tofi.h | 1 |
8 files changed, 45 insertions, 3 deletions
@@ -181,6 +181,11 @@ In roughly descending order, the most important options for performance are: sharpness, but your mileage may vary. This option has no effect if a path to a font file hasn't been passed to `--font`. +* `--ascii-input` - Proper Unicode handling is slower than plain ASCII - on the + order of a few ms for ~40 kB of input. Specifying `--ascii-input true` will + disable some of this handling, speeding up tofi's startup, but searching for + non-ASCII characters may not work properly. + * `--late-keyboard-init` - The last avoidable thing that slows down startup is initialisation of the keyboard. This only takes 1-2ms on my laptop, but up to 60ms on a Raspberry Pi Zero 2 W. Passing this option will delay keyboard diff --git a/completions/tofi b/completions/tofi index 328f7dc..d871db1 100644 --- a/completions/tofi +++ b/completions/tofi @@ -79,6 +79,7 @@ _tofi() --hint-font --late-keyboard-init --multi-instance + --ascii-input ) case "${prev}" in @@ -255,6 +255,11 @@ # from running simultaneously. multi-instance = false + # Assume input is plain ASCII, and disable some Unicode handling + # functions. This is faster, but means e.g. a search for "e" will not + # match "é". + ascii-input = false + # ### Inclusion # diff --git a/doc/tofi.5.md b/doc/tofi.5.md index e8f3c49..622858f 100644 --- a/doc/tofi.5.md +++ b/doc/tofi.5.md @@ -137,6 +137,14 @@ options. > > Default: false +**ascii-input**=*true\|false* + +> Assume input is plain ASCII, and disable some Unicode handling +> functions. This is faster, but means e.g. a search for "e" will not +> match "é". +> +> Default: false + # STYLE OPTIONS **font**=*font* diff --git a/doc/tofi.5.scd b/doc/tofi.5.scd index 72be59e..4dde4d6 100644 --- a/doc/tofi.5.scd +++ b/doc/tofi.5.scd @@ -118,6 +118,13 @@ options. Default: false +*ascii-input*=_true|false_ + Assume input is plain ASCII, and disable some Unicode handling + functions. This is faster, but means e.g. a search for "e" will not + match "é". + + Default: false + # STYLE OPTIONS *font*=_font_ diff --git a/src/config.c b/src/config.c index 83321ed..0cfd566 100644 --- a/src/config.c +++ b/src/config.c @@ -686,6 +686,11 @@ bool parse_option(struct tofi *tofi, const char *filename, size_t lineno, const if (!err) { tofi->multiple_instance = val; } + } else if (strcasecmp(option, "ascii-input") == 0) { + bool val = parse_bool(filename, lineno, value, &err); + if (!err) { + tofi->ascii_input = val; + } } else if (strcasecmp(option, "late-keyboard-init") == 0) { bool val = parse_bool(filename, lineno, value, &err); if (!err) { @@ -48,7 +48,7 @@ static uint32_t gettime_ms() { /* Read all of stdin into a buffer. */ -static char *read_stdin() { +static char *read_stdin(bool normalize) { const size_t block_size = BUFSIZ; size_t num_blocks = 1; size_t buf_size = block_size; @@ -66,12 +66,21 @@ static char *read_stdin() { stdin); if (bytes_read != block_size) { if (!feof(stdin) && ferror(stdin)) { - log_error("Error reading stdin\n"); + log_error("Error reading stdin.\n"); } buf[block * block_size + bytes_read] = '\0'; break; } } + if (normalize) { + if (utf8_validate(buf)) { + char *tmp = utf8_normalize(buf); + free(buf); + buf = tmp; + } else { + log_error("Invalid UTF-8 in stdin.\n"); + } + } return buf; } @@ -875,6 +884,7 @@ const struct option long_options[] = { {"terminal", required_argument, NULL, 0}, {"hint-font", required_argument, NULL, 0}, {"multi-instance", required_argument, NULL, 0}, + {"ascii-input", required_argument, NULL, 0}, {"output", required_argument, NULL, 0}, {"scale", required_argument, NULL, 0}, {"late-keyboard-init", optional_argument, NULL, 'k'}, @@ -1360,7 +1370,7 @@ int main(int argc, char *argv[]) log_debug("App list generated.\n"); } else { log_debug("Reading stdin.\n"); - char *buf = read_stdin(); + char *buf = read_stdin(!tofi.ascii_input); tofi.window.entry.command_buffer = buf; tofi.window.entry.commands = string_ref_vec_from_buffer(buf); if (tofi.use_history) { @@ -86,6 +86,7 @@ struct tofi { /* Options */ uint32_t anchor; + bool ascii_input; bool hide_cursor; bool use_history; bool use_scale; |