prompt: concentrate manipulations of 'statusbar_x' into a single file

master
Benno Schulenberg 2018-07-11 10:07:33 +02:00
parent e6c6a72ee8
commit 0c455155ad
4 changed files with 21 additions and 15 deletions

View File

@ -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;
}

View File

@ -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(). */

View File

@ -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,

View File

@ -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, ...);