} aobject_t;
-int main(void);
+int main(int, char **);
+static void usage(void);
+
static void shape_draw(int, int, int);
static void anim_init(void);
static void anim_redraw(void);
static void read_shapes(void);
+/* Simulate BSD set/getprogname(3) on GNU */
+static const char *progname = "";
+
/* Color related */
+static bool cfg_use_color = true;
+static bool cfg_use_attributes = true;
+static bool use_color = false;
+static bool use_attributes = false;
static short ncolpairs = -1;
/* Loaded shapes */
int
-main(void)
+main(int argc, char **argv)
{
+ int ch;
+
+ progname = strdup(argv[0]);
+ while ((ch = getopt(argc, argv, "?mp"))
+ != -1) {
+ switch (ch) {
+ case 'm':
+ cfg_use_color = false;
+ break;
+ case 'p':
+ cfg_use_attributes = false;
+ break;
+ case '?':
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
screen_init();
/*
* enforced color pairs to really only define the foreground or
* background color.
*/
- (void)use_default_colors();
- if (start_color() == ERR)
- err(EXIT_FAILURE, "start_color()");
+ if (cfg_use_color && has_colors()) {
+ (void)use_default_colors();
+ if (start_color() == OK) {
+ /*
+ * Allocate a few basic pairs before loading shapes
+ * that will also allocate new pairs as needed.
+ */
+ (void)init_pair(++ncolpairs, -1, -1);
+ (void)init_pair(++ncolpairs, COLOR_WHITE, COLOR_BLACK);
- /*
- * Allocate a few basic pairs before loading shapes that will also
- * allocate new pairs as needed.
- */
- (void)init_pair(++ncolpairs, -1, -1);
- (void)init_pair(++ncolpairs, COLOR_WHITE, COLOR_BLACK);
+ use_color = true;
+ }
+ }
+ if (cfg_use_attributes && termattrs() != 0)
+ use_attributes = true;
/* Read shape definitions from file */
read_shapes();
exit(EXIT_SUCCESS);
}
+static void
+usage(void)
+{
+
+ (void)fprintf(stderr,
+ "\nUsage: %s [-m] [-p]\n\n"
+ "Where:\n"
+ " -m - Monochrome mode, do not use colors.\n"
+ " -p - Plain, do not use text attributes like bold.\n\n",
+ progname);
+
+ exit(EXIT_FAILURE);
+}
+
/* 2d text shape blitting routine */
static void
shape_draw(int shape, int y, int x)
int i;
/* Redraw screen with all objects */
- (void)attrset(COLOR_PAIR(0));
+ if (use_color)
+ (void)attrset(COLOR_PAIR(0));
(void)erase();
for (i = 0; i < NOBJECTS; i++) {
aobject_t *o = &objects[i];
if (o->t == AOT_SHAPE)
shape_draw(o->s, o->y, o->x);
else {
- (void)attrset(COLOR_PAIR(o->col));
+ if (use_color && o->col != -1)
+ (void)attrset(COLOR_PAIR(o->col));
(void)mvaddch(o->y, o->x, o->c);
}
}
/* Avatar */
+ /* XXX */
(void)attr_on(A_REVERSE, NULL);
(void)mvaddch(avatar.y, avatar.x, avatar.c);
(void)attr_off(A_REVERSE, NULL);
continue;
}
if (line[0] == 'F' && line[1] == ' ') {
+ if (!use_color)
+ continue;
rarray_append(&flines,
(intptr_t)strdup(&line[2]));
continue;
}
if (line[0] == 'B' && line[1] == ' ') {
+ if (!use_color)
+ continue;
rarray_append(&blines,
(intptr_t)strdup(&line[2]));
continue;
}
if (line[0] == 'A' && line[1] == ' ') {
+ if (!use_attributes)
+ continue;
rarray_append(&alines,
(intptr_t)strdup(&line[2]));
continue;
(void)werase(pad);
/* Fill with characters marked with attributes as needed */
- /* XXX Also avoid to apply colors or attributes depending on
- * options like mono/nocolor */
for (y = 0; y < tlines.count; y++) {
for (len = strlen((const char *)tlines.array[y]),
x = 0; x < len; x++) {
chtype ch;
int fg = -1, bg = -1;
char *cptr, c;
+ int supattr;
+
+ supattr = termattrs();
cptr = (char *)tlines.array[y];
ch = cptr[x];
c = cptr[x];
switch (c) {
case 'E':
- ch |= A_BOLD;
+ if ((supattr & A_BOLD)
+ != 0)
+ ch |= A_BOLD;
break;
case 'I':
- ch |= A_REVERSE;
+ if ((supattr &
+ A_REVERSE) != 0)
+ ch |=
+ A_REVERSE;
break;
case 'U':
- ch |= A_UNDERLINE;
+ if ((supattr &
+ A_UNDERLINE) != 0)
+ ch |=
+ A_UNDERLINE;
break;
case 'B':
- ch |= A_BLINK;
+ if ((supattr & A_BLINK)
+ != 0)
+ ch |= A_BLINK;
break;
}
}
}
ch |= COLOR_PAIR(p);
}
+ /*
+ * If color is used disable the use of
+ * attributes that are incompatible with it
+ */
+ if (fg != -1 || bg != -1)
+ ch &= ~(no_color_attributes());
/* Finally add character to pad */
(void)mvwaddch(pad, y, x, ch);