Commit 3d12f0f5 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

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
No related merge requests found
Showing with 53 additions and 34 deletions
+53 -34
...@@ -5,6 +5,19 @@ CVS code - ...@@ -5,6 +5,19 @@ CVS code -
is disabled when NANO_SMALL is defined. New functions is disabled when NANO_SMALL is defined. New functions
do_scroll_up() and do_scroll_down(); changes to do_scroll_up() and do_scroll_down(); changes to
shortcut_init(). (DLR, suggested by Mike Frysinger) 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 GNU nano 1.3.9 - 2005.10.23
- General: - General:
......
...@@ -634,7 +634,7 @@ void window_init(void) ...@@ -634,7 +634,7 @@ void window_init(void)
{ {
/* If the screen height is too small, get out. */ /* If the screen height is too small, get out. */
editwinrows = LINES - 5 + no_more_space() + no_help(); 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")); die(_("Window size is too small for nano...\n"));
#ifndef DISABLE_WRAPJUSTIFY #ifndef DISABLE_WRAPJUSTIFY
......
...@@ -522,7 +522,9 @@ typedef struct rcoption { ...@@ -522,7 +522,9 @@ typedef struct rcoption {
#define VIEW TRUE #define VIEW TRUE
#define NOVIEW FALSE #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 #define MIN_EDITOR_ROWS 1
/* Default number of characters from end-of-line where text wrapping /* Default number of characters from end-of-line where text wrapping
......
...@@ -632,6 +632,7 @@ bool do_statusbar_next_word(bool allow_punct); ...@@ -632,6 +632,7 @@ bool do_statusbar_next_word(bool allow_punct);
bool do_statusbar_prev_word(bool allow_punct); bool do_statusbar_prev_word(bool allow_punct);
#endif #endif
void do_statusbar_verbatim_input(bool *got_enter); 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 xplustabs(void);
size_t actual_x(const char *str, size_t xplus); size_t actual_x(const char *str, size_t xplus);
size_t strnlenpt(const char *buf, size_t size); size_t strnlenpt(const char *buf, size_t size);
......
...@@ -155,7 +155,7 @@ int search_init(bool replacing, bool use_answer) ...@@ -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 /* We use (COLS / 3) here because we need to see more on the
* line. */ * line. */
sprintf(buf, " [%s%s]", disp, sprintf(buf, " [%s%s]", disp,
strlenpt(last_search) > COLS / 3 ? "..." : ""); (strlenpt(last_search) > COLS / 3) ? "..." : "");
free(disp); free(disp);
} else } else
buf = mallocstrcpy(NULL, ""); buf = mallocstrcpy(NULL, "");
......
...@@ -2174,6 +2174,20 @@ void do_statusbar_verbatim_input(bool *got_enter) ...@@ -2174,6 +2174,20 @@ void do_statusbar_verbatim_input(bool *got_enter)
free(output); 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 /* Return the placewewant associated with current_x, i.e, the zero-based
* column position of the cursor. The value will be no smaller than * column position of the cursor. The value will be no smaller than
* current_x. */ * current_x. */
...@@ -2453,39 +2467,33 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool ...@@ -2453,39 +2467,33 @@ char *display_string(const char *buf, size_t start_col, size_t len, bool
return converted; return converted;
} }
/* Repaint the statusbar when getting a character in nanogetstr(). buf /* Repaint the statusbar when getting a character in nanogetstr(). Note
* should be no longer than max(0, COLS - 4). * that we must turn on A_REVERSE here, since do_help() turns it off! */
*
* 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) void nanoget_repaint(const char *buf, const char *inputbuf, size_t x)
{ {
size_t x_real = strnlenpt(inputbuf, x); size_t start_col, xpt, page_start;
int wid = COLS - strlenpt(buf) - 2; char *expanded;
assert(x <= strlen(inputbuf)); 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); wattron(bottomwin, A_REVERSE);
blank_statusbar(); blank_statusbar();
mvwaddnstr(bottomwin, 0, 0, buf, actual_x(buf, COLS - 2)); mvwaddnstr(bottomwin, 0, 0, buf, actual_x(buf, COLS - 2));
waddch(bottomwin, ':'); waddch(bottomwin, ':');
waddch(bottomwin, (page_start == 0) ? ' ' : '$');
if (COLS > 1) expanded = display_string(inputbuf, page_start, COLS - start_col -
waddch(bottomwin, x_real < wid ? ' ' : '$'); 1, FALSE);
if (COLS > 2) {
size_t page_start = x_real - x_real % wid;
char *expanded = display_string(inputbuf, page_start, wid,
FALSE);
assert(wid > 0);
assert(strlenpt(expanded) <= wid);
waddstr(bottomwin, expanded); waddstr(bottomwin, expanded);
free(expanded); free(expanded);
wmove(bottomwin, 0, COLS - wid + x_real - page_start);
} else wmove(bottomwin, 0, start_col + xpt + 1 - page_start);
wmove(bottomwin, 0, COLS - 1);
wattroff(bottomwin, A_REVERSE); wattroff(bottomwin, A_REVERSE);
} }
...@@ -2769,7 +2777,6 @@ void titlebar(const char *path) ...@@ -2769,7 +2777,6 @@ void titlebar(const char *path)
/* Do we put an ellipsis before the path? */ /* Do we put an ellipsis before the path? */
assert(path != NULL || openfile->filename != NULL); assert(path != NULL || openfile->filename != NULL);
assert(COLS >= 0);
wattron(topwin, A_REVERSE); wattron(topwin, A_REVERSE);
blank_titlebar(); blank_titlebar();
...@@ -2885,7 +2892,7 @@ void titlebar(const char *path) ...@@ -2885,7 +2892,7 @@ void titlebar(const char *path)
free(exppath); free(exppath);
if (state[0] != '\0') { if (state[0] != '\0') {
if (COLS <= 1 || statelen >= COLS - 1) if (statelen >= COLS - 1)
mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS)); mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS));
else { else {
assert(COLS - statelen - 1 >= 0); assert(COLS - statelen - 1 >= 0);
...@@ -2932,7 +2939,7 @@ void statusbar(const char *msg, ...) ...@@ -2932,7 +2939,7 @@ void statusbar(const char *msg, ...)
/* Blank out the line. */ /* Blank out the line. */
blank_statusbar(); blank_statusbar();
if (COLS >= 4) { {
char *bar, *foo; char *bar, *foo;
size_t start_x = 0, foo_len; size_t start_x = 0, foo_len;
#if !defined(NANO_SMALL) && defined(ENABLE_NANORC) #if !defined(NANO_SMALL) && defined(ENABLE_NANORC)
...@@ -3060,20 +3067,16 @@ void onekey(const char *keystroke, const char *desc, size_t len) ...@@ -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 /* nano scrolls horizontally within a line in chunks. This function
* returns the column number of the first character displayed in the * returns the column number of the first character displayed in the
* window when the cursor is at the given column. Note that * edit window when the cursor is at the given column. Note that (0 <=
* 0 <= column - get_page_start(column) < COLS. */ * column - get_page_start(column) < COLS). */
size_t get_page_start(size_t column) size_t get_page_start(size_t column)
{ {
assert(COLS > 0);
if (column == 0 || column < COLS - 1) if (column == 0 || column < COLS - 1)
return 0; return 0;
else if (COLS > 9) else if (COLS > 9)
return column - 7 - (column - 7) % (COLS - 8); return column - 7 - (column - 7) % (COLS - 8);
else if (COLS > 2)
return column - (COLS - 2);
else else
return column - (COLS - 1); return column - (COLS - 2);
} }
/* Resets current_y, based on the position of current, and puts the /* Resets current_y, based on the position of current, and puts the
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment