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:
parent
2a4071f8dc
commit
25bb787f08
@ -11,6 +11,10 @@ typedef enum { LEFT=0, RIGHT=1, CENTER=2, AUTOADJUST=3 } Adjust;
|
||||
|
||||
typedef enum { BASE=0, ITERATIVE=1, CONTINGENT=2 } ContentVariety;
|
||||
|
||||
typedef unsigned char ColorNum;
|
||||
|
||||
#define MAX_MAX_COLORS UCHAR_MAX;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Token **contents[CONTINGENT];
|
||||
@ -19,6 +23,8 @@ typedef struct
|
||||
Token resvalue;
|
||||
Adjust adjust;
|
||||
int precision;
|
||||
ColorNum foreground;
|
||||
ColorNum background;
|
||||
unsigned int updated:1;
|
||||
unsigned int shadowed:1;
|
||||
unsigned int scientific:1;
|
||||
|
@ -46,13 +46,14 @@ int getopt(int argc, char * const *argv, const char *optstring);
|
||||
|
||||
/* variables */ /*{{{*/
|
||||
char helpfile[PATH_MAX];
|
||||
int batch=0;
|
||||
bool batch = false;
|
||||
unsigned int batchln=0;
|
||||
int def_precision = DEF_PRECISION;
|
||||
int quote=0;
|
||||
int header=1;
|
||||
bool quote = false;
|
||||
bool header = true;
|
||||
bool always_redraw = false;
|
||||
int debug_level = 0;
|
||||
static int usexdr=1;
|
||||
static bool usexdr = true;
|
||||
/*}}}*/
|
||||
|
||||
void moveto(Sheet *sheet, int x, int y, int z)
|
||||
@ -1801,7 +1802,6 @@ int main(int argc, char *argv[])
|
||||
Sheet sheet,*cursheet;
|
||||
int o;
|
||||
const char *loadfile;
|
||||
int always_redraw=0;
|
||||
char ln[1024];
|
||||
/*}}}*/
|
||||
|
||||
@ -1814,29 +1814,29 @@ int main(int argc, char *argv[])
|
||||
/* a -- use ascii as default */ /*{{{*/
|
||||
case 'a':
|
||||
{
|
||||
usexdr=0;
|
||||
usexdr = false;
|
||||
break;
|
||||
}
|
||||
/*}}}*/
|
||||
/* b -- run batch */ /*{{{*/
|
||||
case 'b': batch=1; break;
|
||||
case 'b': batch = true; break;
|
||||
/*}}}*/
|
||||
/* d -- increase debug level */ /*{{{*/
|
||||
case 'd': ++debug_level; break;
|
||||
/*}}}*/
|
||||
/* n -- no quoted strings */ /*{{{*/
|
||||
case 'n': quote=0; break;
|
||||
case 'n': quote = false; break;
|
||||
/*}}}*/
|
||||
/* q -- force quoted strings */ /*{{{*/
|
||||
case 'q': quote=1; break;
|
||||
case 'q': quote = true; break;
|
||||
/*}}}*/
|
||||
/* H -- no row/column headers */ /*{{{*/
|
||||
case 'H': header=0; break;
|
||||
case 'H': header = false; break;
|
||||
/*}}}*/
|
||||
/* r -- always redraw */ /*{{{*/
|
||||
case 'r':
|
||||
{
|
||||
always_redraw=1;
|
||||
always_redraw = true;
|
||||
break;
|
||||
}
|
||||
/*}}}*/
|
||||
@ -1878,12 +1878,6 @@ int main(int argc, char *argv[])
|
||||
/*}}}*/
|
||||
cursheet = &sheet;
|
||||
initialize_sheet(cursheet);
|
||||
/* start display */ /*{{{*/
|
||||
if (!batch) {
|
||||
display_init(cursheet, always_redraw);
|
||||
line_msg((const char*)0,"");
|
||||
}
|
||||
/*}}}*/
|
||||
if (loadfile) /* load given sheet */ /*{{{*/
|
||||
{
|
||||
const char *msg;
|
||||
@ -1967,10 +1961,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
/*}}}*/
|
||||
else /* process interactive input */ /*{{{*/
|
||||
{
|
||||
display_main(cursheet);
|
||||
display_end();
|
||||
}
|
||||
/*}}}*/
|
||||
freesheet(cursheet,1);
|
||||
fclose(stdin);
|
||||
|
@ -11,11 +11,12 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int batch;
|
||||
extern bool batch;
|
||||
extern int def_precision;
|
||||
extern int quote;
|
||||
extern int header;
|
||||
extern bool quote;
|
||||
extern bool header;
|
||||
extern int debug_level;
|
||||
extern bool always_redraw;
|
||||
extern unsigned int batchln;
|
||||
|
||||
/* A variable of type Key is either a special symbol from this enum, representing
|
||||
|
@ -253,6 +253,12 @@ void initialize_sheet(Sheet *sheet) {
|
||||
sheet->moveonly = 0;
|
||||
sheet->clk = 0;
|
||||
(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->column) free(sheet->column);
|
||||
if (sheet->name) free(sheet->name);
|
||||
if (!batch)
|
||||
{
|
||||
display_end(sheet);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -37,7 +37,6 @@ typedef struct
|
||||
struct Label *labelcache[LABEL_CACHE];
|
||||
Location cur;
|
||||
Location mark1, mark2;
|
||||
MarkState marking;
|
||||
int offx, offy;
|
||||
Cell **sheet;
|
||||
int *column;
|
||||
@ -45,10 +44,13 @@ typedef struct
|
||||
int orix, oriy, maxx, maxy;
|
||||
int width;
|
||||
char *name;
|
||||
void *display;
|
||||
int max_colors;
|
||||
void *palette;
|
||||
MarkState marking;
|
||||
unsigned int changed:1;
|
||||
unsigned int moveonly:1;
|
||||
unsigned int clk:1;
|
||||
void *display;
|
||||
} Sheet;
|
||||
|
||||
#define LOC_WITHINC(s,x,y,z) (x<s->dimx && y<s->dimy && z<s->dimz)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
#define TEAPOT_WHITE 16
|
||||
#define CHANNEL_MAX 1000
|
||||
|
||||
void display_init(Sheet *cursheet, int always_redraw)
|
||||
{
|
||||
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);
|
||||
noecho();
|
||||
raw();
|
||||
@ -409,7 +418,7 @@ void display_init(Sheet *cursheet, int always_redraw)
|
||||
#endif
|
||||
}
|
||||
|
||||
void display_end(void)
|
||||
void display_end(Sheet* sheet)
|
||||
{
|
||||
curs_set(1);
|
||||
echo();
|
||||
|
@ -801,7 +801,7 @@ sheet->changed = ch;
|
||||
new MainWindow(sheet);} {}
|
||||
}
|
||||
|
||||
Function {display_end()} {C return_type void
|
||||
Function {display_end(Sheet* sheet)} {C return_type void
|
||||
} {
|
||||
code {} {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user