force ncurses mode if supported when hex colors are set in config

instead of exiting with error it is better to force ncurses on.
noncurses is now default, but does not support hex colors. so if
hex colors are used (like in a gradient) it will be better to force
ncurses mode. ncurses might have some performance issues and slight
glitches. but it should be ok as long as it is documented in the
config file. relates to #368
master
karlstav 6 years ago
parent 4db05a1742
commit 2d93b29e1f
  1. 27
      config.c
  2. 3
      example_files/config

@ -52,18 +52,26 @@ void write_errorf(void *err, const char *fmt, ...) {
va_end(args); va_end(args);
} }
int validate_color(char *checkColor, int om, void *err) { int validate_color(char *checkColor, void *params, void *err) {
struct config_params *p = (struct config_params *)params;
struct error_s *error = (struct error_s *)err; struct error_s *error = (struct error_s *)err;
int validColor = 0; int validColor = 0;
if (checkColor[0] == '#' && strlen(checkColor) == 7) { if (checkColor[0] == '#' && strlen(checkColor) == 7) {
// If the output mode is not ncurses, tell the user to use a named colour instead of hex // If the output mode is not ncurses, tell the user to use a named colour instead of hex
// colours. // colours.
if (om != OUTPUT_NCURSES) { if (p->om != OUTPUT_NCURSES) {
write_errorf( #ifdef NCURSES
error, "Only 'ncurses' output method supports HTML colors. Please change " write_errorf(error,
"the colours or the output method.\nAs of version 0.7.0 ncurses is no longer" "hex color configured, but ncurses not set. Forcing ncurses mode.\n");
" the default output method\n"); p->om = OUTPUT_NCURSES;
#else
write_errorf(error,
"Only 'ncurses' output method supports HTML colors "
"(required by gradient). "
"Cava was built without ncurses support, install ncurses(w) dev files "
"and rebuild.\n");
return 0; return 0;
#endif
} }
// 0 to 9 and a to f // 0 to 9 and a to f
for (int i = 1; checkColor[i]; ++i) { for (int i = 1; checkColor[i]; ++i) {
@ -94,14 +102,14 @@ bool validate_colors(void *params, void *err) {
struct error_s *error = (struct error_s *)err; struct error_s *error = (struct error_s *)err;
// validate: color // validate: color
if (!validate_color(p->color, p->om, error)) { if (!validate_color(p->color, p, error)) {
write_errorf(error, "The value for 'foreground' is invalid. It can be either one of the 7 " write_errorf(error, "The value for 'foreground' is invalid. It can be either one of the 7 "
"named colors or a HTML color of the form '#xxxxxx'.\n"); "named colors or a HTML color of the form '#xxxxxx'.\n");
return false; return false;
} }
// validate: background color // validate: background color
if (!validate_color(p->bcolor, p->om, error)) { if (!validate_color(p->bcolor, p, error)) {
write_errorf(error, "The value for 'background' is invalid. It can be either one of the 7 " write_errorf(error, "The value for 'background' is invalid. It can be either one of the 7 "
"named colors or a HTML color of the form '#xxxxxx'.\n"); "named colors or a HTML color of the form '#xxxxxx'.\n");
return false; return false;
@ -109,7 +117,7 @@ bool validate_colors(void *params, void *err) {
if (p->gradient) { if (p->gradient) {
for (int i = 0; i < p->gradient_count; i++) { for (int i = 0; i < p->gradient_count; i++) {
if (!validate_color(p->gradient_colors[i], p->om, error)) { if (!validate_color(p->gradient_colors[i], p, error)) {
write_errorf( write_errorf(
error, error,
"Gradient color %d is invalid. It must be HTML color of the form '#xxxxxx'.\n", "Gradient color %d is invalid. It must be HTML color of the form '#xxxxxx'.\n",
@ -267,6 +275,7 @@ bool validate_config(struct config_params *p, struct error_s *error) {
return false; return false;
} }
// validate: colors
if (!validate_colors(p, error)) { if (!validate_colors(p, error)) {
return false; return false;
} }

@ -83,7 +83,7 @@
# 'raw' is an 8 or 16 bit (configurable via the 'bit_format' option) data # 'raw' is an 8 or 16 bit (configurable via the 'bit_format' option) data
# stream of the bar heights that can be used to send to other applications. # stream of the bar heights that can be used to send to other applications.
# 'raw' defaults to 200 bars, which can be adjusted in the 'bars' option above. # 'raw' defaults to 200 bars, which can be adjusted in the 'bars' option above.
; method = ncurses ; method = noncurses
# Visual channels. Can be 'stereo' or 'mono'. # Visual channels. Can be 'stereo' or 'mono'.
# 'stereo' mirrors both channels with low frequencies in center. # 'stereo' mirrors both channels with low frequencies in center.
@ -116,6 +116,7 @@
# Colors can be one of seven predefined: black, blue, cyan, green, magenta, red, white, yellow. # Colors can be one of seven predefined: black, blue, cyan, green, magenta, red, white, yellow.
# Or defined by hex code '#xxxxxx' (hex code must be within ''). User defined colors requires # Or defined by hex code '#xxxxxx' (hex code must be within ''). User defined colors requires
# ncurses output method and a terminal that can change color definitions such as Gnome-terminal or rxvt. # ncurses output method and a terminal that can change color definitions such as Gnome-terminal or rxvt.
# if supported, ncurses mode will be forced on if user defined colors are used.
# default is to keep current terminal color # default is to keep current terminal color
; background = default ; background = default
; foreground = default ; foreground = default

Loading…
Cancel
Save