Prepare for per-cell configurable colors

So far, this jst consists of initializing color in curses mode, and making
  the display start and end part of intializing and freeing a sheet (so that
  it can control allocating the palette, for example, where the data structure
  used depends on what kind of display it is.

  Next up will be to allocate and destroy the color palette, and set up the
  default colors for cells to use (0 for foreground,
  TEAPOT_WHITE for background.) The outline beyond that is to allow setting of
  the cell colors, then actually display those colors, and finally edit the
  palette.
This commit is contained in:
Glen Whitney 2019-07-29 11:35:10 -04:00
parent 2a4071f8dc
commit 25bb787f08
7 changed files with 49 additions and 30 deletions

View File

@ -10,7 +10,11 @@ extern "C" {
typedef enum { LEFT=0, RIGHT=1, CENTER=2, AUTOADJUST=3 } Adjust; typedef enum { LEFT=0, RIGHT=1, CENTER=2, AUTOADJUST=3 } Adjust;
typedef enum { BASE=0, ITERATIVE=1, CONTINGENT=2 } ContentVariety; typedef enum { BASE=0, ITERATIVE=1, CONTINGENT=2 } ContentVariety;
typedef unsigned char ColorNum;
#define MAX_MAX_COLORS UCHAR_MAX;
typedef struct typedef struct
{ {
Token **contents[CONTINGENT]; Token **contents[CONTINGENT];
@ -19,6 +23,8 @@ typedef struct
Token resvalue; Token resvalue;
Adjust adjust; Adjust adjust;
int precision; int precision;
ColorNum foreground;
ColorNum background;
unsigned int updated:1; unsigned int updated:1;
unsigned int shadowed:1; unsigned int shadowed:1;
unsigned int scientific:1; unsigned int scientific:1;

View File

@ -46,13 +46,14 @@ int getopt(int argc, char * const *argv, const char *optstring);
/* variables */ /*{{{*/ /* variables */ /*{{{*/
char helpfile[PATH_MAX]; char helpfile[PATH_MAX];
int batch=0; bool batch = false;
unsigned int batchln=0; unsigned int batchln=0;
int def_precision=DEF_PRECISION; int def_precision = DEF_PRECISION;
int quote=0; bool quote = false;
int header=1; bool header = true;
int debug_level=0; bool always_redraw = false;
static int usexdr=1; int debug_level = 0;
static bool usexdr = true;
/*}}}*/ /*}}}*/
void moveto(Sheet *sheet, int x, int y, int z) void moveto(Sheet *sheet, int x, int y, int z)
@ -1801,7 +1802,6 @@ int main(int argc, char *argv[])
Sheet sheet,*cursheet; Sheet sheet,*cursheet;
int o; int o;
const char *loadfile; const char *loadfile;
int always_redraw=0;
char ln[1024]; char ln[1024];
/*}}}*/ /*}}}*/
@ -1814,29 +1814,29 @@ int main(int argc, char *argv[])
/* a -- use ascii as default */ /*{{{*/ /* a -- use ascii as default */ /*{{{*/
case 'a': case 'a':
{ {
usexdr=0; usexdr = false;
break; break;
} }
/*}}}*/ /*}}}*/
/* b -- run batch */ /*{{{*/ /* b -- run batch */ /*{{{*/
case 'b': batch=1; break; case 'b': batch = true; break;
/*}}}*/ /*}}}*/
/* d -- increase debug level */ /*{{{*/ /* d -- increase debug level */ /*{{{*/
case 'd': ++debug_level; break; case 'd': ++debug_level; break;
/*}}}*/ /*}}}*/
/* n -- no quoted strings */ /*{{{*/ /* n -- no quoted strings */ /*{{{*/
case 'n': quote=0; break; case 'n': quote = false; break;
/*}}}*/ /*}}}*/
/* q -- force quoted strings */ /*{{{*/ /* q -- force quoted strings */ /*{{{*/
case 'q': quote=1; break; case 'q': quote = true; break;
/*}}}*/ /*}}}*/
/* H -- no row/column headers */ /*{{{*/ /* H -- no row/column headers */ /*{{{*/
case 'H': header=0; break; case 'H': header = false; break;
/*}}}*/ /*}}}*/
/* r -- always redraw */ /*{{{*/ /* r -- always redraw */ /*{{{*/
case 'r': case 'r':
{ {
always_redraw=1; always_redraw = true;
break; break;
} }
/*}}}*/ /*}}}*/
@ -1878,12 +1878,6 @@ int main(int argc, char *argv[])
/*}}}*/ /*}}}*/
cursheet = &sheet; cursheet = &sheet;
initialize_sheet(cursheet); initialize_sheet(cursheet);
/* start display */ /*{{{*/
if (!batch) {
display_init(cursheet, always_redraw);
line_msg((const char*)0,"");
}
/*}}}*/
if (loadfile) /* load given sheet */ /*{{{*/ if (loadfile) /* load given sheet */ /*{{{*/
{ {
const char *msg; const char *msg;
@ -1967,10 +1961,7 @@ int main(int argc, char *argv[])
} }
/*}}}*/ /*}}}*/
else /* process interactive input */ /*{{{*/ else /* process interactive input */ /*{{{*/
{
display_main(cursheet); display_main(cursheet);
display_end();
}
/*}}}*/ /*}}}*/
freesheet(cursheet,1); freesheet(cursheet,1);
fclose(stdin); fclose(stdin);

View File

@ -11,11 +11,12 @@
extern "C" { extern "C" {
#endif #endif
extern int batch; extern bool batch;
extern int def_precision; extern int def_precision;
extern int quote; extern bool quote;
extern int header; extern bool header;
extern int debug_level; extern int debug_level;
extern bool always_redraw;
extern unsigned int batchln; extern unsigned int batchln;
/* A variable of type Key is either a special symbol from this enum, representing /* A variable of type Key is either a special symbol from this enum, representing

View File

@ -253,6 +253,12 @@ void initialize_sheet(Sheet *sheet) {
sheet->moveonly = 0; sheet->moveonly = 0;
sheet->clk = 0; sheet->clk = 0;
(void)memset(sheet->labelcache, 0, sizeof(sheet->labelcache)); (void)memset(sheet->labelcache, 0, sizeof(sheet->labelcache));
sheet->max_colors = MAX_MAX_COLORS;
/* start display of this sheet */
if (!batch) {
display_init(sheet, always_redraw);
line_msg((const char*)0,"");
}
} }
/*}}}*/ /*}}}*/
@ -425,6 +431,10 @@ void freesheet(Sheet *sheet, int all)
if (sheet->sheet) free(sheet->sheet); if (sheet->sheet) free(sheet->sheet);
if (sheet->column) free(sheet->column); if (sheet->column) free(sheet->column);
if (sheet->name) free(sheet->name); if (sheet->name) free(sheet->name);
if (!batch)
{
display_end(sheet);
}
} }
else else
{ {

View File

@ -37,7 +37,6 @@ typedef struct
struct Label *labelcache[LABEL_CACHE]; struct Label *labelcache[LABEL_CACHE];
Location cur; Location cur;
Location mark1, mark2; Location mark1, mark2;
MarkState marking;
int offx, offy; int offx, offy;
Cell **sheet; Cell **sheet;
int *column; int *column;
@ -45,10 +44,13 @@ typedef struct
int orix, oriy, maxx, maxy; int orix, oriy, maxx, maxy;
int width; int width;
char *name; char *name;
void *display;
int max_colors;
void *palette;
MarkState marking;
unsigned int changed:1; unsigned int changed:1;
unsigned int moveonly:1; unsigned int moveonly:1;
unsigned int clk:1; unsigned int clk:1;
void *display;
} Sheet; } Sheet;
#define LOC_WITHINC(s,x,y,z) (x<s->dimx && y<s->dimy && z<s->dimz) #define LOC_WITHINC(s,x,y,z) (x<s->dimx && y<s->dimy && z<s->dimz)

View File

@ -394,9 +394,18 @@ void display_main(Sheet *cursheet)
} while (k == K_INVALID || !do_sheetcmd(cursheet,k,0) || doanyway(cursheet,_("Sheet modified, leave anyway?"))!=1); } while (k == K_INVALID || !do_sheetcmd(cursheet,k,0) || doanyway(cursheet,_("Sheet modified, leave anyway?"))!=1);
} }
#define TEAPOT_WHITE 16
#define CHANNEL_MAX 1000
void display_init(Sheet *cursheet, int always_redraw) void display_init(Sheet *cursheet, int always_redraw)
{ {
initscr(); initscr();
start_color();
init_color(TEAPOT_WHITE, CHANNEL_MAX, CHANNEL_MAX, CHANNEL_MAX);
assume_default_colors(COLOR_BLACK, TEAPOT_WHITE);
if (debug_level > 1)
printf("Terminal has colors: %d, #colors:%d, #pairs:%d",
has_colors(), COLORS, COLOR_PAIRS);
curs_set(0); curs_set(0);
noecho(); noecho();
raw(); raw();
@ -409,7 +418,7 @@ void display_init(Sheet *cursheet, int always_redraw)
#endif #endif
} }
void display_end(void) void display_end(Sheet* sheet)
{ {
curs_set(1); curs_set(1);
echo(); echo();

View File

@ -801,7 +801,7 @@ sheet->changed = ch;
new MainWindow(sheet);} {} new MainWindow(sheet);} {}
} }
Function {display_end()} {C return_type void Function {display_end(Sheet* sheet)} {C return_type void
} { } {
code {} {} code {} {}
} }