Commit 1f28b8f4 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

DB's rewrite of the screen update and color routines

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1285 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 413 additions and 528 deletions
+413 -528
...@@ -24,6 +24,9 @@ CVS code - ...@@ -24,6 +24,9 @@ CVS code -
properly. New function init_operating_dir() to handle properly. New function init_operating_dir() to handle
setting it both on the command line and in the nanorc file. setting it both on the command line and in the nanorc file.
(David Benbennick) (David Benbennick)
- Major rewrite of color and screen update routines to fix
minor bugs and increase efficiency. New function
set_colorpairs() for the former. (David Benbennick)
- configure.ac: - configure.ac:
- Added pt_BR to ALL_LINGUAS (Jordi). - Added pt_BR to ALL_LINGUAS (Jordi).
- Changed --enable-color warning to be slightly less severe. - Changed --enable-color warning to be slightly less severe.
...@@ -122,7 +125,9 @@ CVS code - ...@@ -122,7 +125,9 @@ CVS code -
format ({} instead of \{\}) (found by DLR). format ({} instead of \{\}) (found by DLR).
- Add a better string matching sequence that includes escaped - Add a better string matching sequence that includes escaped
quotes (thanks to Carl E. Lindberg, who doesn't even know he quotes (thanks to Carl E. Lindberg, who doesn't even know he
helped ;-) helped ;-). Some unneeded \'s in that sequence removed, and
a new sequence to handle multi-line quotes added, by David
Benbennick.
- rcfile.c: - rcfile.c:
parse_colors() parse_colors()
- Stop infinite loop when syntax doesn't begin with " char. - Stop infinite loop when syntax doesn't begin with " char.
......
...@@ -40,72 +40,91 @@ ...@@ -40,72 +40,91 @@
#define _(string) (string) #define _(string) (string)
#endif #endif
void do_colorinit(void) /* For each syntax list entry, we go through the list of colors and
* assign color pairs. */
void set_colorpairs(void)
{ {
int i; const syntaxtype *this_syntax = syntaxes;
colortype *tmpcolor = NULL, *beforenow = NULL;
int defok = 0; for(; this_syntax != NULL; this_syntax = this_syntax->next) {
colortype *this_color = this_syntax->color;
int color_pair = 1;
for(; this_color != NULL; this_color = this_color->next) {
const colortype *beforenow = this_syntax->color;
for(; beforenow != NULL && beforenow != this_color &&
(beforenow->fg != this_color->fg ||
beforenow->bg != this_color->bg ||
beforenow->bright != this_color->bright);
beforenow = beforenow->next)
;
if (beforenow != NULL && beforenow != this_color)
this_color->pairnum = beforenow->pairnum;
else {
this_color->pairnum = color_pair;
color_pair++;
}
}
}
}
void do_colorinit(void)
{
if (has_colors()) { if (has_colors()) {
const colortype *tmpcolor = NULL;
#ifdef HAVE_USE_DEFAULT_COLORS
int defok;
#endif
start_color(); start_color();
/* Add in colors, if available */ /* Add in colors, if available */
#ifdef HAVE_USE_DEFAULT_COLORS #ifdef HAVE_USE_DEFAULT_COLORS
if (use_default_colors() != ERR) defok = use_default_colors() != ERR;
defok = 1;
#endif #endif
i = 1;
for (tmpcolor = colorstrings; tmpcolor != NULL; for (tmpcolor = colorstrings; tmpcolor != NULL;
tmpcolor = tmpcolor->next) { tmpcolor = tmpcolor->next) {
short background = tmpcolor->bg;
for (beforenow = colorstrings; beforenow != NULL if (background == -1)
&& beforenow != tmpcolor && #ifdef HAVE_USE_DEFAULT_COLORS
(beforenow->fg != tmpcolor->fg || beforenow->bg != tmpcolor->bg if (!defok)
|| beforenow->bright != tmpcolor->bright); #endif
beforenow = beforenow->next) background = COLOR_BLACK;
;
if (beforenow != NULL && beforenow != tmpcolor) { init_pair(tmpcolor->pairnum, tmpcolor->fg, background);
tmpcolor->pairnum = beforenow->pairnum;
continue;
}
if (defok && tmpcolor->bg == -1)
init_pair(i, tmpcolor->fg, -1);
else if (tmpcolor->bg == -1)
init_pair(i, tmpcolor->fg, COLOR_BLACK);
else /* They picked a fg and bg color */
init_pair(i, tmpcolor->fg, tmpcolor->bg);
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, _("Running init_pair with fg = %d and bg = %d\n"), tmpcolor->fg, tmpcolor->bg); fprintf(stderr, _("Running init_pair with fg = %d and bg = %d\n"), tmpcolor->fg, tmpcolor->bg);
#endif #endif
tmpcolor->pairnum = i;
i++;
} }
} }
return;
} }
/* Update the color information based on the current filename */ /* Update the color information based on the current filename */
void update_color(void) void update_color(void)
{ {
syntaxtype *tmpsyntax; const syntaxtype *tmpsyntax;
colorstrings = NULL; colorstrings = NULL;
for (tmpsyntax = syntaxes; tmpsyntax != NULL; tmpsyntax = tmpsyntax->next) { for (tmpsyntax = syntaxes; tmpsyntax != NULL; tmpsyntax = tmpsyntax->next) {
exttype *e; const exttype *e;
for (e = tmpsyntax->extensions; e != NULL; e = e->next) { for (e = tmpsyntax->extensions; e != NULL; e = e->next) {
regcomp(&syntaxfile_regexp, e->val, REG_EXTENDED); regex_t syntaxfile_regexp;
regcomp(&syntaxfile_regexp, e->val, REG_EXTENDED | REG_NOSUB);
/* Set colorstrings if we matched the extension regex */ /* Set colorstrings if we matched the extension regex */
if (!regexec(&syntaxfile_regexp, filename, 1, synfilematches, 0)) if (!regexec(&syntaxfile_regexp, filename, 0, NULL, 0))
colorstrings = tmpsyntax->color; colorstrings = tmpsyntax->color;
regfree(&syntaxfile_regexp); regfree(&syntaxfile_regexp);
if (colorstrings != NULL)
break;
} }
} }
......
...@@ -125,7 +125,7 @@ shortcut *browser_list = NULL; ...@@ -125,7 +125,7 @@ shortcut *browser_list = NULL;
#endif #endif
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
colortype *colorstrings = NULL; const colortype *colorstrings = NULL;
syntaxtype *syntaxes = NULL; syntaxtype *syntaxes = NULL;
char *syntaxstr = NULL; char *syntaxstr = NULL;
#endif #endif
...@@ -145,13 +145,6 @@ regex_t search_regexp; /* Global to store compiled search regexp */ ...@@ -145,13 +145,6 @@ regex_t search_regexp; /* Global to store compiled search regexp */
regmatch_t regmatches[10]; /* Match positions for parenthetical regmatch_t regmatches[10]; /* Match positions for parenthetical
subexpressions, max of 10 */ subexpressions, max of 10 */
#endif #endif
#ifdef ENABLE_COLOR
regex_t color_regexp; /* Global to store compiled search regexp */
regmatch_t colormatches[1]; /* Match positions for parenthetical */
regex_t syntaxfile_regexp; /* Global to store compiled search regexp */
regmatch_t synfilematches[1]; /* Match positions for parenthetical */
#endif /* ENABLE_COLOR */
int length_of_list(const shortcut *s) int length_of_list(const shortcut *s)
{ {
......
...@@ -102,7 +102,8 @@ ...@@ -102,7 +102,8 @@
# because syntax highlighting rules will be applied in the order they are # because syntax highlighting rules will be applied in the order they are
# read in # read in
# color brightyellow "<[^= ]*>" "\"(\\.|[^\\"])*\"" # color brightyellow "<[^= ]*>" ""(\\.|[^\"])*""
# color brightyellow start=""(\\.|[^\"])*\\( | )*$" end="^(\\.|[^\"])*""
# color brightblue "//.*" # color brightblue "//.*"
# color brightblue start="/\*" end="\*/" # color brightblue start="/\*" end="\*/"
......
...@@ -71,11 +71,9 @@ extern openfilestruct *open_files; ...@@ -71,11 +71,9 @@ extern openfilestruct *open_files;
#endif #endif
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
extern colortype *colorstrings; extern const colortype *colorstrings;
extern syntaxtype *syntaxes; extern syntaxtype *syntaxes;
extern char *syntaxstr; extern char *syntaxstr;
extern regex_t color_regexp;
extern regmatch_t colormatches[1];
#endif #endif
extern shortcut *shortcut_list; extern shortcut *shortcut_list;
...@@ -110,6 +108,7 @@ extern toggle *toggles; ...@@ -110,6 +108,7 @@ extern toggle *toggles;
/* Public functions in color.c */ /* Public functions in color.c */
#ifdef ENABLE_COLOR #ifdef ENABLE_COLOR
void set_colorpairs(void);
void do_colorinit(void); void do_colorinit(void);
void update_color(void); void update_color(void);
#endif /* ENABLE_COLOR */ #endif /* ENABLE_COLOR */
...@@ -401,15 +400,18 @@ void set_modified(void); ...@@ -401,15 +400,18 @@ void set_modified(void);
void titlebar(const char *path); void titlebar(const char *path);
void bottombars(const shortcut *s); void bottombars(const shortcut *s);
void onekey(const char *keystroke, const char *desc, int len); void onekey(const char *keystroke, const char *desc, int len);
int get_page_start_virtual(int page); #ifndef NDEBUG
int get_page_from_virtual(int virtual); int check_linenumbers(const filestruct *fileptr);
int get_page_end_virtual(int page); #endif
int get_page_start(int column); int get_page_start(int column);
void reset_cursor(void); void reset_cursor(void);
void add_marked_sameline(int begin, int end, filestruct *fileptr, int y, void add_marked_sameline(int begin, int end, filestruct *fileptr, int y,
int virt_cur_x, int this_page); int virt_cur_x, int this_page);
void edit_add(filestruct *fileptr, int yval, int start, int virt_cur_x, void edit_add(const filestruct *fileptr, int yval, int start
int virt_mark_beginx, int this_page); #ifndef NANO_SMALL
, int virt_mark_beginx, int virt_cur_x
#endif
);
void update_line(filestruct *fileptr, int index); void update_line(filestruct *fileptr, int index);
void update_cursor(void); void update_cursor(void);
void center_cursor(void); void center_cursor(void);
......
...@@ -631,6 +631,9 @@ void do_rcfile(void) ...@@ -631,6 +631,9 @@ void do_rcfile(void)
} }
free(nanorc); free(nanorc);
#ifdef ENABLE_COLOR
set_colorpairs();
#endif
} }
#endif /* ENABLE_NANORC */ #endif /* ENABLE_NANORC */
This diff is collapsed.
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