aboutsummaryrefslogtreecommitdiff
path: root/project/dclib/dclib-color.c
diff options
context:
space:
mode:
authorWiimm <wiimm@wiimm.de>2021-04-24 09:10:02 +0200
committerWiimm <wiimm@wiimm.de>2021-04-24 09:10:02 +0200
commitf33ad95520f6c6bb8f192c8bcd1c17cf40ba6b6b (patch)
tree60c229f3f17eb965fda2bfa19021559123af65b4 /project/dclib/dclib-color.c
parent4f14fc871ab525488d821e132f80da99841d5646 (diff)
SZS v2.25a
Diffstat (limited to 'project/dclib/dclib-color.c')
-rw-r--r--project/dclib/dclib-color.c823
1 files changed, 520 insertions, 303 deletions
diff --git a/project/dclib/dclib-color.c b/project/dclib/dclib-color.c
index 07e8625..ef0ca01 100644
--- a/project/dclib/dclib-color.c
+++ b/project/dclib/dclib-color.c
@@ -1285,12 +1285,12 @@ static uint grayscale_tab[4] = {0,8,7,15};
const char ColorIndexName[TCI__N][16] =
{
"black",
- "dark_gray_1",
- "dark_gray_2",
- "dark_gray_3",
- "light_gray_1",
- "light_gray_2",
- "light_gray_3",
+ "grey1",
+ "grey2",
+ "grey3",
+ "grey4",
+ "grey5",
+ "grey6",
"white",
"red",
@@ -1323,6 +1323,7 @@ static uint grayscale_tab[4] = {0,8,7,15};
"b_magenta",
"b_magenta_red",
};
+
#else // !SUPPORT_36_COLORS
const char ColorIndexName[TCI__N][11] =
@@ -3062,6 +3063,185 @@ ccp GetTextMode
//
///////////////////////////////////////////////////////////////////////////////
+/////////////// color tables ///////////////
+///////////////////////////////////////////////////////////////////////////////
+// [[color_helper_tab_t]]
+
+typedef struct color_helper_tab_t
+{
+ ccp name;
+ uint offset;
+ bool is_alt;
+}
+color_helper_tab_t;
+
+//-----------------------------------------------------------------------------
+
+#undef JOB0
+#undef JOB1
+#undef JOB2
+#undef SEP1
+
+#define JOB0 {0,0,0}
+#define JOB1(n) { #n, offsetof(ColorSet_t,n), 0 },
+#define JOB2(t,n,a) { #t, offsetof(ColorSet_t,n), a },
+#define SEP1 { EmptyString, 0, 0 },
+
+//-----------------------------------------------------------------------------
+
+static const color_helper_tab_t ch_tab_color[] =
+{
+ SEP1
+ JOB1(red_magenta)
+ JOB1(red)
+ JOB1(red_orange)
+ JOB1(orange_red)
+ JOB1(orange)
+ JOB1(orange_yellow)
+ JOB1(yellow_orange)
+ JOB1(yellow)
+ JOB1(yellow_green)
+ JOB1(green_yellow)
+ JOB1(green)
+ JOB1(green_cyan)
+ JOB1(cyan_green)
+ JOB1(cyan)
+ JOB1(cyan_blue)
+ JOB1(blue_cyan)
+ JOB1(blue)
+ JOB1(blue_magenta)
+ JOB1(magenta_blue)
+ JOB1(magenta)
+ JOB1(magenta_red)
+ JOB0
+};
+
+//-----------------------------------------------------------------------------
+
+static const color_helper_tab_t ch_tab_bcolor[] =
+{
+ SEP1
+ JOB1(b_red_magenta)
+ JOB1(b_red)
+ JOB1(b_red_orange)
+ JOB1(b_orange_red)
+ JOB1(b_orange)
+ JOB1(b_orange_yellow)
+ JOB1(b_yellow_orange)
+ JOB1(b_yellow)
+ JOB1(b_yellow_green)
+ JOB1(b_green_yellow)
+ JOB1(b_green)
+ JOB1(b_green_cyan)
+ JOB1(b_cyan_green)
+ JOB1(b_cyan)
+ JOB1(b_cyan_blue)
+ JOB1(b_blue_cyan)
+ JOB1(b_blue)
+ JOB1(b_blue_magenta)
+ JOB1(b_magenta_blue)
+ JOB1(b_magenta)
+ JOB1(b_magenta_red)
+ JOB0
+};
+
+//-----------------------------------------------------------------------------
+_Static_assert( N_COLORSET_GREY == 10, "wrong N_COLORSET_GREY" );
+
+static const color_helper_tab_t ch_tab_grey[] =
+{
+ SEP1
+ JOB1(black)
+ JOB1(b_black)
+ JOB1(white)
+ JOB1(b_white)
+
+ SEP1
+ JOB2(grey0,grey[0],0)
+ JOB2(grey1,grey[1],0)
+ JOB2(grey2,grey[2],0)
+ JOB2(grey3,grey[3],0)
+ JOB2(grey4,grey[4],0)
+ JOB2(grey5,grey[5],0)
+ JOB2(grey6,grey[6],0)
+ JOB2(grey7,grey[7],0)
+ JOB2(grey8,grey[8],0)
+ JOB2(grey9,grey[9],0)
+
+ JOB0
+};
+
+//-----------------------------------------------------------------------------
+
+static const color_helper_tab_t ch_tab_name[] =
+{
+ SEP1
+
+ JOB1(setup)
+ JOB1(run)
+ JOB1(abort)
+ JOB1(finish)
+ JOB1(script)
+ JOB1(open)
+ JOB1(close)
+ JOB1(file)
+ JOB1(job)
+
+ JOB1(info)
+ JOB1(hint)
+ JOB1(warn)
+ JOB1(debug)
+ JOB1(log)
+
+ JOB1(name)
+ JOB1(op)
+ JOB1(value)
+ JOB2(val,value,1)
+ JOB1(success)
+ JOB1(error)
+ JOB1(fail)
+ JOB1(fail2)
+ JOB1(fatal)
+ JOB1(mark)
+ JOB1(bad)
+
+ JOB1(select)
+ JOB1(differ)
+ JOB1(stat_line)
+ JOB1(warn_line)
+ JOB1(proc_line)
+ JOB1(cite)
+ JOB1(status)
+ JOB1(highlight)
+ JOB2(hl,highlight,1)
+ JOB1(hide)
+
+ JOB1(heading)
+ JOB2(head,heading,1)
+ JOB1(caption)
+ JOB1(section)
+ JOB1(syntax)
+ JOB1(cmd)
+ JOB1(option)
+ JOB2(opt,option,1)
+ JOB1(param)
+ JOB2(par,param,1)
+
+ JOB1(off)
+ JOB1(on)
+
+ JOB0
+};
+
+//-----------------------------------------------------------------------------
+
+#undef JOB0
+#undef JOB1
+#undef JOB2
+#undef SEP1
+
+//
+///////////////////////////////////////////////////////////////////////////////
/////////////// colors ///////////////
///////////////////////////////////////////////////////////////////////////////
@@ -3147,40 +3327,66 @@ const ColorSet_t * GetColorSet8()
col.on = STRDUP(GetTextMode(1,TTM_COL_ON));
col.off = STRDUP(GetTextMode(1,TTM_COL_OFF));
+ _Static_assert( N_COLORSET_GREY == 10, "wrong N_COLORSET_GREY" );
+
+ col.grey[0] =
+ col.grey[1] =
col.black = STRDUP(GetTextMode(1,TTM_NO_BOLD|TTM_BLACK));
+ col.grey[2] =
+ col.grey[3] =
+ col.grey[4] =
col.b_black = STRDUP(GetTextMode(1,TTM_BOLD|TTM_BLACK));
+ col.grey[5] =
+ col.grey[6] =
+ col.grey[7] =
col.white = STRDUP(GetTextMode(1,TTM_NO_BOLD|TTM_WHITE));
+ col.grey[8] =
+ col.grey[9] =
col.b_white = STRDUP(GetTextMode(1,TTM_BOLD|TTM_WHITE));
- col.red = STRDUP(GetTextMode(1,TTM_NO_BOLD|TTM_RED));
- col.red_orange = col.red;
- col.orange = col.red;
- col.yellow = STRDUP(GetTextMode(1,TTM_NO_BOLD|TTM_YELLOW));
- col.orange_yellow = col.yellow;
- col.yellow_green = col.yellow;
- col.green = STRDUP(GetTextMode(1,TTM_NO_BOLD|TTM_GREEN));
- col.green_cyan = col.green;
- col.cyan = STRDUP(GetTextMode(1,TTM_NO_BOLD|TTM_CYAN));
- col.cyan_blue = col.cyan;
- col.blue = STRDUP(GetTextMode(1,TTM_NO_BOLD|TTM_BLUE));
- col.blue_magenta = col.blue;
- col.magenta = STRDUP(GetTextMode(1,TTM_NO_BOLD|TTM_MAGENTA));
- col.magenta_red = col.magenta;
+ col.red_magenta =
+ col.red =
+ col.red_orange =
+ col.orange_red =
+ col.orange =
+ col.orange_yellow = STRDUP(GetTextMode(1,TTM_NO_BOLD|TTM_RED));
+ col.yellow_orange =
+ col.yellow =
+ col.yellow_green = STRDUP(GetTextMode(1,TTM_NO_BOLD|TTM_YELLOW));
+ col.green_yellow =
+ col.green =
+ col.green_cyan = STRDUP(GetTextMode(1,TTM_NO_BOLD|TTM_GREEN));
+ col.cyan_green =
+ col.cyan =
+ col.cyan_blue = STRDUP(GetTextMode(1,TTM_NO_BOLD|TTM_CYAN));
+ col.blue_cyan =
+ col.blue =
+ col.blue_magenta = STRDUP(GetTextMode(1,TTM_NO_BOLD|TTM_BLUE));
+ col.magenta_blue =
+ col.magenta =
+ col.magenta_red = STRDUP(GetTextMode(1,TTM_NO_BOLD|TTM_MAGENTA));
- col.b_red = STRDUP(GetTextMode(1,TTM_BOLD|TTM_RED));
- col.b_red_orange = col.b_red;
- col.b_orange = col.b_red;
- col.b_yellow = STRDUP(GetTextMode(1,TTM_BOLD|TTM_YELLOW));
- col.b_orange_yellow = col.b_yellow;
- col.b_yellow_green = col.b_yellow;
- col.b_green = STRDUP(GetTextMode(1,TTM_BOLD|TTM_GREEN));
- col.b_green_cyan = col.b_green;
- col.b_cyan = STRDUP(GetTextMode(1,TTM_BOLD|TTM_CYAN));
- col.b_cyan_blue = col.b_cyan;
- col.b_blue = STRDUP(GetTextMode(1,TTM_BOLD|TTM_BLUE));
- col.b_blue_magenta = col.b_blue;
- col.b_magenta = STRDUP(GetTextMode(1,TTM_BOLD|TTM_MAGENTA));
- col.b_magenta_red = col.b_magenta;
+ col.b_red_magenta =
+ col.b_red =
+ col.b_red_orange =
+ col.b_orange_red =
+ col.b_orange =
+ col.b_orange_yellow = STRDUP(GetTextMode(1,TTM_BOLD|TTM_RED));
+ col.b_yellow_orange =
+ col.b_yellow =
+ col.b_yellow_green = STRDUP(GetTextMode(1,TTM_BOLD|TTM_YELLOW));
+ col.b_green_yellow =
+ col.b_green =
+ col.b_green_cyan = STRDUP(GetTextMode(1,TTM_BOLD|TTM_GREEN));
+ col.b_cyan_green =
+ col.b_cyan =
+ col.b_cyan_blue = STRDUP(GetTextMode(1,TTM_BOLD|TTM_CYAN));
+ col.b_blue_cyan =
+ col.b_blue =
+ col.b_blue_magenta = STRDUP(GetTextMode(1,TTM_BOLD|TTM_BLUE));
+ col.b_magenta_blue =
+ col.b_magenta =
+ col.b_magenta_red = STRDUP(GetTextMode(1,TTM_BOLD|TTM_MAGENTA));
TermColorIndex_t font, bg;
for ( font = 0; font < TCI__N_FONT; font++ )
@@ -3238,18 +3444,25 @@ const ColorSet_t * GetColorSet256()
// ./mkw-ana testcol 400-420 420-330 330-030 030-033 033-005 005-404 404-400
// ./mkw-ana testcol 400 410 420 320 330 230 030 032 033 024 005 204 404 402 400
+ col.red_magenta = "\e[38;5;161m";
col.red = "\e[38;5;160m";
- col.red_orange = "\e[38;5;166m";
+ col.red_orange =
+ col.orange_red = "\e[38;5;166m";
col.orange = "\e[38;5;172m";
- col.orange_yellow = "\e[38;5;136m";
+ col.orange_yellow =
+ col.yellow_orange = "\e[38;5;136m";
col.yellow = "\e[38;5;142m";
col.yellow_green = "\e[38;5;106m";
+ col.green_yellow = "\e[38;5;70m";
col.green = "\e[38;5;34m";
- col.green_cyan = "\e[38;5;36m";
+ col.green_cyan = "\e[38;5;35m";
+ col.cyan_green = "\e[38;5;36m";
col.cyan = "\e[38;5;37m";
col.cyan_blue = "\e[38;5;32m";
+ col.blue_cyan = "\e[38;5;27m";
col.blue = "\e[38;5;21m";
col.blue_magenta = "\e[38;5;92m";
+ col.magenta_blue = "\e[38;5;128m";
col.magenta = "\e[38;5;164m";
col.magenta_red = "\e[38;5;162m";
@@ -3257,20 +3470,39 @@ const ColorSet_t * GetColorSet256()
// ./mkw-ana testcol 500-520 520-550 550-050 050-055 055-225 225-515 515-500
// ./mkw-ana testcol 500 510 520 530 550 350 050 053 055 135 225 425 515 512 500
+ col.b_red_magenta = "\e[38;5;198m";
col.b_red = "\e[38;5;196m";
- col.b_red_orange = "\e[38;5;202m";
+ col.b_red_orange =
+ col.b_orange_red = "\e[38;5;202m";
col.b_orange = "\e[38;5;208m";
col.b_orange_yellow = "\e[38;5;214m";
+ col.b_yellow_orange = "\e[38;5;220m";
col.b_yellow = "\e[38;5;226m";
col.b_yellow_green = "\e[38;5;154m";
+ col.b_green_yellow = "\e[38;5;118m";
col.b_green = "\e[38;5;46m";
col.b_green_cyan = "\e[38;5;49m";
+ col.b_cyan_green = "\e[38;5;50m";
col.b_cyan = "\e[38;5;51m";
col.b_cyan_blue = "\e[38;5;75m";
+ col.b_blue_cyan = "\e[38;5;111m";
col.b_blue = "\e[38;5;105m";
- col.b_blue_magenta = "\e[38;5;177m";
+ col.b_blue_magenta = "\e[38;5;141m";
+ col.b_magenta_blue = "\e[38;5;177m";
col.b_magenta = "\e[38;5;207m";
- col.b_magenta_red = "\e[38;5;204m";
+ col.b_magenta_red = "\e[38;5;205m";
+
+ _Static_assert( N_COLORSET_GREY == 10, "wrong N_COLORSET_GREY" );
+ col.grey[0] = "\e[38;5;232m";
+ col.grey[1] = "\e[38;5;235m"; //x
+ col.grey[2] = "\e[38;5;237m";
+ col.grey[3] = "\e[38;5;240m"; //x
+ col.grey[4] = "\e[38;5;242m";
+ col.grey[5] = "\e[38;5;245m"; //x
+ col.grey[6] = "\e[38;5;247m";
+ col.grey[7] = "\e[38;5;250m"; //x
+ col.grey[8] = "\e[38;5;252m";
+ col.grey[9] = "\e[38;5;255m"; //x
TermColorIndex_t font, bg;
for ( font = 0; font < TCI__N_FONT; font++ )
@@ -3317,7 +3549,7 @@ const ColorSet_t * GetColorSetAuto ( bool force_on )
if ( auto_mode == COLMD_AUTO )
{
char *term = getenv("TERM");
-
+
#ifdef __CYGWIN__
if (!term)
term = "cygwin";
@@ -3416,23 +3648,31 @@ ccp GetColorByName ( const ColorSet_t *colset, ccp name )
DEF1(abort)
DEF1(b_black)
DEF1(b_blue)
+ DEF1(b_blue_cyan)
DEF1(b_blue_magenta)
DEF1(b_cyan)
DEF1(b_cyan_blue)
+ DEF1(b_cyan_green)
DEF1(b_green)
DEF1(b_green_cyan)
+ DEF1(b_green_yellow)
DEF1(b_magenta)
+ DEF1(b_magenta_blue)
DEF1(b_magenta_red)
DEF1(b_orange)
+ DEF1(b_orange_red)
DEF1(b_orange_yellow)
DEF1(b_red)
+ DEF1(b_red_magenta)
DEF1(b_red_orange)
DEF1(b_white)
DEF1(b_yellow)
DEF1(b_yellow_green)
+ DEF1(b_yellow_orange)
DEF1(bad)
DEF1(black)
DEF1(blue)
+ DEF1(blue_cyan)
DEF1(blue_magenta)
DEF1(caption)
DEF1(cite)
@@ -3440,6 +3680,7 @@ ccp GetColorByName ( const ColorSet_t *colset, ccp name )
DEF1(cmd)
DEF1(cyan)
DEF1(cyan_blue)
+ DEF1(cyan_green)
DEF1(debug)
DEF1(differ)
DEF1(error)
@@ -3448,8 +3689,29 @@ ccp GetColorByName ( const ColorSet_t *colset, ccp name )
DEF1(fatal)
DEF1(file)
DEF1(finish)
+ DEF2(gray0,grey[0])
+ DEF2(gray1,grey[1])
+ DEF2(gray2,grey[2])
+ DEF2(gray3,grey[3])
+ DEF2(gray4,grey[4])
+ DEF2(gray5,grey[5])
+ DEF2(gray6,grey[6])
+ DEF2(gray7,grey[7])
+ DEF2(gray8,grey[8])
+ DEF2(gray9,grey[9])
DEF1(green)
DEF1(green_cyan)
+ DEF1(green_yellow)
+ DEF2(grey0,grey[0])
+ DEF2(grey1,grey[1])
+ DEF2(grey2,grey[2])
+ DEF2(grey3,grey[3])
+ DEF2(grey4,grey[4])
+ DEF2(grey5,grey[5])
+ DEF2(grey6,grey[6])
+ DEF2(grey7,grey[7])
+ DEF2(grey8,grey[8])
+ DEF2(grey9,grey[9])
DEF2(head,heading)
DEF1(heading)
DEF1(hide)
@@ -3460,6 +3722,7 @@ ccp GetColorByName ( const ColorSet_t *colset, ccp name )
DEF1(job)
DEF1(log)
DEF1(magenta)
+ DEF1(magenta_blue)
DEF1(magenta_red)
DEF1(mark)
DEF1(name)
@@ -3470,11 +3733,13 @@ ccp GetColorByName ( const ColorSet_t *colset, ccp name )
DEF2(opt,option)
DEF1(option)
DEF1(orange)
+ DEF1(orange_red)
DEF1(orange_yellow)
DEF2(par,param)
DEF1(param)
DEF1(proc_line)
DEF1(red)
+ DEF1(red_magenta)
DEF1(red_orange)
DEF1(reset)
DEF1(run)
@@ -3493,6 +3758,7 @@ ccp GetColorByName ( const ColorSet_t *colset, ccp name )
DEF1(white)
DEF1(yellow)
DEF1(yellow_green)
+ DEF1(yellow_orange)
};
#if HAVE_PRINT
@@ -3546,135 +3812,179 @@ ccp GetColorByName ( const ColorSet_t *colset, ccp name )
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
+// [[color_helper_t]]
-void PrintColorSetHelper
-(
- FILE *f, // valid output file
- int indent, // indention of output
- const ColorSet_t *cs, // valid color set; if NULL: use std colors
- PrintColorFunc func, // output function, never NULL
- uint mode // output mode (bit field, NULL=default):
- // 1: print normal colors (e.g. RED)
- // 2: print bold colors (e.g. B_RED)
- // 4: print background (e.g. BLUE_RED)
- // 8: print color names (e.g. HIGHLIGHT)
- // 16: include alternative names too (e.g. HL)
-)
+typedef struct color_helper_t
{
- // [[new-color]]
+ FILE *f; // valid output file
+ int indent; // indention of output
+ const ColorSet_t *cs; // valid color set; if NULL: use std colors
+ PrintColorFunc func; // output function, never NULL
+ ColorSelect_t select; // select color groups
+ int multi_assign; // >0: Allow A=B="..."; >1: reorder records too
+ bool print_alt; // print alternative names
+ bool allow_sep; // allow separator lines
- DASSERT(f);
- DASSERT(func);
+ StringField_t sf; // collect strings hre if multi_assign>1
+}
+color_helper_t;
- if (!cs)
- cs = GetColorSet(COLMD_ON);
- indent = NormalizeIndent(indent) + 10; // +10 is max name width
- if (!mode)
- mode = 15;
+//-----------------------------------------------------------------------------
- #undef JOB1
- #undef JOB2
- #define JOB1(m,n) func(f,indent,cs,m,#n,cs->n)
- #define JOB2(m,t,n) func(f,indent,cs,m,#t,cs->n)
+static void print_by_helper_tab
+(
+ color_helper_t *ch, // valid param
+ const color_helper_tab_t *tab // valid color list
+)
+{
+ DASSERT(ch);
+ DASSERT(tab);
- if ( mode & 1 )
+ const ColorSet_t *col = ch->cs;
+ if ( ch->multi_assign <= 0 )
{
- func(f,indent,cs,1,0,0);
- JOB1(1,black);
- JOB1(1,red);
- JOB1(1,red_orange);
- JOB1(1,orange);
- JOB1(1,orange_yellow);
- JOB1(1,yellow);
- JOB1(1,yellow_green);
- JOB1(1,green);
- JOB1(1,green_cyan);
- JOB1(1,cyan);
- JOB1(1,cyan_blue);
- JOB1(1,blue);
- JOB1(1,blue_magenta);
- JOB1(1,magenta);
- JOB1(1,magenta_red);
- JOB1(1,white);
+ for ( ; tab->name; tab++ )
+ {
+ if ( !tab->is_alt || ch->print_alt )
+ {
+ if (tab->offset)
+ {
+ ch->allow_sep = true;
+ ch->func( ch->f, ch->indent, col,
+ tab->name, *(ccp*)((u8*)col+tab->offset) );
+ }
+ else if (ch->allow_sep)
+ {
+ ch->allow_sep = false;
+ ch->func(ch->f,ch->indent,col,0,0);
+ }
+ }
+ }
+ return;
}
- if ( mode & 2 )
+ //-------------------------------------------------------------------------
+
+ if ( ch->multi_assign > 1 )
{
- func(f,indent,cs,2,0,0);
- JOB1(2,b_black);
- JOB1(2,b_red);
- JOB1(2,b_red_orange);
- JOB1(2,b_orange);
- JOB1(2,b_orange_yellow);
- JOB1(2,b_yellow);
- JOB1(2,b_yellow_green);
- JOB1(2,b_green);
- JOB1(2,b_green_cyan);
- JOB1(2,b_cyan);
- JOB1(2,b_cyan_blue);
- JOB1(2,b_blue);
- JOB1(2,b_blue_magenta);
- JOB1(2,b_magenta);
- JOB1(2,b_magenta_red);
- JOB1(2,b_white);
+ char key[100];
+ for ( ; tab->name; tab++ )
+ {
+ if ( tab->offset && ( !tab->is_alt || ch->print_alt ))
+ {
+ snprintf(key,sizeof(key),"%s\1%s",*(ccp*)((u8*)col+tab->offset),tab->name);
+ InsertStringField(&ch->sf,key,false);
+ }
+ }
+ return;
}
- if ( mode & 8 )
+ //-------------------------------------------------------------------------
+ // ch->multi_assign == 1
+
+ // skip separators
+ while ( tab->name && ( !tab->offset || !( !tab->is_alt || ch->print_alt )))
+ tab++;
+
+ while (tab->name)
{
- const bool alt = ( mode & 16 ) != 0;
- func(f,indent,cs,8,0,0);
+ bool have_next = false;
+ const color_helper_tab_t *next = tab+1;
+ for ( ; next->name; next++ )
+ {
+ if ( next->offset && ( !next->is_alt || ch->print_alt ))
+ {
+ have_next = true;
+ break;
+ }
+ }
+ ccp val = *(ccp*)((u8*)col+tab->offset);
+ if ( have_next && !strcmp(val,*(ccp*)((u8*)col+next->offset)) )
+ val = 0;
+ ch->func( ch->f, ch->indent, col, tab->name, val );
+ if (!have_next)
+ break;
+ tab = next;
+ }
+};
- JOB1(4,setup);
- JOB1(4,run);
- JOB1(4,abort);
- JOB1(4,finish);
- JOB1(4,script);
- JOB1(4,open);
- JOB1(4,close);
- JOB1(4,file);
- JOB1(4,job);
+//-----------------------------------------------------------------------------
+
+void PrintColorSetHelper2
+(
+ color_helper_t *ch // valid params
+)
+{
+ // [[new-color]]
- JOB1(4,info);
- JOB1(4,hint);
- JOB1(4,warn);
- JOB1(4,debug);
- JOB1(4,log);
+ DASSERT(ch);
+ DASSERT(ch->f);
+ DASSERT(ch->func);
- JOB1(4,name);
- JOB1(4,op);
- JOB1(4,value); if (alt) JOB2(12,val,value);
- JOB1(4,success);
- JOB1(4,error);
- JOB1(4,fail);
- JOB1(4,fail2);
- JOB1(4,fatal);
- JOB1(4,mark);
- JOB1(4,bad);
+ if (!ch->cs)
+ ch->cs = GetColorSet(COLMD_ON);
+ ch->indent = NormalizeIndent(ch->indent) + 15; // 15 is max name width
- JOB1(4,select);
- JOB1(4,differ);
- JOB1(4,stat_line);
- JOB1(4,warn_line);
- JOB1(4,proc_line);
- JOB1(4,cite);
- JOB1(4,status);
- JOB1(4,highlight); if (alt) JOB2(12,hl,highlight);
- JOB1(4,hide);
+ if ( !ch->select )
+ ch->select = COLSEL_M_MODE;
+ ch->print_alt = ( ch->select & COLSEL_F_ALT ) != 0;
+ ch->allow_sep = true;
- JOB1(4,heading); if (alt) JOB2(12,head,heading);
- JOB1(4,caption);
- JOB1(4,section);
- JOB1(4,syntax);
- JOB1(4,cmd);
- JOB1(4,option); if (alt) JOB2(12,opt,option);
- JOB1(4,param); if (alt) JOB2(12,par,param);
+ if ( ch->multi_assign > 1 )
+ InitializeStringField(&ch->sf);
- JOB1(4,off);
- JOB1(4,on);
+ if ( ch->select & COLSEL_COLOR )
+ print_by_helper_tab(ch,ch_tab_color);
+
+ if ( ch->select & COLSEL_B_COLOR )
+ print_by_helper_tab(ch,ch_tab_bcolor);
+
+ if ( ch->select & COLSEL_GREY )
+ print_by_helper_tab(ch,ch_tab_grey);
+
+ if ( ch->select & COLSEL_NAME )
+ print_by_helper_tab(ch,ch_tab_name);
+
+ if ( ch->multi_assign > 1 )
+ {
+ ccp *ptr, *end = ch->sf.field + ch->sf.used;
+ for ( ptr = ch->sf.field; ptr < end; ptr++ )
+ {
+ ccp val = *ptr;
+ char *name = strchr(val,'\1');
+ if (!name) continue; // this may never happen!!
+ if ( ptr+1 < end && !memcmp(val,ptr[1],name-val+1) )
+ val = 0;
+ *name++ = 0;
+ ch->func( ch->f, ch->indent, ch->cs, name, val );
+ }
+ ResetStringField(&ch->sf);
}
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
- #undef JOB1
- #undef JOB2
+void PrintColorSetHelper
+(
+ FILE *f, // valid output file
+ int indent, // indention of output
+ const ColorSet_t *cs, // valid color set; if NULL: use std colors
+ PrintColorFunc func, // output function, never NULL
+ ColorSelect_t select, // select color groups
+ int multi_assign // >0: Allow A=B="..."; >1: reorder records too
+)
+{
+ color_helper_t ch =
+ {
+ .f = f,
+ .indent = indent,
+ .cs = cs,
+ .func = func,
+ .select = select,
+ .multi_assign = multi_assign,
+ };
+ PrintColorSetHelper2(&ch);
}
///////////////////////////////////////////////////////////////////////////////
@@ -3686,7 +3996,6 @@ static void PrintColorSetCOL
FILE *f, // valid output file
int indent, // normalized indention of output
const ColorSet_t *cs, // valid color set, never NULL
- uint mode, // output mode of PrintColorSetHelper()
ccp col_name, // name of color
ccp col_string // escape string for the color
)
@@ -3716,7 +4025,6 @@ static void PrintColorSetSH
FILE *f, // valid output file
int indent, // normalized indention of output
const ColorSet_t *cs, // valid color set, never NULL
- uint mode, // output mode of PrintColorSetHelper()
ccp col_name, // name of color
ccp col_string // escape string for the color
)
@@ -3748,23 +4056,25 @@ static void PrintColorSetPHP
FILE *f, // valid output file
int indent, // normalized indention of output
const ColorSet_t *cs, // valid color set, never NULL
- uint mode, // output mode of PrintColorSetHelper()
ccp col_name, // name of color
ccp col_string // escape string for the color
)
{
- if (col_name)
+ if ( col_name )
{
- DASSERT(col_string);
-
- fprintf(f," $COL->%s%.*s= ", col_name, (29-(int)strlen(col_name))/8, Tabs20 );
+ fprintf(f," $COL->%s%.*s=", col_name, (29-(int)strlen(col_name))/8, Tabs20 );
- char buf[50];
- PrintEscapedString(buf,sizeof(buf),col_string,-1,CHMD_ESC,0,0);
- if (memcmp(buf,"\\x1B",4))
- fprintf(f,"\"%s\";\n",buf);
+ if (col_string)
+ {
+ char buf[50];
+ PrintEscapedString(buf,sizeof(buf),col_string,-1,CHMD_ESC,0,0);
+ if (memcmp(buf,"\\x1B",4))
+ fprintf(f," \"%s\";\n",buf);
+ else
+ fprintf(f," \"\\033%s\";\n",buf+4);
+ }
else
- fprintf(f,"\"\\033%s\";\n",buf+4);
+ fputc('\n',f);
}
}
@@ -3774,22 +4084,8 @@ void PrintColorSet
(
FILE *f, // valid output file
int indent, // indention of output
- const ColorSet_t *cs // valid color set; if NULL: use std colors
-)
-{
- DASSERT(f);
- PrintColorSetHelper(f,indent,cs,PrintColorSetCOL,4);
- fputc('\n',f);
-}
-
-//-----------------------------------------------------------------------------
-
-void PrintColorSetEx
-(
- FILE *f, // valid output file
- int indent, // indention of output
const ColorSet_t *cs, // valid color set; if NULL: use std colors
- uint mode, // output mode => see PrintColorSetHelper()
+ ColorSelect_t select, // select color groups
uint format // output format
// 0: colored list
// 1: shell definitions
@@ -3804,7 +4100,7 @@ void PrintColorSetEx
case 1:
if (!cs)
cs = GetColorSet(COLMD_ON);
- PrintColorSetHelper(f,indent,cs,PrintColorSetSH,mode);
+ PrintColorSetHelper(f,indent,cs,PrintColorSetSH,select,0);
PrintEscapedString(buf,sizeof(buf),cs->reset,-1,CHMD_ESC,0,0);
if (memcmp(buf,"\\x1B",4))
fprintf(f,"COL0=$'%s'\n",buf);
@@ -3815,11 +4111,11 @@ void PrintColorSetEx
case 2:
if (!cs)
cs = GetColorSet(COLMD_ON);
- PrintColorSetHelper(f,indent,cs,PrintColorSetPHP,mode);
+ PrintColorSetHelper(f,indent,cs,PrintColorSetPHP,select,2);
break;
default:
- PrintColorSetHelper(f,indent,cs,PrintColorSetCOL,mode);
+ PrintColorSetHelper(f,indent,cs,PrintColorSetCOL,select,0);
fputc('\n',f);
break;
}
@@ -3857,6 +4153,8 @@ void SetupColorView ( ColorView_t *cv )
case 'g': case 'G': cv->order = 1; break;
case 'b': case 'B': cv->order = 2; break;
}
+
+ cv->allow_sep = false;
}
///////////////////////////////////////////////////////////////////////////////
@@ -4221,26 +4519,42 @@ void ViewColors256 ( ColorView_t *cv )
static void ViewColorsPredef_helper
(
- ColorView_t *cv, // basic data
- ccp col_name, // name of color
- ccp col_string // escape string for the color
+ ColorView_t *cv, // basic data
+ const color_helper_tab_t *tab // valid color list
)
{
DASSERT(cv);
- DASSERT(col_string);
+ DASSERT(tab);
- if ( col_string && *col_string )
- fprintf(cv->f,"%*s %s %-15s %s \\e%s\n",
- cv->indent, col_name, col_string, col_name,
- cv->colset->reset, col_string+1 );
- else
- fprintf(cv->f,"%*s %s\n",
- cv->indent, col_name, col_name );
+ const ColorSet_t *col = cv->colset;
+
+ for ( ; tab->name; tab++ )
+ {
+ if ( !tab->is_alt || cv->print_alt )
+ {
+ if (tab->offset)
+ {
+ cv->allow_sep = true;
+ ccp val = *(ccp*)((u8*)col+tab->offset);
+ if (*val)
+ fprintf(cv->f,"%*s %s %-15s %s \\e%s\n",
+ cv->indent, tab->name, val, tab->name, col->reset, val+1 );
+ else
+ fprintf(cv->f,"%*s %s %-15s %s\n",
+ cv->indent, tab->name, val, tab->name, col->reset );
+ }
+ else if (cv->allow_sep)
+ {
+ cv->allow_sep = false;
+ fputc('\n',cv->f);
+ }
+ }
+ }
}
//-----------------------------------------------------------------------------
-void ViewColorsPredef ( ColorView_t *cv, uint mode )
+void ViewColorsPredef ( ColorView_t *cv, ColorSelect_t colsel )
{
// [[new-color]]
@@ -4248,128 +4562,31 @@ void ViewColorsPredef ( ColorView_t *cv, uint mode )
SetupColorView(cv);
DASSERT(cv->colset);
- #ifdef TEST
- fprintf(cv->f,"%*s%s() %s, %u colors, mode %d, stdcol %d, order %d\n",
- cv->indent,"", __FUNCTION__,
- GetColorModeName(cv->colset->col_mode,0),
- cv->colset->n_colors, cv->mode, cv->std_col, cv->order );
- #endif
+ if ( !colsel )
+ colsel = COLSEL_M_MODE;
+ cv->print_alt = ( colsel & COLSEL_F_ALT ) != 0;
+
+ cv->indent += 15; // 15 is max name width
fprintf(cv->f,
"%s\n%*sPredefined%s color names for mode %s:\n\n",
cv->colset->reset, cv->indent, "",
- ( mode & 3 ) == 1 ? " semantic" : "",
+ ( colsel & COLSEL_M_MODE ) == COLSEL_NAME ? " semantic" : "",
GetColorModeName(cv->col_mode,0) );
- cv->indent += 14;
-
- #undef JOB1
- #undef JOB2
- #define JOB1(n) ViewColorsPredef_helper(cv,#n,cv->colset->n)
- #define JOB2(n,c) ViewColorsPredef_helper(cv,#n,cv->colset->c)
-
- if ( mode & 1 )
- {
- const bool alt = cv->mode & 1;
-
- JOB1(setup);
- JOB1(run);
- JOB1(abort);
- JOB1(finish);
- JOB1(script);
- JOB1(open);
- JOB1(close);
- JOB1(file);
- JOB1(job);
-
- JOB1(info);
- JOB1(hint);
- JOB1(warn);
- JOB1(debug);
- JOB1(log);
+ if ( colsel & COLSEL_NAME )
+ ViewColorsPredef_helper(cv,ch_tab_name);
- JOB1(name);
- JOB1(op);
- JOB1(value); if (alt) JOB2(val,value);
- JOB1(success);
- JOB1(error);
- JOB1(fail);
- JOB1(fail2);
- JOB1(fatal);
- JOB1(mark);
- JOB1(bad);
+ if ( colsel & COLSEL_COLOR )
+ ViewColorsPredef_helper(cv,ch_tab_color);
- JOB1(select);
- JOB1(differ);
- JOB1(stat_line);
- JOB1(warn_line);
- JOB1(proc_line);
- JOB1(cite);
- JOB1(status);
- JOB1(highlight); if (alt) JOB2(hl,highlight);
- JOB1(hide);
+ if ( colsel & COLSEL_B_COLOR )
+ ViewColorsPredef_helper(cv,ch_tab_bcolor);
- JOB1(heading);
- JOB1(caption);
- JOB1(section);
- JOB1(syntax);
- JOB1(cmd);
- JOB1(option); if (alt) JOB2(opt,option);
- JOB1(param); if (alt) JOB2(par,param);
-
- JOB1(off);
- JOB1(on);
- }
-
- if ( mode & 2 )
- {
- if ( mode & 1 )
- fputc('\n',cv->f);
- JOB1(black);
- JOB1(b_black);
- JOB1(white);
- JOB1(b_white);
-
- if ( !(mode & 1) )
- fputc('\n',cv->f);
- JOB1(red);
- JOB1(red_orange);
- JOB1(orange);
- JOB1(orange_yellow);
- JOB1(yellow);
- JOB1(yellow_green);
- JOB1(green);
- JOB1(green_cyan);
- JOB1(cyan);
- JOB1(cyan_blue);
- JOB1(blue);
- JOB1(blue_magenta);
- JOB1(magenta);
- JOB1(magenta_red);
- JOB1(red);
-
- if ( !(mode & 1) )
- fputc('\n',cv->f);
- JOB1(b_red);
- JOB1(b_red_orange);
- JOB1(b_orange);
- JOB1(b_orange_yellow);
- JOB1(b_yellow);
- JOB1(b_yellow_green);
- JOB1(b_green);
- JOB1(b_green_cyan);
- JOB1(b_cyan);
- JOB1(b_cyan_blue);
- JOB1(b_blue);
- JOB1(b_blue_magenta);
- JOB1(b_magenta);
- JOB1(b_magenta_red);
- JOB1(b_red);
- }
+ if ( colsel & COLSEL_GREY )
+ ViewColorsPredef_helper(cv,ch_tab_grey);
- #undef JOB1
- #undef JOB2
- cv->indent -= 14;
+ cv->indent -= 15;
}
//