display: correctly trim an overshooting character from a prompt answer
Tell display_string() explicitly when we're at a prompt, instead of letting it glean this from the current menu not being MMAIN, which fails in some circumstances. This improves the fix for https://savannah.gnu.org/bugs/?55620, fixes https://savannah.gnu.org/bugs/?55680 in a better way, and fixes https://savannah.gnu.org/bugs/?55773.
Этот коммит содержится в:
родитель
de47b58dc1
Коммит
f13dd140eb
@ -529,7 +529,7 @@ void browser_refresh(void)
|
|||||||
/* Whether to put an ellipsis before the filename? We don't
|
/* Whether to put an ellipsis before the filename? We don't
|
||||||
* waste space on dots when there are fewer than 15 columns. */
|
* waste space on dots when there are fewer than 15 columns. */
|
||||||
char *disp = display_string(thename, dots ?
|
char *disp = display_string(thename, dots ?
|
||||||
namelen + infomaxlen + 4 - longest : 0, longest, FALSE);
|
namelen + infomaxlen + 4 - longest : 0, longest, FALSE, FALSE);
|
||||||
/* The filename (or a fragment of it) in displayable format.
|
/* The filename (or a fragment of it) in displayable format.
|
||||||
* When a fragment, account for dots plus one space padding. */
|
* When a fragment, account for dots plus one space padding. */
|
||||||
|
|
||||||
@ -667,7 +667,7 @@ int filesearch_init(bool forwards)
|
|||||||
|
|
||||||
/* If something was searched for before, show it between square brackets. */
|
/* If something was searched for before, show it between square brackets. */
|
||||||
if (*last_search != '\0') {
|
if (*last_search != '\0') {
|
||||||
char *disp = display_string(last_search, 0, COLS / 3, FALSE);
|
char *disp = display_string(last_search, 0, COLS / 3, FALSE, FALSE);
|
||||||
|
|
||||||
thedefault = charalloc(strlen(disp) + 7);
|
thedefault = charalloc(strlen(disp) + 7);
|
||||||
/* We use (COLS / 3) here because we need to see more on the line. */
|
/* We use (COLS / 3) here because we need to see more on the line. */
|
||||||
|
@ -359,13 +359,13 @@ int do_lockfile(const char *filename)
|
|||||||
postedname = mallocstrcpy(NULL, "_");
|
postedname = mallocstrcpy(NULL, "_");
|
||||||
else if (room < strlenpt(filename)) {
|
else if (room < strlenpt(filename)) {
|
||||||
char *fragment = display_string(filename,
|
char *fragment = display_string(filename,
|
||||||
strlenpt(filename) - room + 3, room, FALSE);
|
strlenpt(filename) - room + 3, room, FALSE, FALSE);
|
||||||
postedname = charalloc(strlen(fragment) + 4);
|
postedname = charalloc(strlen(fragment) + 4);
|
||||||
strcpy(postedname, "...");
|
strcpy(postedname, "...");
|
||||||
strcat(postedname, fragment);
|
strcat(postedname, fragment);
|
||||||
free(fragment);
|
free(fragment);
|
||||||
} else
|
} else
|
||||||
postedname = display_string(filename, 0, room, FALSE);
|
postedname = display_string(filename, 0, room, FALSE, FALSE);
|
||||||
|
|
||||||
/* Allow extra space for username (14), program name (8), PID (8),
|
/* Allow extra space for username (14), program name (8), PID (8),
|
||||||
* and terminating \0 (1), minus the %s (2) for the file name. */
|
* and terminating \0 (1), minus the %s (2) for the file name. */
|
||||||
@ -2256,7 +2256,7 @@ int do_writeout(bool exiting, bool withprompt)
|
|||||||
if (name_exists) {
|
if (name_exists) {
|
||||||
char *question = _("File \"%s\" exists; OVERWRITE? ");
|
char *question = _("File \"%s\" exists; OVERWRITE? ");
|
||||||
char *name = display_string(answer, 0,
|
char *name = display_string(answer, 0,
|
||||||
COLS - strlenpt(question) + 1, FALSE);
|
COLS - strlenpt(question) + 1, FALSE, FALSE);
|
||||||
char *message = charalloc(strlen(question) +
|
char *message = charalloc(strlen(question) +
|
||||||
strlen(name) + 1);
|
strlen(name) + 1);
|
||||||
|
|
||||||
@ -2704,7 +2704,7 @@ char *input_tab(char *buf, bool allow_files, size_t *place,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
disp = display_string(matches[match], 0, longest_name, FALSE);
|
disp = display_string(matches[match], 0, longest_name, FALSE, FALSE);
|
||||||
waddstr(edit, disp);
|
waddstr(edit, disp);
|
||||||
free(disp);
|
free(disp);
|
||||||
|
|
||||||
|
@ -400,7 +400,7 @@ void draw_the_promptbar(void)
|
|||||||
waddch(bottomwin, ':');
|
waddch(bottomwin, ':');
|
||||||
waddch(bottomwin, (the_page == 0) ? ' ' : '<');
|
waddch(bottomwin, (the_page == 0) ? ' ' : '<');
|
||||||
|
|
||||||
expanded = display_string(answer, the_page, COLS - base, FALSE);
|
expanded = display_string(answer, the_page, COLS - base, FALSE, TRUE);
|
||||||
waddstr(bottomwin, expanded);
|
waddstr(bottomwin, expanded);
|
||||||
free(expanded);
|
free(expanded);
|
||||||
|
|
||||||
|
@ -618,7 +618,8 @@ void blank_statusbar(void);
|
|||||||
void wipe_statusbar(void);
|
void wipe_statusbar(void);
|
||||||
void blank_bottombars(void);
|
void blank_bottombars(void);
|
||||||
void check_statusblank(void);
|
void check_statusblank(void);
|
||||||
char *display_string(const char *buf, size_t column, size_t span, bool isdata);
|
char *display_string(const char *buf, size_t column, size_t span,
|
||||||
|
bool isdata, bool isprompt);
|
||||||
void titlebar(const char *path);
|
void titlebar(const char *path);
|
||||||
void statusbar(const char *msg);
|
void statusbar(const char *msg);
|
||||||
void warn_and_shortly_pause(const char *msg);
|
void warn_and_shortly_pause(const char *msg);
|
||||||
|
@ -83,7 +83,7 @@ void search_init(bool replacing, bool keep_the_answer)
|
|||||||
|
|
||||||
/* If something was searched for earlier, include it in the prompt. */
|
/* If something was searched for earlier, include it in the prompt. */
|
||||||
if (*last_search != '\0') {
|
if (*last_search != '\0') {
|
||||||
char *disp = display_string(last_search, 0, COLS / 3, FALSE);
|
char *disp = display_string(last_search, 0, COLS / 3, FALSE, FALSE);
|
||||||
|
|
||||||
thedefault = charalloc(strlen(disp) + 7);
|
thedefault = charalloc(strlen(disp) + 7);
|
||||||
/* We use (COLS / 3) here because we need to see more on the line. */
|
/* We use (COLS / 3) here because we need to see more on the line. */
|
||||||
@ -388,7 +388,7 @@ void do_findnext(void)
|
|||||||
/* Report on the status bar that the given string was not found. */
|
/* Report on the status bar that the given string was not found. */
|
||||||
void not_found_msg(const char *str)
|
void not_found_msg(const char *str)
|
||||||
{
|
{
|
||||||
char *disp = display_string(str, 0, (COLS / 2) + 1, FALSE);
|
char *disp = display_string(str, 0, (COLS / 2) + 1, FALSE, FALSE);
|
||||||
size_t numchars = actual_x(disp, strnlenpt(disp, COLS / 2));
|
size_t numchars = actual_x(disp, strnlenpt(disp, COLS / 2));
|
||||||
|
|
||||||
statusline(HUSH, _("\"%.*s%s\" not found"), numchars, disp,
|
statusline(HUSH, _("\"%.*s%s\" not found"), numchars, disp,
|
||||||
@ -579,7 +579,6 @@ ssize_t do_replace_loop(const char *needle, bool whole_word_only,
|
|||||||
light_from_col = xplustabs();
|
light_from_col = xplustabs();
|
||||||
light_to_col = strnlenpt(openfile->current->data,
|
light_to_col = strnlenpt(openfile->current->data,
|
||||||
openfile->current_x + match_len);
|
openfile->current_x + match_len);
|
||||||
currmenu = MMAIN;
|
|
||||||
|
|
||||||
/* Refresh the edit window, scrolling it if necessary. */
|
/* Refresh the edit window, scrolling it if necessary. */
|
||||||
edit_refresh();
|
edit_refresh();
|
||||||
|
@ -2203,7 +2203,6 @@ bool fix_spello(const char *word)
|
|||||||
filestruct *saved_mark = openfile->mark;
|
filestruct *saved_mark = openfile->mark;
|
||||||
openfile->mark = NULL;
|
openfile->mark = NULL;
|
||||||
#endif
|
#endif
|
||||||
currmenu = MMAIN;
|
|
||||||
edit_refresh();
|
edit_refresh();
|
||||||
|
|
||||||
/* Let the user supply a correctly spelled alternative. */
|
/* Let the user supply a correctly spelled alternative. */
|
||||||
|
24
src/winio.c
24
src/winio.c
@ -1863,8 +1863,11 @@ void check_statusblank(void)
|
|||||||
* at most span columns. column is zero-based, and span is one-based, so
|
* at most span columns. column is zero-based, and span is one-based, so
|
||||||
* span == 0 means you get "" returned. The returned string is dynamically
|
* span == 0 means you get "" returned. The returned string is dynamically
|
||||||
* allocated, and should be freed. If isdata is TRUE, the caller might put
|
* allocated, and should be freed. If isdata is TRUE, the caller might put
|
||||||
* "<" at the beginning or ">" at the end of the line if it's too long. */
|
* "<" at the beginning or ">" at the end of the line if it's too long. If
|
||||||
char *display_string(const char *buf, size_t column, size_t span, bool isdata)
|
* isprompt is TRUE, the caller might put ">" at the end of the line if it's
|
||||||
|
* too long. */
|
||||||
|
char *display_string(const char *buf, size_t column, size_t span,
|
||||||
|
bool isdata, bool isprompt)
|
||||||
{
|
{
|
||||||
size_t start_index = actual_x(buf, column);
|
size_t start_index = actual_x(buf, column);
|
||||||
/* The index of the first character that the caller wishes to show. */
|
/* The index of the first character that the caller wishes to show. */
|
||||||
@ -1989,7 +1992,7 @@ char *display_string(const char *buf, size_t column, size_t span, bool isdata)
|
|||||||
|
|
||||||
/* If there is more text than can be shown, make room for the ">". */
|
/* If there is more text than can be shown, make room for the ">". */
|
||||||
if ((*buf != '\0' || column > beyond) &&
|
if ((*buf != '\0' || column > beyond) &&
|
||||||
(currmenu != MMAIN || (isdata && !ISSET(SOFTWRAP)))) {
|
(isprompt || (isdata && !ISSET(SOFTWRAP)))) {
|
||||||
do {
|
do {
|
||||||
index = move_mbleft(converted, index);
|
index = move_mbleft(converted, index);
|
||||||
} while (mbwidth(converted + index) == 0);
|
} while (mbwidth(converted + index) == 0);
|
||||||
@ -2143,13 +2146,13 @@ void titlebar(const char *path)
|
|||||||
|
|
||||||
/* Print the full path if there's room; otherwise, dottify it. */
|
/* Print the full path if there's room; otherwise, dottify it. */
|
||||||
if (pathlen + pluglen + statelen <= COLS) {
|
if (pathlen + pluglen + statelen <= COLS) {
|
||||||
caption = display_string(path, 0, pathlen, FALSE);
|
caption = display_string(path, 0, pathlen, FALSE, FALSE);
|
||||||
waddstr(topwin, caption);
|
waddstr(topwin, caption);
|
||||||
free(caption);
|
free(caption);
|
||||||
} else if (5 + statelen <= COLS) {
|
} else if (5 + statelen <= COLS) {
|
||||||
waddstr(topwin, "...");
|
waddstr(topwin, "...");
|
||||||
caption = display_string(path, 3 + pathlen - COLS + statelen,
|
caption = display_string(path, 3 + pathlen - COLS + statelen,
|
||||||
COLS - statelen, FALSE);
|
COLS - statelen, FALSE, FALSE);
|
||||||
waddstr(topwin, caption);
|
waddstr(topwin, caption);
|
||||||
free(caption);
|
free(caption);
|
||||||
}
|
}
|
||||||
@ -2240,7 +2243,7 @@ void statusline(message_type importance, const char *msg, ...)
|
|||||||
compound = charalloc(MAXCHARLEN * (COLS + 1));
|
compound = charalloc(MAXCHARLEN * (COLS + 1));
|
||||||
vsnprintf(compound, MAXCHARLEN * (COLS + 1), msg, ap);
|
vsnprintf(compound, MAXCHARLEN * (COLS + 1), msg, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
message = display_string(compound, 0, COLS, FALSE);
|
message = display_string(compound, 0, COLS, FALSE, FALSE);
|
||||||
free(compound);
|
free(compound);
|
||||||
|
|
||||||
start_col = (COLS - strlenpt(message)) / 2;
|
start_col = (COLS - strlenpt(message)) / 2;
|
||||||
@ -2772,7 +2775,7 @@ int update_line(filestruct *fileptr, size_t index)
|
|||||||
|
|
||||||
/* Expand the line, replacing tabs with spaces, and control
|
/* Expand the line, replacing tabs with spaces, and control
|
||||||
* characters with their displayed forms. */
|
* characters with their displayed forms. */
|
||||||
converted = display_string(fileptr->data, from_col, editwincols, TRUE);
|
converted = display_string(fileptr->data, from_col, editwincols, TRUE, FALSE);
|
||||||
|
|
||||||
/* Draw the line. */
|
/* Draw the line. */
|
||||||
edit_draw(fileptr, converted, row, from_col);
|
edit_draw(fileptr, converted, row, from_col);
|
||||||
@ -2842,7 +2845,8 @@ int update_softwrapped_line(filestruct *fileptr)
|
|||||||
blank_row(edit, row, 0, COLS);
|
blank_row(edit, row, 0, COLS);
|
||||||
|
|
||||||
/* Convert the chunk to its displayable form and draw it. */
|
/* Convert the chunk to its displayable form and draw it. */
|
||||||
converted = display_string(fileptr->data, from_col, to_col - from_col, TRUE);
|
converted = display_string(fileptr->data, from_col, to_col - from_col,
|
||||||
|
TRUE, FALSE);
|
||||||
edit_draw(fileptr, converted, row++, from_col);
|
edit_draw(fileptr, converted, row++, from_col);
|
||||||
free(converted);
|
free(converted);
|
||||||
|
|
||||||
@ -3443,7 +3447,7 @@ void spotlight(size_t from_col, size_t to_col)
|
|||||||
to_col++;
|
to_col++;
|
||||||
} else
|
} else
|
||||||
word = display_string(openfile->current->data, from_col,
|
word = display_string(openfile->current->data, from_col,
|
||||||
to_col - from_col, FALSE);
|
to_col - from_col, FALSE, FALSE);
|
||||||
|
|
||||||
word_span = strlenpt(word);
|
word_span = strlenpt(word);
|
||||||
|
|
||||||
@ -3496,7 +3500,7 @@ void spotlight_softwrapped(size_t from_col, size_t to_col)
|
|||||||
break_col++;
|
break_col++;
|
||||||
} else
|
} else
|
||||||
word = display_string(openfile->current->data, from_col,
|
word = display_string(openfile->current->data, from_col,
|
||||||
break_col - from_col, FALSE);
|
break_col - from_col, FALSE, FALSE);
|
||||||
|
|
||||||
wattron(edit, interface_color_pair[SELECTED_TEXT]);
|
wattron(edit, interface_color_pair[SELECTED_TEXT]);
|
||||||
|
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user