tweaks: rename a variable, to better match its task

The 'statusbar_x' variable does not refer to a position in the status
bar, but to a position in the answer that is currently being typed at
the prompt.  So... let's call it 'typing_x', for lots of contrast.
master
Benno Schulenberg 2018-07-11 10:55:59 +02:00
parent aea54276b6
commit 18f13c3a75
1 changed files with 49 additions and 49 deletions

View File

@ -25,7 +25,7 @@
static char *prompt = NULL;
/* The prompt string used for statusbar questions. */
static size_t statusbar_x = HIGHEST_POSITIVE;
static size_t typing_x = HIGHEST_POSITIVE;
/* The cursor position in answer. */
#ifdef ENABLE_MOUSE
@ -41,7 +41,7 @@ int do_statusbar_mouse(void)
/* Move to where the click occurred. */
if (click_row == 0 && click_col >= start_col)
statusbar_x = actual_x(answer,
typing_x = actual_x(answer,
get_statusbar_page_start(start_col, start_col +
statusbar_xplustabs()) + click_col - start_col);
}
@ -208,11 +208,11 @@ void do_statusbar_output(int *the_input, size_t input_len,
/* Insert the typed character into the existing answer string. */
answer = charealloc(answer, strlen(answer) + char_len + 1);
charmove(answer + statusbar_x + char_len, answer + statusbar_x,
strlen(answer) - statusbar_x + 1);
strncpy(answer + statusbar_x, onechar, char_len);
charmove(answer + typing_x + char_len, answer + typing_x,
strlen(answer) - typing_x + 1);
strncpy(answer + typing_x, onechar, char_len);
statusbar_x += char_len;
typing_x += char_len;
}
free(output);
@ -221,45 +221,45 @@ void do_statusbar_output(int *the_input, size_t input_len,
/* Move to the beginning of the answer. */
void do_statusbar_home(void)
{
statusbar_x = 0;
typing_x = 0;
}
/* Move to the end of the answer. */
void do_statusbar_end(void)
{
statusbar_x = strlen(answer);
typing_x = strlen(answer);
}
/* Move left one character. */
void do_statusbar_left(void)
{
if (statusbar_x > 0)
statusbar_x = move_mbleft(answer, statusbar_x);
if (typing_x > 0)
typing_x = move_mbleft(answer, typing_x);
}
/* Move right one character. */
void do_statusbar_right(void)
{
if (answer[statusbar_x] != '\0')
statusbar_x = move_mbright(answer, statusbar_x);
if (answer[typing_x] != '\0')
typing_x = move_mbright(answer, typing_x);
}
/* Delete one character. */
void do_statusbar_delete(void)
{
if (answer[statusbar_x] != '\0') {
int char_len = parse_mbchar(answer + statusbar_x, NULL, NULL);
if (answer[typing_x] != '\0') {
int char_len = parse_mbchar(answer + typing_x, NULL, NULL);
charmove(answer + statusbar_x, answer + statusbar_x + char_len,
strlen(answer) - statusbar_x - char_len + 1);
charmove(answer + typing_x, answer + typing_x + char_len,
strlen(answer) - typing_x - char_len + 1);
}
}
/* Backspace over one character. */
void do_statusbar_backspace(void)
{
if (statusbar_x > 0) {
statusbar_x = move_mbleft(answer, statusbar_x);
if (typing_x > 0) {
typing_x = move_mbleft(answer, typing_x);
do_statusbar_delete();
}
}
@ -268,34 +268,34 @@ void do_statusbar_backspace(void)
void do_statusbar_cut_text(void)
{
if (!ISSET(CUT_FROM_CURSOR))
statusbar_x = 0;
typing_x = 0;
answer[statusbar_x] = '\0';
answer[typing_x] = '\0';
}
#ifndef NANO_TINY
/* Move to the next word in the answer. */
void do_statusbar_next_word(void)
{
bool seen_space = !is_word_mbchar(answer + statusbar_x, FALSE);
bool seen_space = !is_word_mbchar(answer + typing_x, FALSE);
bool seen_word = !seen_space;
/* Move forward until we reach either the end or the start of a word,
* depending on whether the AFTER_ENDS flag is set or not. */
while (answer[statusbar_x] != '\0') {
statusbar_x = move_mbright(answer, statusbar_x);
while (answer[typing_x] != '\0') {
typing_x = move_mbright(answer, typing_x);
if (ISSET(AFTER_ENDS)) {
/* If this is a word character, continue; else it's a separator,
* and if we've already seen a word, then it's a word end. */
if (is_word_mbchar(answer + statusbar_x, FALSE))
if (is_word_mbchar(answer + typing_x, FALSE))
seen_word = TRUE;
else if (seen_word)
break;
} else {
/* If this is not a word character, then it's a separator; else
* if we've already seen a separator, then it's a word start. */
if (!is_word_mbchar(answer + statusbar_x, FALSE))
if (!is_word_mbchar(answer + typing_x, FALSE))
seen_space = TRUE;
else if (seen_space)
break;
@ -309,10 +309,10 @@ void do_statusbar_prev_word(void)
bool seen_a_word = FALSE, step_forward = FALSE;
/* Move backward until we pass over the start of a word. */
while (statusbar_x != 0) {
statusbar_x = move_mbleft(answer, statusbar_x);
while (typing_x != 0) {
typing_x = move_mbleft(answer, typing_x);
if (is_word_mbchar(answer + statusbar_x, FALSE))
if (is_word_mbchar(answer + typing_x, FALSE))
seen_a_word = TRUE;
else if (seen_a_word) {
/* This is space now: we've overshot the start of the word. */
@ -323,7 +323,7 @@ void do_statusbar_prev_word(void)
if (step_forward)
/* Move one character forward again to sit on the start of the word. */
statusbar_x = move_mbright(answer, statusbar_x);
typing_x = move_mbright(answer, typing_x);
}
#endif /* !NANO_TINY */
@ -343,7 +343,7 @@ void do_statusbar_verbatim_input(void)
/* Return the zero-based column position of the cursor in the answer. */
size_t statusbar_xplustabs(void)
{
return strnlenpt(answer, statusbar_x);
return strnlenpt(answer, typing_x);
}
/* Paste the first line of the cutbuffer into the current answer. */
@ -354,13 +354,13 @@ void do_statusbar_uncut_text(void)
/* Concatenate: the current answer before the cursor, the first line
* of the cutbuffer, plus the rest of the current answer. */
strncpy(fusion, answer, statusbar_x);
strncpy(fusion + statusbar_x, cutbuffer->data, pastelen);
strcpy(fusion + statusbar_x + pastelen, answer + statusbar_x);
strncpy(fusion, answer, typing_x);
strncpy(fusion + typing_x, cutbuffer->data, pastelen);
strcpy(fusion + typing_x + pastelen, answer + typing_x);
free(answer);
answer = fusion;
statusbar_x += pastelen;
typing_x += pastelen;
}
/* Return the column number of the first character of the answer that is
@ -380,7 +380,7 @@ size_t get_statusbar_page_start(size_t base, size_t column)
/* Reinitialize the cursor position in the answer. */
void reinit_statusbar_x(void)
{
statusbar_x = HIGHEST_POSITIVE;
typing_x = HIGHEST_POSITIVE;
}
/* Redraw the promptbar and place the cursor at the right spot. */
@ -390,7 +390,7 @@ void draw_the_promptbar(void)
size_t the_page, end_page, column;
char *expanded;
the_page = get_statusbar_page_start(base, base + strnlenpt(answer, statusbar_x));
the_page = get_statusbar_page_start(base, base + strnlenpt(answer, typing_x));
end_page = get_statusbar_page_start(base, base + strlenpt(answer) - 1);
/* Color the promptbar over its full width. */
@ -413,7 +413,7 @@ void draw_the_promptbar(void)
wmove(bottomwin, 0, 0);
wrefresh(bottomwin);
/* Place the cursor at statusbar_x in the answer. */
/* Place the cursor at typing_x in the answer. */
column = base + statusbar_xplustabs();
wmove(bottomwin, 0, column - get_statusbar_page_start(base, column));
wnoutrefresh(bottomwin);
@ -425,13 +425,13 @@ 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--;
if (typing_x > 0)
typing_x--;
} else {
answer = charealloc(answer, strlen(answer) + 2);
charmove(answer + 1, answer, strlen(answer) + 1);
answer[0] = '|';
statusbar_x++;
typing_x++;
}
}
#endif
@ -463,8 +463,8 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabs,
#endif
#endif /* ENABLE_HISTORIES */
if (statusbar_x > strlen(answer))
statusbar_x = strlen(answer);
if (typing_x > strlen(answer))
typing_x = strlen(answer);
while (TRUE) {
draw_the_promptbar();
@ -501,12 +501,12 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabs,
if (complete_len > 0) {
answer = get_history_completion(history_list,
answer, complete_len);
statusbar_x = strlen(answer);
typing_x = strlen(answer);
}
} else
#endif
if (allow_tabs)
answer = input_tab(answer, allow_files, &statusbar_x,
answer = input_tab(answer, allow_files, &typing_x,
&tabbed, refresh_func, listed);
} else
#endif /* ENABLE_TABCOMP */
@ -522,7 +522,7 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabs,
* answer. If there is no older search, don't do anything. */
if ((history = get_history_older(history_list)) != NULL) {
answer = mallocstrcpy(answer, history);
statusbar_x = strlen(answer);
typing_x = strlen(answer);
}
/* This key has a shortcut-list entry when it's used to
@ -537,7 +537,7 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabs,
* answer. If there is no newer search, don't do anything. */
if ((history = get_history_newer(history_list)) != NULL) {
answer = mallocstrcpy(answer, history);
statusbar_x = strlen(answer);
typing_x = strlen(answer);
}
/* If, after scrolling down, we're at the bottom of the
@ -546,7 +546,7 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabs,
if ((*history_list)->next == NULL &&
*answer == '\0' && magichistory != NULL) {
answer = mallocstrcpy(answer, magichistory);
statusbar_x = strlen(answer);
typing_x = strlen(answer);
}
/* This key has a shortcut-list entry when it's used to
@ -609,7 +609,7 @@ int do_prompt(bool allow_tabs, bool allow_files,
functionptrtype func = NULL;
bool listed = FALSE;
/* Save a possible current statusbar x position and prompt. */
size_t was_statusbar_x = statusbar_x;
size_t was_typing_x = typing_x;
char *saved_prompt = prompt;
bottombars(menu);
@ -640,7 +640,7 @@ int do_prompt(bool allow_tabs, bool allow_files,
/* If we're done with this prompt, restore the x position to what
* it was at a possible previous prompt. */
if (func == do_cancel || func == do_enter)
statusbar_x = was_statusbar_x;
typing_x = was_typing_x;
/* If we left the prompt via Cancel or Enter, set the return value
* properly. */