openfilestruct, and so that the values in it are used directly
instead of being periodically synced up with the globals.
Accordingly, remove the globals. Changes to pretty much
- every function. Rename global_init() resize_init(), rename
- add_open_file() make_new_buffer(), rename load_buffer()
+ every function. Rename global_init() window_size_init(),
+ rename add_open_file() make_new_buffer(), rename load_buffer()
open_buffer(), rename load_open_file() load_buffer(), rename
open_prevnext_file() switch_to_prevnext_buffer(), rename
open_prevfile_void() switch_to_prev_buffer(), rename
open_nextfile_void() switch_to_next_buffer(), remove
load_file(), rename cancel_fork() cancel_command(),
- rename open_pipe() execute_command(), and remove
- execute_command(). (DLR)
- - Replace almost all mvwaddstr(hblank) calls with mvwhline(' ',
- COLS) calls, which do the same thing. New function
- nmvwhline() (since slang doesn't define mvwhline()); changes
- to do_browser(), blank_titlebar(), blank_topbar(),
- blank_edit(), blank_statusbar(), blank_bottombars(),
- update_line(), and edit_refresh(). (DLR)
+ rename open_pipe() execute_command(), remove
+ execute_command(), and remove resize_variables(). (DLR)
+ - Replace all mvwaddstr(hblank) calls with a new function that
+ does the same thing without the need for hblank. New function
+ blank_line(); changes to do_browser(), blank_titlebar(),
+ blank_topbar(), blank_edit(), blank_statusbar(),
+ blank_bottombars(), update_line(), and edit_refresh(). (DLR)
- files.c:
open_file()
- Assert that filename isn't NULL, and don't do anything special
display_string()
- Display invalid multibyte sequences as Unicode 0xFFFD
(Replacement Character). (DLR)
- total_redraw()
- - Rework to use functions that slang actually defines. (DLR)
+ titlebar()
+ - Rework to display only one space after the version number, so
+ that there's more room for other things, and to not display
+ the status when we're in the file browser, since Pico doesn't.
+ (DLR)
- configure.ac:
- Since we only use vsnprintf() now, remove the tests for
snprintf(). (DLR)
openfile = openfile->next;
}
+ /* Initialize the new buffer. */
+ initialize_buffer();
+}
+
+/* Initialize the current entry of the openfile openfilestruct. */
+void initialize_buffer(void)
+{
+ assert(openfile != NULL);
+
openfile->filename = mallocstrcpy(NULL, "");
openfile->fileage = make_new_node(NULL);
#endif
}
+#ifndef DISABLE_SPELLER
+/* Reinitialize the current entry of the openfile openfilestruct. */
+void reinitialize_buffer(void)
+{
+ assert(openfile != NULL);
+
+ free(openfile->filename);
+
+ free_filestruct(openfile->fileage);
+
+ initialize_buffer();
+}
+#endif
+
/* filename is a file to open. We make a new buffer, if necessary, and
* then open and read the file. */
void open_buffer(const char *filename)
switch_to_prevnext_buffer(TRUE);
}
-/* Delete an entry from the openfile filestruct, and open the one
+/* Delete an entry from the openfile filestruct, and switch to the one
* after it. Return TRUE on success, or FALSE if there are no more open
* file buffers. */
bool close_buffer(void)
if (j == selected)
wattron(edit, A_REVERSE);
- mvwhline(edit, editline, col, ' ', longest);
+ blank_line(edit, editline, col, longest);
mvwaddstr(edit, editline, col, disp);
free(disp);
ssize_t tabsize = -1; /* Our internal tabsize variable. The
default value is set in main(). */
-char *hblank = NULL; /* A horizontal blank line */
#ifndef DISABLE_HELP
char *help_text; /* The text in the help window */
#endif
free(last_search);
if (last_replace != NULL)
free(last_replace);
- if (hblank != NULL)
- free(hblank);
#ifndef DISABLE_SPELLER
if (alt_speller != NULL)
free(alt_speller);
die(_("Window size is too small for nano...\n"));
}
-/* Reinitialize the variables that depend on the window size. That is,
- * fill and hblank. */
-void resize_variables(void)
+/* Make sure the window size isn't too small, and reinitialize the fill
+ * variable, since it depends on the window size. */
+void window_size_init(void)
{
+ check_die_too_small();
+
#ifndef DISABLE_WRAPJUSTIFY
fill = wrap_at;
if (fill <= 0)
if (fill < 0)
fill = 0;
#endif
-
- hblank = charealloc(hblank, COLS + 1);
- charset(hblank, ' ', COLS);
- hblank[COLS] = '\0';
-}
-
-/* Initialize the resize variables. */
-void resize_init(void)
-{
- check_die_too_small();
- resize_variables();
}
void window_init(void)
const char *do_alt_speller(char *tempfile_name)
{
int alt_spell_status;
+ char *filename_save;
size_t current_x_save = openfile->current_x;
size_t pww_save = openfile->placewewant;
ssize_t current_y_save = openfile->current_y;
}
#endif
- /* Reinitialize the filestruct. */
- free_filestruct(openfile->fileage);
+ /* Set up the window size. */
+ window_size_init();
+
+ /* Save the current filename. */
+ filename_save = mallocstrcpy(NULL, openfile->filename);
+
+ /* Reinitialize the current buffer. */
+ reinitialize_buffer();
- /* Reinitialize the resize variables. */
- resize_init();
+ /* Restore the current filename. */
+ openfile->filename = filename_save;
- /* Reload the temp file. Do what open_buffer() would do, except for
- * making a new buffer for the temp file if multibuffer support is
- * available. */
+ /* Reload the temp file. Open it, read it into the current buffer,
+ * and move back to the first line of the buffer. */
open_file(tempfile_name, FALSE, &f);
read_file(f, tempfile_name);
openfile->current = openfile->fileage;
COLS = win.ws_col;
LINES = win.ws_row;
- resize_init();
+ /* Reinitialize the window size variables. */
+ window_size_init();
/* If we've partitioned the filestruct, unpartition it now. */
if (filepart != NULL)
/* Back up the old terminal settings so that they can be restored. */
tcgetattr(0, &oldterm);
- /* Curses initialization stuff: Start curses and set up the
- * terminal state. */
+ /* Initialize curses mode. */
initscr();
+
+ /* Set up the terminal state. */
terminal_init();
/* Turn the cursor on for sure. */
curs_set(1);
- /* Set up the resize variables and the shortcuts. */
- resize_init();
+ /* Initialize the window size variables. */
+ window_size_init();
+
+ /* Set up the shortcuts. */
shortcut_init(FALSE);
/* Set up the signal handlers. */
#define getline ngetline
#endif
-/* Slang curses emulation brain damage, part 3: Slang doesn't define
- * mvwhline(), so use the version we have. */
-#ifdef USE_SLANG
-#define mvwhline nmvwhline
-#endif
-
#define VERMSG "GNU nano " VERSION
/* If we aren't using ncurses, turn the mouse support off, as it's
extern WINDOW *topwin, *edit, *bottomwin;
extern char *answer;
-extern char *hblank;
#ifndef DISABLE_HELP
extern char *help_text;
#endif
void free_openfilestruct(openfilestruct *src);
#endif
void make_new_buffer(void);
+void initialize_buffer(void);
+#ifndef DISABLE_SPELLER
+void reinitialize_buffer(void);
+#endif
void open_buffer(const char *filename);
void load_buffer(void);
#ifdef ENABLE_MULTIBUFFER
void die(const char *msg, ...);
void die_save_file(const char *die_filename);
void check_die_too_small(void);
-void resize_variables(void);
-void resize_init(void);
+void window_size_init(void);
void window_init(void);
#ifndef DISABLE_MOUSE
void mouse_init(void);
*lines, size_t *size);
/* Public functions in winio.c. */
-#ifdef USE_SLANG
-int nmvwhline(WINDOW *win, int y, int x, char ch, int n);
-#endif
#ifndef NANO_SMALL
void reset_kbinput(void);
#endif
size_t actual_x(const char *str, size_t xplus);
size_t strnlenpt(const char *buf, size_t size);
size_t strlenpt(const char *buf);
+void blank_line(WINDOW *win, int y, int x, int n);
void blank_titlebar(void);
void blank_topbar(void);
void blank_edit(void);
/* Should we reset the cursor position
* at the statusbar prompt? */
-#ifdef USE_SLANG
-/* Slang curses emulation brain damage, part 4: Slang doesn't define
- * mvwhline(). */
-int nmvwhline(WINDOW *win, int y, int x, char ch, int n)
-{
- wmove(win, y, x);
- for (; n > 0; n--)
- waddch(win, ch);
-
- return 0;
-}
-#endif
-
/* Control character compatibility:
*
* - NANO_BACKSPACE_KEY is Ctrl-H, which is Backspace under ASCII, ANSI,
return strnlenpt(buf, (size_t)-1);
}
+/* Move to (x, y) in win, and display a line of n spaces with the
+ * current attributes. */
+void blank_line(WINDOW *win, int y, int x, int n)
+{
+ wmove(win, y, x);
+ for (; n > 0; n--)
+ waddch(win, ' ');
+}
+
void blank_titlebar(void)
{
- mvwhline(topwin, 0, 0, ' ', COLS);
+ blank_line(topwin, 0, 0, COLS);
}
void blank_topbar(void)
{
if (!ISSET(MORE_SPACE))
- mvwhline(topwin, 1, 0, ' ', COLS);
+ blank_line(topwin, 1, 0, COLS);
}
void blank_edit(void)
{
int i;
for (i = 0; i < editwinrows; i++)
- mvwhline(edit, i, 0, ' ', COLS);
+ blank_line(edit, i, 0, COLS);
}
void blank_statusbar(void)
{
- mvwhline(bottomwin, 0, 0, ' ', COLS);
+ blank_line(bottomwin, 0, 0, COLS);
}
void blank_bottombars(void)
{
if (!ISSET(NO_HELP)) {
- mvwhline(bottomwin, 1, 0, ' ', COLS);
- mvwhline(bottomwin, 2, 0, ' ', COLS);
+ blank_line(bottomwin, 1, 0, COLS);
+ blank_line(bottomwin, 2, 0, COLS);
}
}
{
int space;
/* The space we have available for display. */
- size_t verlen = strlenpt(VERMSG) + 1;
+ size_t verlen = strlenpt(VERMSG);
/* The length of the version message in columns. */
const char *prefix;
- /* "File:", "Dir:", or "New Buffer". Goes before filename. */
+ /* "DIR:", "File:", or "New Buffer". Goes before filename. */
size_t prefixlen;
- /* The length of the prefix in columns, plus one. */
+ /* The length of the prefix in columns. */
const char *state;
- /* "Modified", "View", or spaces the length of "Modified".
- * Tells the state of this buffer. */
+ /* "Modified", "View", or "". Shows the state of this
+ * buffer. */
size_t statelen = 0;
- /* The length of the state in columns, plus one. */
+ /* The length of the state in columns, or the length of
+ * "Modified" if the state is blank. */
char *exppath = NULL;
/* The file name, expanded for display. */
bool newfie = FALSE;
wattron(topwin, A_REVERSE);
blank_titlebar();
- if (COLS <= 5 || COLS - 5 < verlen)
+ if (COLS <= 4 || COLS - 4 < verlen)
space = 0;
else {
- space = COLS - 5 - verlen;
- /* Reserve 2/3 of the screen plus one column for after the
+ space = COLS - 4 - verlen;
+ /* Reserve 2/3 of the screen plus two columns for after the
* version message. */
- if (space < COLS - (COLS / 3) + 1)
- space = COLS - (COLS / 3) + 1;
+ if (space < COLS - (COLS / 3) + 2)
+ space = COLS - (COLS / 3) + 2;
}
- if (COLS > 4) {
- /* The version message should only take up 1/3 of the screen
- * minus one column. */
+ if (COLS > 3) {
+ /* The version message, counting the two spaces before it,
+ * should only take up 1/3 of the screen minus two columns. */
mvwaddnstr(topwin, 0, 2, VERMSG, actual_x(VERMSG,
- (COLS / 3) - 3));
- waddstr(topwin, " ");
+ (COLS / 3) - 4));
+ waddch(topwin, ' ');
}
- if (openfile->modified)
- state = _("Modified");
- else if (ISSET(VIEW_MODE))
- state = _("View");
- else {
- if (space > 0)
- statelen = strnlenpt(_("Modified"), space - 1) + 1;
- state = &hblank[COLS - statelen];
- }
- statelen = strnlenpt(state, COLS);
+#ifndef DISABLE_BROWSER
+ /* Don't display the state if we're in the file browser. */
+ if (path != NULL)
+ state = "";
+ else
+#endif
+ state = openfile->modified ? _("Modified") : ISSET(VIEW_MODE) ?
+ _("View") : "";
+
+ statelen = strlenpt((state[0] != '\0') ? state : _("Modified"));
/* We need a space before state. */
if ((openfile->modified || ISSET(VIEW_MODE)) && statelen < COLS)
goto the_end;
#ifndef DISABLE_BROWSER
+ /* path should be a directory if we're in the file browser. */
if (path != NULL)
prefix = _("DIR:");
else
if (!newfie && prefixlen + statelen < space)
prefixlen++;
+ /* If we're not in the file browser, path should be the current
+ * filename. */
if (path == NULL)
path = openfile->filename;
+
if (space >= prefixlen + statelen)
space -= prefixlen + statelen;
else
/* space is now the room we have for the file name. */
if (!newfie) {
- size_t lenpt = strlenpt(path), start_col;
+ size_t lenpt = strlenpt(path) + 1, start_col;
- dots = (lenpt > space);
+ dots = (lenpt >= space);
if (dots) {
start_col = lenpt - space + 3;
/* The length of the expanded filename. */
/* There is room for the whole filename, so we center it. */
- waddnstr(topwin, hblank, (space - exppathlen) / 3);
- waddnstr(topwin, prefix, actual_x(prefix, prefixlen));
+ mvwaddnstr(topwin, 0, ((COLS / 3) - 4) + ((space - exppathlen) /
+ 3), prefix, actual_x(prefix, prefixlen));
if (!newfie) {
assert(strlenpt(prefix) + 1 == prefixlen);
the_end:
free(exppath);
- if (COLS <= 1 || statelen >= COLS - 1)
- mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS));
- else {
- assert(COLS - statelen - 2 >= 0);
+ if (state[0] != '\0') {
+ if (COLS <= 1 || statelen >= COLS - 1)
+ mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS));
+ else {
+ assert(COLS - statelen - 2 >= 0);
- mvwaddch(topwin, 0, COLS - statelen - 2, ' ');
- mvwaddnstr(topwin, 0, COLS - statelen - 1, state,
+ mvwaddch(topwin, 0, COLS - statelen - 2, ' ');
+ mvwaddnstr(topwin, 0, COLS - statelen - 1, state,
actual_x(state, statelen));
+ }
}
wattroff(topwin, A_REVERSE);
return;
/* First, blank out the line. */
- mvwhline(edit, line, 0, ' ', COLS);
+ blank_line(edit, line, 0, COLS);
/* Next, convert variables that index the line to their equivalent
* positions in the expanded line. */
foo = foo->next;
}
while (nlines < editwinrows) {
- mvwhline(edit, nlines, 0, ' ', COLS);
+ blank_line(edit, nlines, 0, COLS);
nlines++;
}
reset_cursor();
void total_redraw(void)
{
- touchwin(stdscr);
- wrefresh(stdscr);
+#ifdef USE_SLANG
+ /* Slang curses emulation brain damage, part 3: Slang doesn't define
+ * curscr. */
+ SLsmg_touch_screen();
+ SLsmg_refresh();
+#else
+ wrefresh(curscr);
+#endif
}
void total_refresh(void)