Commit 8ce2413f authored by Chris Allegretta's avatar Chris Allegretta
Browse files

Add color changes, undocumented and ugly, but hey maybe people want to see what chap I wrote so far

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@624 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent 465f1e30
Showing with 350 additions and 105 deletions
+350 -105
## $Id$
bin_PROGRAMS = nano
nano_SOURCES = cut.c \
nano_SOURCES = color.c \
cut.c \
files.c \
global.c \
move.c \
......
......@@ -86,7 +86,7 @@ USE_NLS = @USE_NLS@
VERSION = @VERSION@
bin_PROGRAMS = nano
nano_SOURCES = cut.c files.c global.c move.c nano.c nano.h proto.h rcfile.c search.c utils.c winio.c
nano_SOURCES = color.c cut.c files.c global.c move.c nano.c nano.h proto.h rcfile.c search.c utils.c winio.c
man_MANS = nano.1
......@@ -113,8 +113,8 @@ DEFS = @DEFS@ -I. -I$(srcdir) -I.
CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
nano_OBJECTS = cut.o files.o global.o move.o nano.o rcfile.o search.o \
utils.o winio.o
nano_OBJECTS = color.o cut.o files.o global.o move.o nano.o rcfile.o \
search.o utils.o winio.o
nano_DEPENDENCIES =
nano_LDFLAGS =
CFLAGS = @CFLAGS@
......
......@@ -57,6 +57,9 @@
/* Define this to use the .nanorc file */
#undef ENABLE_NANORC
/* Define this if your curses library has the use_default_colors command */
#undef HAVE_USE_DEFAULT_COLORS
/* Define this to have syntax hilighting, requires ENABLE_NANORC too! */
#undef ENABLE_COLOR
......@@ -91,6 +91,9 @@
/* Define this to use the .nanorc file */
#undef ENABLE_NANORC
/* Define this if your curses library has the use_default_colors command */
#undef HAVE_USE_DEFAULT_COLORS
/* Define this to have syntax hilighting, requires ENABLE_NANORC too! */
#undef ENABLE_COLOR
......
This diff is collapsed.
......@@ -237,6 +237,7 @@ else
fi
AC_CHECK_LIB([$CURSES_LIB_NAME], use_default_colors, [AC_DEFINE(HAVE_USE_DEFAULT_COLORS)])
if test x$slang_support != xyes; then
AC_CHECK_LIB([$CURSES_LIB_NAME], wresize, [AC_DEFINE(HAVE_WRESIZE)])
AC_CHECK_LIB([$CURSES_LIB_NAME], resizeterm, [AC_DEFINE(HAVE_RESIZETERM)])
......
......@@ -1322,6 +1322,7 @@ char *do_browser(char *inpath)
return do_browser(path);
/* Stuff we want to abort the browser */
case NANO_CONTROL_C:
case 'q':
case 'Q':
case 'e': /* Pico compatibility, yeech */
......@@ -1380,11 +1381,22 @@ char *do_browser(char *inpath)
}
/* Hilight the currently selected file/dir */
if (j == selected)
if (j == selected) {
#ifdef ENABLE_COLOR
color_on(edit, COLOR_STATUSBAR);
#else
wattron(edit, A_REVERSE);
#endif
}
waddnstr(edit, foo, strlen(foo));
if (j == selected)
if (j == selected) {
#ifdef ENABLE_COLOR
color_off(edit, COLOR_STATUSBAR);
#else
wattroff(edit, A_REVERSE);
#endif
}
/* And add some space between the cols */
waddstr(edit, " ");
......
......@@ -88,6 +88,10 @@ shortcut spell_list[SPELL_LIST_LEN];
shortcut browser_list[BROWSER_LIST_LEN];
#endif
#ifdef ENABLE_COLOR
colorstruct colors[NUM_NCOLORS];
#endif
shortcut *currshortcut = main_list; /* Current shortcut list we're using */
int currslen = MAIN_VISIBLE; /* Length of current shortcut list */
......
......@@ -453,6 +453,9 @@ void version(void)
#ifdef ENABLE_NANORC
printf(" --enable-nanorc");
#endif
#ifdef ENABLE_COLOR
printf(" --enable-color");
#endif
#ifdef NANO_SMALL
printf(" --enable-tiny");
......@@ -2402,6 +2405,10 @@ int main(int argc, char *argv[])
fprintf(stderr, _("Main: set up windows\n"));
#endif
#ifdef ENABLE_COLOR
do_colorinit();
#endif /* ENABLE_COLOR */
window_init();
mouse_init();
......
......@@ -285,4 +285,25 @@ know what you're doing */
/* Minimum fill length (space available for text before wrapping occurs) */
#define MIN_FILL_LENGTH 10
/* Color specific defines */
#ifdef ENABLE_COLOR
typedef struct colorstruct {
int fg;
int bg;
int bold;
int set;
} colorstruct;
#define FIRST_COLORNUM 16
#define COLOR_TITLEBAR 16
#define COLOR_BOTTOMBARS 17
#define COLOR_STATUSBAR 18
#define COLOR_TEXT 19
#define COLOR_MARKER 20
#define NUM_NCOLORS 5
#endif /* ENABLE_COLOR */
#endif /* ifndef NANO_H */
......@@ -174,6 +174,14 @@ struct stat filestat(const char *path);
char *do_browse_from(char *inpath);
#endif
#ifdef ENABLE_COLOR
int do_colorinit(void);
void color_on(WINDOW *win, int whatever);
void color_off(WINDOW *win, int whatever);
extern colorstruct colors[NUM_NCOLORS];
#endif /* ENABLE_COLOR */
RETSIGTYPE main_loop (int junk);
filestruct *copy_node(filestruct * src);
......
......@@ -227,7 +227,11 @@ void nanoget_repaint(char *buf, char *inputbuf, int x)
int len = strlen(buf);
int wid = COLS - len;
#ifdef ENABLE_COLOR
color_on(bottomwin, COLOR_STATUSBAR);
#endif
blank_statusbar();
if (x <= COLS - 1) {
/* Black magic */
buf[len - 1] = ' ';
......@@ -244,6 +248,10 @@ void nanoget_repaint(char *buf, char *inputbuf, int x)
waddnstr(bottomwin, &inputbuf[wid * ((x - len) / (wid))], wid);
wmove(bottomwin, 0, ((x - len) % wid) + len);
}
#ifdef ENABLE_COLOR
color_off(bottomwin, COLOR_STATUSBAR);
#endif
}
/* Get the input from the kb, this should only be called from statusq */
......@@ -492,8 +500,15 @@ void titlebar(char *path)
if (path == NULL)
what = filename;
#ifdef ENABLE_COLOR
color_on(topwin, COLOR_TITLEBAR);
mvwaddstr(topwin, 0, 0, hblank);
#else
horizbar(topwin, 0);
wattron(topwin, A_REVERSE);
#endif
mvwaddstr(topwin, 0, 3, VERMSG);
space = COLS - strlen(VERMSG) - strlen(VERSION) - 21;
......@@ -519,7 +534,14 @@ void titlebar(char *path)
}
if (ISSET(MODIFIED))
mvwaddstr(topwin, 0, COLS - 10, _("Modified"));
#ifdef ENABLE_COLOR
color_off(topwin, COLOR_TITLEBAR);
#else
wattroff(topwin, A_REVERSE);
#endif
wrefresh(topwin);
reset_cursor();
}
......@@ -552,6 +574,10 @@ void bottombars(shortcut s[], int slen)
if (ISSET(NO_HELP))
return;
#ifdef ENABLE_COLOR
color_on(bottomwin, COLOR_BOTTOMBARS);
#endif
/* Determine how many extra spaces are needed to fill the bottom of the screen */
k = COLS / 6 - 13;
......@@ -574,6 +600,10 @@ void bottombars(shortcut s[], int slen)
waddch(bottomwin, ' ');
}
#ifdef ENABLE_COLOR
color_off(bottomwin, COLOR_BOTTOMBARS);
#endif
wrefresh(bottomwin);
}
......@@ -671,10 +701,22 @@ void add_marked_sameline(int begin, int end, filestruct * fileptr, int y,
/* Paint this line! */
mvwaddnstr(edit, y, 0, &fileptr->data[this_page_start], pre_data_len);
#ifdef ENABLE_COLOR
color_on(edit, COLOR_MARKER);
#else
wattron(edit, A_REVERSE);
#endif /* ENABLE_COLOR */
mvwaddnstr(edit, y, begin - this_page_start,
&fileptr->data[begin], sel_data_len);
#ifdef ENABLE_COLOR
color_off(edit, COLOR_MARKER);
#else
wattroff(edit, A_REVERSE);
#endif /* ENABLE_COLOR */
mvwaddnstr(edit, y, end - this_page_start,
&fileptr->data[end], post_data_len);
}
......@@ -702,9 +744,20 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
if (fileptr != mark_beginbuf && fileptr != current) {
/* We are on a completely marked line, paint it all
* inverse */
#ifdef ENABLE_COLOR
color_on(edit, COLOR_MARKER);
#else
wattron(edit, A_REVERSE);
#endif /* ENABLE_COLOR */
mvwaddnstr(edit, yval, 0, fileptr->data, COLS);
#ifdef ENABLE_COLOR
color_off(edit, COLOR_MARKER);
#else
wattroff(edit, A_REVERSE);
#endif /* ENABLE_COLOR */
} else if (fileptr == mark_beginbuf && fileptr == current) {
/* Special case, we're still on the same line we started
* marking -- so we call our helper function */
......@@ -730,8 +783,13 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
*/
int target;
if (mark_beginbuf->lineno > current->lineno)
if (mark_beginbuf->lineno > current->lineno) {
#ifdef ENABLE_COLOR
color_on(edit, COLOR_MARKER);
#else
wattron(edit, A_REVERSE);
#endif /* ENABLE_COLOR */
}
target =
(virt_mark_beginx <
......@@ -739,10 +797,23 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
mvwaddnstr(edit, yval, 0, fileptr->data, target);
if (mark_beginbuf->lineno < current->lineno)
if (mark_beginbuf->lineno < current->lineno) {
#ifdef ENABLE_COLOR
color_on(edit, COLOR_MARKER);
#else
wattron(edit, A_REVERSE);
else
#endif /* ENABLE_COLOR */
} else {
#ifdef ENABLE_COLOR
color_off(edit, COLOR_MARKER);
#else
wattroff(edit, A_REVERSE);
#endif /* ENABLE_COLOR */
}
target = (COLS - 1) - virt_mark_beginx;
if (target < 0)
......@@ -751,8 +822,15 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
mvwaddnstr(edit, yval, virt_mark_beginx,
&fileptr->data[virt_mark_beginx], target);
if (mark_beginbuf->lineno < current->lineno)
if (mark_beginbuf->lineno < current->lineno) {
#ifdef ENABLE_COLOR
color_off(edit, COLOR_MARKER);
#else
wattroff(edit, A_REVERSE);
#endif /* ENABLE_COLOR */
}
} else if (fileptr == current) {
/* we're on the cursor's line, but it's not the first
......@@ -760,8 +838,15 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
int this_page_start = get_page_start_virtual(this_page),
this_page_end = get_page_end_virtual(this_page);
if (mark_beginbuf->lineno < current->lineno)
if (mark_beginbuf->lineno < current->lineno) {
#ifdef ENABLE_COLOR
color_on(edit, COLOR_MARKER);
#else
wattron(edit, A_REVERSE);
#endif /* ENABLE_COLOR */
}
if (virt_cur_x > COLS - 2) {
mvwaddnstr(edit, yval, 0,
......@@ -771,10 +856,23 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
mvwaddnstr(edit, yval, 0, fileptr->data, virt_cur_x);
}
if (mark_beginbuf->lineno > current->lineno)
if (mark_beginbuf->lineno > current->lineno) {
#ifdef ENABLE_COLOR
color_on(edit, COLOR_MARKER);
#else
wattron(edit, A_REVERSE);
else
#endif /* ENABLE_COLOR */
} else {
#ifdef ENABLE_COLOR
color_off(edit, COLOR_MARKER);
#else
wattroff(edit, A_REVERSE);
#endif /* ENABLE_COLOR */
}
if (virt_cur_x > COLS - 2)
mvwaddnstr(edit, yval, virt_cur_x - this_page_start,
......@@ -784,8 +882,15 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
mvwaddnstr(edit, yval, virt_cur_x,
&fileptr->data[virt_cur_x], COLS - virt_cur_x);
if (mark_beginbuf->lineno > current->lineno)
if (mark_beginbuf->lineno > current->lineno) {
#ifdef ENABLE_COLOR
color_off(edit, COLOR_MARKER);
#else
wattroff(edit, A_REVERSE);
#endif /* ENABLE_COLOR */
}
}
} else
......@@ -1007,9 +1112,21 @@ int statusq(int tabs, shortcut s[], int slen, char *def, char *msg, ...)
va_end(ap);
strncat(foo, ": ", 132);
#ifdef ENABLE_COLOR
color_on(bottomwin, COLOR_STATUSBAR);
#else
wattron(bottomwin, A_REVERSE);
#endif
ret = nanogetstr(tabs, foo, def, s, slen, (strlen(foo) + 3));
#ifdef ENABLE_COLOR
color_off(bottomwin, COLOR_STATUSBAR);
#else
wattroff(bottomwin, A_REVERSE);
#endif
switch (ret) {
......@@ -1061,9 +1178,10 @@ int do_yesno(int all, int leavecursor, char *msg, ...)
/* Write the bottom of the screen */
clear_bottomwin();
wattron(bottomwin, A_REVERSE);
blank_statusbar_refresh();
wattroff(bottomwin, A_REVERSE);
#ifdef ENABLE_COLOR
color_on(bottomwin, COLOR_BOTTOMBARS);
#endif
/* Remove gettext call for keybindings until we clear the thing up */
if (!ISSET(NO_HELP)) {
......@@ -1086,9 +1204,23 @@ int do_yesno(int all, int leavecursor, char *msg, ...)
va_start(ap, msg);
vsnprintf(foo, 132, msg, ap);
va_end(ap);
#ifdef ENABLE_COLOR
color_off(bottomwin, COLOR_BOTTOMBARS);
color_on(bottomwin, COLOR_STATUSBAR);
#else
wattron(bottomwin, A_REVERSE);
#endif /* ENABLE_COLOR */
blank_statusbar();
mvwaddstr(bottomwin, 0, 0, foo);
#ifdef ENABLE_COLOR
color_off(bottomwin, COLOR_STATUSBAR);
#else
wattroff(bottomwin, A_REVERSE);
#endif
wrefresh(bottomwin);
if (leavecursor == 1)
......@@ -1188,12 +1320,22 @@ void statusbar(char *msg, ...)
wmove(bottomwin, 0, start_x);
#ifdef ENABLE_COLOR
color_on(bottomwin, COLOR_STATUSBAR);
#else
wattron(bottomwin, A_REVERSE);
#endif
waddstr(bottomwin, "[ ");
waddstr(bottomwin, foo);
waddstr(bottomwin, " ]");
#ifdef ENABLE_COLOR
color_off(bottomwin, COLOR_STATUSBAR);
#else
wattroff(bottomwin, A_REVERSE);
#endif
wrefresh(bottomwin);
if (ISSET(CONSTUPDATE))
......
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