sandy

text editor
git clone git://git.suckless.org/sandy
Log | Files | Refs | README | LICENSE

commit 1c37cdf85cb6e5811439af79e212c141db0dbc91
parent a8b396550ef15a3aae2be283143b2cd3bf5c3f65
Author: Dimitris Zervas <dzervas@dzervas.gr>
Date:   Sun, 13 Jul 2014 05:07:18 +0300

Added support for 256 colors

Diffstat:
config.h | 37++++++++++++++++++++++++++-----------
sandy.c | 8++++++--
2 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/config.h b/config.h @@ -1,3 +1,5 @@ +#include <ncurses.h> + /* A simplified way to customize */ #define HILIGHT_CURRENT 1 #define HILIGHT_SYNTAX 1 @@ -324,6 +326,7 @@ static const Syntax syntaxes[] = { /* LoRed */ "\"(\\\\.|[^\"])*\"", /* LoBlue */ "(//.*|/\\*([^*]|\\*[^/])*\\*/|/\\*([^*]|\\*[^/])*$|^([^/]|/[^*])*\\*/)", } }, + {"java", "\\.java$", { /* HiRed */ B"[A-Z_][0-9A-Z_]+"B, /* HiGreen */ B"(for|if|while|do|else|case|default|switch)"B, @@ -334,6 +337,7 @@ static const Syntax syntaxes[] = { /* LoRed */ "\"(\\\\.|[^\"])*\"", /* LoBlue */ "(//.*|/\\*([^*]|\\*[^/])*\\*/|/\\*([^*]|\\*[^/])*$|^([^/]|/[^*])*\\*/)", } }, + {"ruby", "\\.rb$", { /* HiRed */ "(\\$|@|@@)?"B"[A-Z]+[0-9A-Z_a-z]*", /* HiGreen */ B"(__FILE__|__LINE__|BEGIN|END|alias|and|begin|break|case|class|def|defined\?|do|else|elsif|end|ensure|false|for|if|in|module|next|nil|not|or|redo|rescue|retry|return|self|super|then|true|undef|unless|until|when|while|yield)"B, @@ -349,21 +353,32 @@ static const Syntax syntaxes[] = { #endif /* HILIGHT_SYNTAX */ }; +/* Define colors / +init_color(0x272822, 0x27, 0x28, 0x22); +init_color(0x3E3D32, 0x3E, 0x3D, 0x32); +init_color(0x66D9EF, 0x66, 0xD9, 0xEF); +init_color(0x75715E, 0x75, 0x71, 0x5E); +init_color(0xA6E22E, 0xA6, 0xE2, 0x2E); +init_color(0xE6DB74, 0xE6, 0xDB, 0x74); +init_color(0xF8F8F2, 0xF8, 0xF8, 0xF2); +init_color(0xF92672, 0xF9, 0x26, 0x72); +*/ + /* Colors */ static const short fgcolors[LastFG] = { - [DefFG] = -1, - [CurFG] = (HILIGHT_CURRENT?COLOR_BLACK:-1), - [SelFG] = COLOR_BLACK, + [DefFG] = 0xFFF, // 0xF8F8F2 + [CurFG] = -1, + [SelFG] = -1, [SpcFG] = COLOR_WHITE, [CtrlFG] = COLOR_RED, [Syn0FG] = COLOR_RED, - [Syn1FG] = COLOR_GREEN, - [Syn2FG] = COLOR_GREEN, + [Syn1FG] = 0xF27, // 0xF92672 + [Syn2FG] = 0x6DE, // 0x66D9EF [Syn3FG] = COLOR_MAGENTA, - [Syn4FG] = COLOR_MAGENTA, + [Syn4FG] = 0xAE2, // 0xA6E22E [Syn5FG] = COLOR_BLUE, - [Syn6FG] = COLOR_RED, - [Syn7FG] = COLOR_BLUE, + [Syn6FG] = 0xED7, // 0xE6DB74 + [Syn7FG] = 0x775, // 0x7E8E91 }; static const int colorattrs[LastFG] = { @@ -399,9 +414,9 @@ static const int bwattrs[LastFG] = { }; static const short bgcolors[LastBG] = { - [DefBG] = -1, - [CurBG] = (HILIGHT_CURRENT?COLOR_CYAN:-1), - [SelBG] = COLOR_YELLOW, + [DefBG] = 0x222, // 0x272822 or 0x1B1D1E + [CurBG] = (HILIGHT_CURRENT?0x333:-1), // 0x3E3D32 or 0x293739 + [SelBG] = 0x333, // 0x3E3D32 or 0x293739 }; /* Helper config functions implementation */ diff --git a/sandy.c b/sandy.c @@ -2,8 +2,8 @@ #include <errno.h> #include <fcntl.h> #include <locale.h> -#include <ncurses.h> #include <regex.h> +#include <ncurses.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> @@ -113,7 +113,7 @@ struct Undo { /** Undo information */ /* ENUMS */ /* Colors */ enum { DefFG, CurFG, SelFG, SpcFG, CtrlFG, Syn0FG, Syn1FG, Syn2FG, Syn3FG, Syn4FG, Syn5FG, Syn6FG, Syn7FG, LastFG, }; -enum { DefBG, CurBG, SelBG, /* WARNING: BGs MUST have a matching FG */ LastBG, }; +enum { DefBG, CurBG, SelBG, /* WARNING: BGs MUST have a matching FG */ LastBG, }; /* arg->i to use in f_extsel() */ enum { ExtDefault, ExtWord, ExtLines, ExtAll, }; @@ -1341,6 +1341,10 @@ i_setup(void){ use_default_colors(); for(i=0; i<LastFG; i++) for(j=0; j<LastBG; j++) { + /* Handle more than 8 colors */ + if(fgcolors[i] > 7) init_color(fgcolors[i], fgcolors[i] >> 8, (fgcolors[i] >> 4) & 0xF, fgcolors[i] & 0xFF); + if(bgcolors[i] > 7) init_color(bgcolors[i], bgcolors[i] >> 8, (bgcolors[i] >> 4) & 0xF, bgcolors[i] & 0xFF); + init_pair((i*LastBG)+j, fgcolors[i], bgcolors[j]); textattrs[i][j] = COLOR_PAIR((i*LastBG)+j) | colorattrs[i]; }