From 986678ce66bb5aa8d74d70809f3ed2c0c4cc8986 Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Sun, 17 Jul 2016 18:59:07 +0530 Subject: [PATCH] tweaks: add new variable for streamlining the code Add a new variable attributes in struct colortype. It plays the role of amalgamation of brightness and pairnum, with which we paint our text. Addition of this variable makes writing the code more simpler. Signed-off-by: Rishabh Dave --- src/color.c | 3 +++ src/nano.h | 3 +++ src/winio.c | 7 ++----- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/color.c b/src/color.c index 3f5ae67..06d385c 100644 --- a/src/color.c +++ b/src/color.c @@ -97,6 +97,9 @@ void set_colorpairs(void) this_color->pairnum = clr_pair; clr_pair++; } + + this_color->attributes = COLOR_PAIR(this_color->pairnum) + | (this_color->bright ? A_BOLD : A_NORMAL); } } } diff --git a/src/nano.h b/src/nano.h index ff880d8..80fed0a 100644 --- a/src/nano.h +++ b/src/nano.h @@ -210,6 +210,9 @@ typedef struct colortype { int pairnum; /* The color pair number used for this foreground color and * background color. */ + int attributes; + /* Attributes, an amalgamataion of pair number and brightness + * (when bright is TRUE), with which text will be painted. */ int rex_flags; /* The regex compilation flags (with or without REG_ICASE). */ char *start_regex; diff --git a/src/winio.c b/src/winio.c index e96f6e9..24274ab 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2252,9 +2252,7 @@ void edit_draw(filestruct *fileptr, const char *converted, int regmatch_t endmatch; /* Match position for end_regex. */ - if (varnish->bright) - wattron(edit, A_BOLD); - wattron(edit, COLOR_PAIR(varnish->pairnum)); + wattron(edit, varnish->attributes); /* Two notes about regexec(). A return value of zero means * that there is a match. Also, rm_eo is the first * non-matching character after the match. */ @@ -2511,8 +2509,7 @@ void edit_draw(filestruct *fileptr, const char *converted, int } } tail_of_loop: - wattroff(edit, A_BOLD); - wattroff(edit, COLOR_PAIR(varnish->pairnum)); + wattroff(edit, varnish->attributes); } } #endif /* !DISABLE_COLOR */ -- 2.9.1