#ifndef _OCOLOR_H_ #define _OCOLOR_H_ #include "contexts.h" /* Okay, here's the least-common-denominator color support for orcus. Eventually, I hope to extend this to accomodate more than the eight basic colors for display types which support more, but this is what should work on xterm, nxterm, linux-console, vt102, etc, anything that's backward-compatible to these basic display types. Conceptually, orcus maintains a list of terminal maps, each with a textual name, a unique numeric id, a list of contexts ("directory"), and a list of color codes ("map"). A context describes something orcus displays under particular circumstances (eg, a public message, or a server alert, or something more precise, like an asterisk in the name-tag of a public message). A list of symbolic context names can be found in "contexts.h". Associated with the context is its name, its numeric id, and its color code. A color map entry describes how the terminal type is instructed to colorize its text. Right now this is vestigal; the xterm codes are hard-coded, but if/when someone wants to create an alternative map, this is where the information gets stored. Each map entry stores a color code identfier, a name, and a control-string. The color code is used to identify the color to the orcus color control functions, ie as the parameter to ocolor_write(). The name is a string that describes the color, in english, so that ocolor_code_to_string() (and visa-versa) can work, and the control-string is the actual string written to the display to make the change. int colorize; This global determines whether color functions actually do anything or not. It defaults to 0, colorization off. As long as it is 0, most of the ocolor_* functions simply return without doing anything. int current_color; Set to the color code of the color the display is actually set to. Writes to stdout will show up as this color. int color_dir_n; int color_dir_max; ocd_t *color_directory; Pointer to an array of color_dir_n ocd_t elements, describing the current colorization settings for the various contexts. char *term_name; The name of the currently active terminal type. int context_n; int *contexts; Pointer to an array of context_n context color code identifiers. In order to make orcus display the given context's text in color, the appropriate color code should be assigned to that context's entry in *contexts. char *ocolor_code_to_string ( int ccode ); Converts the given ccode to its color string under the currently active terminal. int ocolor_string_to_code ( char *str ); Interprets str as a name of a color code, which it finds under the active terminal's color map and returns the associated colorcode. int ocolor_write ( int ccode ); Low-level color setting function; writes the control string for the given color code to stdout. Probably shouldn't use this outside of the ocolor_set() function. int ocolor_set ( int ccode ); Slightly higher color setting function; returns immediately if the client is not generating output (ie, silent_running == 1), else writes ccode to current_color and calls ocolor_write(). int ocolor_push ( int ccode ); The primary color-setting function that should be called from most orcus functions. Again, returns immediately if the client is not generating output. Maintains a stack of color values, so that within a function the color can be set and then reset to the old value (via ocolor_pop()) without having to litter the function with code that explicitly saves and restores the information. Also provides the ability to optimize, since if the current color is already ccode, ccode can be pushed onto the stack without actually sending the control string to stdout. int ocolor_pop (); Reverses the action of ocolor_push() - restores the pre-push color by popping from the color stack. DOES NOT actually send the color code to stdout, however! When oprint() notices that the current color is not the same as the color on the top of the stack, it will call ocolor_write() itself. This way, multiple ocolor_pop() calls with no output between them do not generate superfluous stdout output. int ocolor_get (); Returns the color code value on the top of the color stack. int ocolor_reset ( int ccode ); I can't remember what I wanted to do with this function. My memory sucks. Commented out for now. int ocolor_bind ( int ccode, int context_id, char *context_name ); Binds a color to a specific context, either by name (context_name != NULL) or by context_id (context_name == NULL). int ocolor_color ( int ccode, int term_id, char *term_name, char *ctlstr, char *name ); Defines a color map entry under a specific terminal. If the terminal doesn't exist, it gets created. int ocolor_sterm ( int term_id, char *term_name ); Sets the active terminal to the given terminal id (term_name == NULL) or to the given terminal name (term_name != NULL). int ocolor_termid ( char *term_name ); Returns the terminal id associated with the named terminal. int ocolor_ctxtid ( char *context_name ); Returns the context id associated with the named context. int ocolor_init (); Initializes the ocolor data structures to a known state, and TO DO: I really should write functions for easily saving/restoring terminal color data to/from disk files. */ #define OC_SANE ((int)(0x00001)) #define OC_NORMAL ((int)(0x00001)) #define OC_BOLD ((int)(0x00002)) #define OC_ULINE ((int)(0x00004)) #define OC_BLINK ((int)(0x00008)) #define OC_INVERT ((int)(0x00010)) #define OC_BLACK ((int)(0x00100)) #define OC_RED ((int)(0x00200)) #define OC_GREEN ((int)(0x00300)) #define OC_YELLOW ((int)(0x00400)) #define OC_BLUE ((int)(0x00500)) #define OC_MAGENTA ((int)(0x00600)) #define OC_CYAN ((int)(0x00700)) #define OC_WHITE ((int)(0x00800)) #define OC_BG_BLACK ((int)(0x01000)) #define OC_BG_RED ((int)(0x02000)) #define OC_BG_GREEN ((int)(0x03000)) #define OC_BG_YELLOW ((int)(0x04000)) #define OC_BG_BLUE ((int)(0x05000)) #define OC_BG_MAGENTA ((int)(0x06000)) #define OC_BG_CYAN ((int)(0x07000)) #define OC_BG_WHITE ((int)(0x08000)) #define OC_BG_DK_BLACK ((int)(0x10000)) #define OC_BG_DK_RED ((int)(0x20000)) #define OC_BG_DK_GREEN ((int)(0x30000)) #define OC_BG_DK_YELLOW ((int)(0x40000)) #define OC_BG_DK_BLUE ((int)(0x50000)) #define OC_BG_DK_MAGENTA ((int)(0x60000)) #define OC_BG_DK_CYAN ((int)(0x70000)) #define OC_BG_DK_WHITE ((int)(0x80000)) typedef struct ocolor_dir_tag { int ccode; /* -1 for sentry */ char *context; int conid; } ocd_t; /* ha-ha :-P yes, actually, I have ocd -- TTK */ typedef struct ocolor_map_tag { int ccode; /* -1 for sentry */ char *name; char *ctlstr; } ocm_t; typedef struct ocolor_term_tag { long flags; char *term_name; int term_id; int n_dir; ocd_t *dir; ocm_t *map; } oct_t #ifndef _OCOLOR_C_ extern int colorize; /* 1 iff using color at all */ extern int current_color; extern int color_dir_n; extern int color_dir_max; extern ocd_t *color_directory; extern char *term_name; /* terminal type for current directory */ extern int context_n; extern int *contexts; /* indexed by OC_CX_* */ extern char **term_list; /* list of term_names, indexed by term_id */ char *ocolor_code_to_string ( int ccode ); int ocolor_string_to_code ( char *str ); int ocolor_write ( int ccode ); int ocolor_set ( int ccode ); int ocolor_push ( int ccode ); int ocolor_pop (); int ocolor_get (); /* int ocolor_reset ( int ccode ); */ int ocolor_bind ( int ccode, int context_id, char *context_name ); int ocolor_color ( int ccode, int term_id, char *term_name, char *ctlstr, char *name ); int ocolor_sterm ( int term_id, char *term_name ); int ocolor_termid ( char *term_name ); int ocolor_ctxtid ( char *context_name ); int ocolor_init (); #endif #endif