Autodetect color support, allow override through arguments
This commit is contained in:
parent
37c1d3607e
commit
a49ed8dd36
35
src/2048.c
35
src/2048.c
|
@ -231,23 +231,15 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
/* parse options */
|
/* parse options */
|
||||||
int c;
|
int c;
|
||||||
while ((c = getopt(argc, argv, "rchs:b:")) != -1) {
|
int enable_color = has_colors();
|
||||||
|
while ((c = getopt(argc, argv, "rcChs:b:")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
/* Color support */
|
/* Color support */
|
||||||
case 'c':
|
case 'c':
|
||||||
if (has_colors()) {
|
enable_color = 1;
|
||||||
start_color();
|
break;
|
||||||
init_pair(0, 1, 0);
|
case 'C':
|
||||||
init_pair(1, 2, 0);
|
enable_color = 0;
|
||||||
init_pair(2, 3, 0);
|
|
||||||
init_pair(3, 4, 0);
|
|
||||||
init_pair(4, 5, 0);
|
|
||||||
init_pair(5, 6, 0);
|
|
||||||
init_pair(6, 7, 0);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fprintf(stderr, "Terminal does not support color\n");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
// different board sizes
|
// different board sizes
|
||||||
case 's':;
|
case 's':;
|
||||||
|
@ -276,6 +268,21 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (enable_color) {
|
||||||
|
if (!has_colors()) {
|
||||||
|
fprintf(stderr, "Terminal does not support color\n");
|
||||||
|
} else {
|
||||||
|
start_color();
|
||||||
|
init_pair(0, 1, 0);
|
||||||
|
init_pair(1, 2, 0);
|
||||||
|
init_pair(2, 3, 0);
|
||||||
|
init_pair(3, 4, 0);
|
||||||
|
init_pair(4, 5, 0);
|
||||||
|
init_pair(5, 6, 0);
|
||||||
|
init_pair(6, 7, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Allocate memory once we actually know amount */
|
/* Allocate memory once we actually know amount */
|
||||||
CALLOC2D(grid, grid_size);
|
CALLOC2D(grid, grid_size);
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ typedef enum {
|
||||||
"Options:\n"\
|
"Options:\n"\
|
||||||
" -s <size> Set the grid border length\n"\
|
" -s <size> Set the grid border length\n"\
|
||||||
" -b <rate> Set the block spawn rate\n"\
|
" -b <rate> Set the block spawn rate\n"\
|
||||||
" -c Enables color support (ncurses version only)\n"
|
" -c Enables color support (ncurses version only)\n"\
|
||||||
|
" -C Disabled color support (ncurses version only)\n"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user