refactor nanoget_repaint() to split out the new function

get_statusbar_page_start(), the statusbar prompt's equivalent of
get_page_start(); also make sure that the minimum allowed terminal size
in columns is 4, as the statusbar prompt code relies on this assumption
and will crash otherwise


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3051 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2005-10-26 23:14:59 +00:00
parent b2bf101d0c
commit 3d12f0f53d
6 changed files with 53 additions and 34 deletions

View File

@ -5,6 +5,19 @@ CVS code -
is disabled when NANO_SMALL is defined. New functions
do_scroll_up() and do_scroll_down(); changes to
shortcut_init(). (DLR, suggested by Mike Frysinger)
- Since the statusbar prompt code needs at least 4 columns in
order to work properly, make that the minimum number of
columns nano requires to run, and remove assertions and code
that make use of a smaller number. Changes to window_init(),
nanoget_repaint(), titlebar(), statusbar(), and
get_page_start(). (DLR)
- nano.h:
- Readd MIN_EDITOR_COLS #define. (DLR)
- winio.c:
nanoget_repaint()
- Move the code to determine the statusbar equivalent of
get_page_start() into the new function
get_statusbar_page_start(). (DLR)
GNU nano 1.3.9 - 2005.10.23
- General:

View File

@ -634,7 +634,7 @@ void window_init(void)
{
/* If the screen height is too small, get out. */
editwinrows = LINES - 5 + no_more_space() + no_help();
if (editwinrows < MIN_EDITOR_ROWS)
if (COLS < MIN_EDITOR_COLS || editwinrows < MIN_EDITOR_ROWS)
die(_("Window size is too small for nano...\n"));
#ifndef DISABLE_WRAPJUSTIFY

View File

@ -522,7 +522,9 @@ typedef struct rcoption {
#define VIEW TRUE
#define NOVIEW FALSE
/* Minimum editor window rows required for nano to work correctly. */
/* Minimum editor window columns and rows required for nano to work
* correctly. */
#define MIN_EDITOR_COLS 4
#define MIN_EDITOR_ROWS 1
/* Default number of characters from end-of-line where text wrapping

View File

@ -632,6 +632,7 @@ bool do_statusbar_next_word(bool allow_punct);
bool do_statusbar_prev_word(bool allow_punct);
#endif
void do_statusbar_verbatim_input(bool *got_enter);
size_t get_statusbar_page_start(size_t start_col, size_t column);
size_t xplustabs(void);
size_t actual_x(const char *str, size_t xplus);
size_t strnlenpt(const char *buf, size_t size);

View File

@ -155,7 +155,7 @@ int search_init(bool replacing, bool use_answer)
/* We use (COLS / 3) here because we need to see more on the
* line. */
sprintf(buf, " [%s%s]", disp,
strlenpt(last_search) > COLS / 3 ? "..." : "");
(strlenpt(last_search) > COLS / 3) ? "..." : "");
free(disp);
} else
buf = mallocstrcpy(NULL, "");

View File

@ -2174,6 +2174,20 @@ void do_statusbar_verbatim_input(bool *got_enter)
free(output);
}
/* nano scrolls horizontally within a line in chunks. This function
* returns the column number of the first character displayed in the
* statusbar prompt when the cursor is at the given column with the
* prompt ending at start_col. Note that (0 <= column -
* get_statusbar_page_start(column) < COLS). */
size_t get_statusbar_page_start(size_t start_col, size_t column)
{
if (column == start_col || column < COLS - 1)
return 0;
else
return column - start_col - (column - start_col) % (COLS -
start_col - 1);
}
/* Return the placewewant associated with current_x, i.e, the zero-based
* column position of the cursor. The value will be no smaller than
* current_x. */
@ -2453,39 +2467,33 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
return converted;
}
/* Repaint the statusbar when getting a character in nanogetstr(). buf
* should be no longer than max(0, COLS - 4).
*
* Note that we must turn on A_REVERSE here, since do_help() turns it
* off! */
/* Repaint the statusbar when getting a character in nanogetstr(). Note
* that we must turn on A_REVERSE here, since do_help() turns it off! */
void nanoget_repaint(const char *buf, const char *inputbuf, size_t x)
{
size_t x_real = strnlenpt(inputbuf, x);
int wid = COLS - strlenpt(buf) - 2;
size_t start_col, xpt, page_start;
char *expanded;
assert(x <= strlen(inputbuf));
start_col = strlenpt(buf) + 1;
xpt = strnlenpt(inputbuf, x);
page_start = get_statusbar_page_start(start_col, start_col + xpt);
wattron(bottomwin, A_REVERSE);
blank_statusbar();
mvwaddnstr(bottomwin, 0, 0, buf, actual_x(buf, COLS - 2));
waddch(bottomwin, ':');
waddch(bottomwin, (page_start == 0) ? ' ' : '$');
if (COLS > 1)
waddch(bottomwin, x_real < wid ? ' ' : '$');
if (COLS > 2) {
size_t page_start = x_real - x_real % wid;
char *expanded = display_string(inputbuf, page_start, wid,
FALSE);
expanded = display_string(inputbuf, page_start, COLS - start_col -
1, FALSE);
waddstr(bottomwin, expanded);
free(expanded);
assert(wid > 0);
assert(strlenpt(expanded) <= wid);
waddstr(bottomwin, expanded);
free(expanded);
wmove(bottomwin, 0, COLS - wid + x_real - page_start);
} else
wmove(bottomwin, 0, COLS - 1);
wmove(bottomwin, 0, start_col + xpt + 1 - page_start);
wattroff(bottomwin, A_REVERSE);
}
@ -2769,7 +2777,6 @@ void titlebar(const char *path)
/* Do we put an ellipsis before the path? */
assert(path != NULL || openfile->filename != NULL);
assert(COLS >= 0);
wattron(topwin, A_REVERSE);
blank_titlebar();
@ -2885,7 +2892,7 @@ void titlebar(const char *path)
free(exppath);
if (state[0] != '\0') {
if (COLS <= 1 || statelen >= COLS - 1)
if (statelen >= COLS - 1)
mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS));
else {
assert(COLS - statelen - 1 >= 0);
@ -2932,7 +2939,7 @@ void statusbar(const char *msg, ...)
/* Blank out the line. */
blank_statusbar();
if (COLS >= 4) {
{
char *bar, *foo;
size_t start_x = 0, foo_len;
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
@ -3060,20 +3067,16 @@ void onekey(const char *keystroke, const char *desc, size_t len)
/* nano scrolls horizontally within a line in chunks. This function
* returns the column number of the first character displayed in the
* window when the cursor is at the given column. Note that
* 0 <= column - get_page_start(column) < COLS. */
* edit window when the cursor is at the given column. Note that (0 <=
* column - get_page_start(column) < COLS). */
size_t get_page_start(size_t column)
{
assert(COLS > 0);
if (column == 0 || column < COLS - 1)
return 0;
else if (COLS > 9)
return column - 7 - (column - 7) % (COLS - 8);
else if (COLS > 2)
return column - (COLS - 2);
else
return column - (COLS - 1);
return column - (COLS - 2);
}
/* Resets current_y, based on the position of current, and puts the