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 -
properly. New function init_operating_dir() to handle
setting it both on the command line and in the nanorc file.
(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:
- Added pt_BR to ALL_LINGUAS (Jordi).
- Changed --enable-color warning to be slightly less severe.
......@@ -122,7 +125,9 @@ CVS code -
format ({} instead of \{\}) (found by DLR).
- Add a better string matching sequence that includes escaped
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:
parse_colors()
- Stop infinite loop when syntax doesn't begin with " char.
......
......@@ -40,72 +40,91 @@
#define _(string) (string)
#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;
colortype *tmpcolor = NULL, *beforenow = NULL;
int defok = 0;
const syntaxtype *this_syntax = syntaxes;
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()) {
const colortype *tmpcolor = NULL;
#ifdef HAVE_USE_DEFAULT_COLORS
int defok;
#endif
start_color();
/* Add in colors, if available */
#ifdef HAVE_USE_DEFAULT_COLORS
if (use_default_colors() != ERR)
defok = 1;
defok = use_default_colors() != ERR;
#endif
i = 1;
for (tmpcolor = colorstrings; tmpcolor != NULL;
tmpcolor = tmpcolor->next) {
short background = tmpcolor->bg;
for (beforenow = colorstrings; beforenow != NULL
&& beforenow != tmpcolor &&
(beforenow->fg != tmpcolor->fg || beforenow->bg != tmpcolor->bg
|| beforenow->bright != tmpcolor->bright);
beforenow = beforenow->next)
;
if (background == -1)
#ifdef HAVE_USE_DEFAULT_COLORS
if (!defok)
#endif
background = COLOR_BLACK;
if (beforenow != NULL && beforenow != tmpcolor) {
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);
init_pair(tmpcolor->pairnum, tmpcolor->fg, background);
#ifdef DEBUG
fprintf(stderr, _("Running init_pair with fg = %d and bg = %d\n"), tmpcolor->fg, tmpcolor->bg);
#endif
tmpcolor->pairnum = i;
i++;
}
}
return;
}
/* Update the color information based on the current filename */
void update_color(void)
{
syntaxtype *tmpsyntax;
const syntaxtype *tmpsyntax;
colorstrings = NULL;
for (tmpsyntax = syntaxes; tmpsyntax != NULL; tmpsyntax = tmpsyntax->next) {
exttype *e;
const exttype *e;
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 */
if (!regexec(&syntaxfile_regexp, filename, 1, synfilematches, 0))
if (!regexec(&syntaxfile_regexp, filename, 0, NULL, 0))
colorstrings = tmpsyntax->color;
regfree(&syntaxfile_regexp);
if (colorstrings != NULL)
break;
}
}
......
......@@ -125,7 +125,7 @@ shortcut *browser_list = NULL;
#endif
#ifdef ENABLE_COLOR
colortype *colorstrings = NULL;
const colortype *colorstrings = NULL;
syntaxtype *syntaxes = NULL;
char *syntaxstr = NULL;
#endif
......@@ -145,13 +145,6 @@ regex_t search_regexp; /* Global to store compiled search regexp */
regmatch_t regmatches[10]; /* Match positions for parenthetical
subexpressions, max of 10 */
#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)
{
......
......@@ -102,7 +102,8 @@
# because syntax highlighting rules will be applied in the order they are
# read in
# color brightyellow "<[^= ]*>" "\"(\\.|[^\\"])*\""
# color brightyellow "<[^= ]*>" ""(\\.|[^\"])*""
# color brightyellow start=""(\\.|[^\"])*\\( | )*$" end="^(\\.|[^\"])*""
# color brightblue "//.*"
# color brightblue start="/\*" end="\*/"
......
......@@ -71,11 +71,9 @@ extern openfilestruct *open_files;
#endif
#ifdef ENABLE_COLOR
extern colortype *colorstrings;
extern const colortype *colorstrings;
extern syntaxtype *syntaxes;
extern char *syntaxstr;
extern regex_t color_regexp;
extern regmatch_t colormatches[1];
#endif
extern shortcut *shortcut_list;
......@@ -110,6 +108,7 @@ extern toggle *toggles;
/* Public functions in color.c */
#ifdef ENABLE_COLOR
void set_colorpairs(void);
void do_colorinit(void);
void update_color(void);
#endif /* ENABLE_COLOR */
......@@ -401,15 +400,18 @@ void set_modified(void);
void titlebar(const char *path);
void bottombars(const shortcut *s);
void onekey(const char *keystroke, const char *desc, int len);
int get_page_start_virtual(int page);
int get_page_from_virtual(int virtual);
int get_page_end_virtual(int page);
#ifndef NDEBUG
int check_linenumbers(const filestruct *fileptr);
#endif
int get_page_start(int column);
void reset_cursor(void);
void add_marked_sameline(int begin, int end, filestruct *fileptr, int y,
int virt_cur_x, int this_page);
void edit_add(filestruct *fileptr, int yval, int start, int virt_cur_x,
int virt_mark_beginx, int this_page);
void edit_add(const filestruct *fileptr, int yval, int start
#ifndef NANO_SMALL
, int virt_mark_beginx, int virt_cur_x
#endif
);
void update_line(filestruct *fileptr, int index);
void update_cursor(void);
void center_cursor(void);
......
......@@ -631,6 +631,9 @@ void do_rcfile(void)
}
free(nanorc);
#ifdef ENABLE_COLOR
set_colorpairs();
#endif
}
#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