From 0c455155ad02c3dc80a46bc2efa73cf2d63634a1 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 11 Jul 2018 10:07:33 +0200 Subject: [PATCH] prompt: concentrate manipulations of 'statusbar_x' into a single file --- src/files.c | 13 +------------ src/global.c | 2 -- src/prompt.c | 19 +++++++++++++++++++ src/proto.h | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/files.c b/src/files.c index 8cdf1959..d0b0d7cb 100644 --- a/src/files.c +++ b/src/files.c @@ -1112,18 +1112,7 @@ void do_insertfile(void) #endif #ifndef NANO_TINY if (func == flip_pipe) { - /* Remove or add the pipe character at the answer's head. */ - if (answer[0] == '|') { - charmove(answer, answer + 1, strlen(answer) + 1); - if (statusbar_x > 0) - statusbar_x--; - } else { - answer = charealloc(answer, strlen(answer) + 2); - charmove(answer + 1, answer, strlen(answer) + 1); - answer[0] = '|'; - statusbar_x++; - } - + add_or_remove_pipe_symbol_from_answer(); given = mallocstrcpy(given, answer); continue; } diff --git a/src/global.c b/src/global.c index fc5fad35..3c21ace1 100644 --- a/src/global.c +++ b/src/global.c @@ -152,8 +152,6 @@ char *word_chars = NULL; char *answer = NULL; /* The answer string used by the statusbar prompt. */ -size_t statusbar_x = HIGHEST_POSITIVE; - /* The cursor position in answer. */ ssize_t tabsize = -1; /* The width of a tab in spaces. The default is set in main(). */ diff --git a/src/prompt.c b/src/prompt.c index c7792a78..3ee95625 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -25,6 +25,8 @@ static char *prompt = NULL; /* The prompt string used for statusbar questions. */ +static size_t statusbar_x = HIGHEST_POSITIVE; + /* The cursor position in answer. */ #ifdef ENABLE_MOUSE /* Handle a mouse click on the statusbar prompt or the shortcut list. */ @@ -417,6 +419,23 @@ void update_the_statusbar(void) wnoutrefresh(bottomwin); } +#ifndef NANO_TINY +/* Remove or add the pipe character at the answer's head. */ +void add_or_remove_pipe_symbol_from_answer(void) +{ + if (answer[0] == '|') { + charmove(answer, answer + 1, strlen(answer) + 1); + if (statusbar_x > 0) + statusbar_x--; + } else { + answer = charealloc(answer, strlen(answer) + 2); + charmove(answer + 1, answer, strlen(answer) + 1); + answer[0] = '|'; + statusbar_x++; + } +} +#endif + /* Get a string of input at the statusbar prompt. */ functionptrtype acquire_an_answer(int *actual, bool allow_tabs, bool allow_files, bool *listed, filestruct **history_list, diff --git a/src/proto.h b/src/proto.h index 02c639ef..b957bcd2 100644 --- a/src/proto.h +++ b/src/proto.h @@ -124,7 +124,6 @@ extern char *quoteerr; extern char *word_chars; extern char *answer; -extern size_t statusbar_x; extern ssize_t tabsize; @@ -465,6 +464,7 @@ size_t statusbar_xplustabs(void); size_t get_statusbar_page_start(size_t start_col, size_t column); void reinit_statusbar_x(void); void update_the_statusbar(void); +void add_or_remove_pipe_symbol_from_answer(void); int do_prompt(bool allow_tabs, bool allow_files, int menu, const char *curranswer, filestruct **history_list, void (*refresh_func)(void), const char *msg, ...);