nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit f012d54a1df0ef30be102fbe578db44cdb2ce072
parent 61dc2cab0b598a508ef17d8c880380058242ec9c
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Wed, 12 Feb 2020 16:58:12 +0100

tweaks: make prompt-bar input more similar to edit-buffer input

In preparation for the next commit.

Diffstat:
Msrc/prompt.c | 42++++++++++++++++++++++--------------------
Msrc/proto.h | 2+-
2 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/src/prompt.c b/src/prompt.c @@ -57,9 +57,9 @@ int do_statusbar_input(bool *finished) { int input; /* The character we read in. */ - static int *kbinput = NULL; + static char *puddle = NULL; /* The input buffer. */ - static size_t kbinput_len = 0; + static size_t depth = 0; /* The length of the input buffer. */ const keystruct *shortcut; @@ -95,20 +95,22 @@ int do_statusbar_input(bool *finished) beep(); else if (!ISSET(RESTRICTED) || currmenu != MWRITEFILE || openfile->filename[0] == '\0') { - kbinput_len++; - kbinput = (int *)nrealloc(kbinput, kbinput_len * sizeof(int)); - kbinput[kbinput_len - 1] = input; + puddle = charealloc(puddle, depth + 2); + puddle[depth++] = (char)input; } } /* If we got a shortcut, or if there aren't any other keystrokes waiting, * it's time to insert all characters in the input buffer (if not empty) * into the answer, and then clear the input buffer. */ - if ((shortcut || get_key_buffer_len() == 0) && kbinput != NULL) { - inject_into_answer(kbinput, kbinput_len); - kbinput_len = 0; - free(kbinput); - kbinput = NULL; + if ((shortcut || get_key_buffer_len() == 0) && puddle != NULL) { + puddle[depth] = '\0'; + + inject_into_answer(puddle, depth); + + free(puddle); + puddle = NULL; + depth = 0; } if (shortcut) { @@ -172,17 +174,11 @@ int do_statusbar_input(bool *finished) } /* The user typed input_len multibyte characters. Add them to the answer. */ -void inject_into_answer(int *the_input, size_t input_len) +void inject_into_answer(char *output, size_t input_len) { - char *output = charalloc(input_len + 1); char onechar[MAXCHARLEN]; size_t charlen, index = 0; - /* Copy the typed stuff so it can be treated. */ - for (size_t i = 0; i < input_len; i++) - output[i] = (char)the_input[i]; - output[input_len] = '\0'; - while (index < input_len) { /* Encode any NUL byte as 0x0A. */ if (output[index] == '\0') @@ -200,8 +196,6 @@ void inject_into_answer(int *the_input, size_t input_len) typing_x += charlen; index += charlen; } - - free(output); } /* Move to the beginning of the answer. */ @@ -317,12 +311,20 @@ void do_statusbar_prev_word(void) void do_statusbar_verbatim_input(void) { int *kbinput; + char *bytes; size_t count; kbinput = get_verbatim_kbinput(bottomwin, &count); - inject_into_answer(kbinput, count); + bytes = charalloc(count + 1); + + for (size_t i = 0; i < count; i++) + bytes[i] = (char)kbinput[i]; + bytes[count] = '\0'; + + inject_into_answer(bytes, count); + free(bytes); free(kbinput); } diff --git a/src/proto.h b/src/proto.h @@ -445,7 +445,7 @@ bool okay_for_view(const keystruct *shortcut); void inject(char *output, size_t output_len); /* Most functions in prompt.c. */ -void inject_into_answer(int *the_input, size_t input_len); +void inject_into_answer(char *output, size_t input_len); void do_statusbar_home(void); void do_statusbar_end(void); void do_statusbar_left(void);