mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Implement Color Vision Deficiencies setting
Implement settings for redgreen and blue blindness. Regards https://github.com/profanity-im/profanity/issues/1191
This commit is contained in:
parent
136f504d5e
commit
2750194279
@ -111,6 +111,7 @@ static char* _clear_autocomplete(ProfWin *window, const char *const input, gbool
|
|||||||
static char* _invite_autocomplete(ProfWin *window, const char *const input, gboolean previous);
|
static char* _invite_autocomplete(ProfWin *window, const char *const input, gboolean previous);
|
||||||
static char* _status_autocomplete(ProfWin *window, const char *const input, gboolean previous);
|
static char* _status_autocomplete(ProfWin *window, const char *const input, gboolean previous);
|
||||||
static char* _logging_autocomplete(ProfWin *window, const char *const input, gboolean previous);
|
static char* _logging_autocomplete(ProfWin *window, const char *const input, gboolean previous);
|
||||||
|
static char* _color_autocomplete(ProfWin *window, const char *const input, gboolean previous);
|
||||||
|
|
||||||
static char* _script_autocomplete_func(const char *const prefix, gboolean previous);
|
static char* _script_autocomplete_func(const char *const prefix, gboolean previous);
|
||||||
|
|
||||||
@ -229,6 +230,7 @@ static Autocomplete invite_ac;
|
|||||||
static Autocomplete status_ac;
|
static Autocomplete status_ac;
|
||||||
static Autocomplete status_state_ac;
|
static Autocomplete status_state_ac;
|
||||||
static Autocomplete logging_ac;
|
static Autocomplete logging_ac;
|
||||||
|
static Autocomplete color_ac;
|
||||||
|
|
||||||
void
|
void
|
||||||
cmd_ac_init(void)
|
cmd_ac_init(void)
|
||||||
@ -903,6 +905,12 @@ cmd_ac_init(void)
|
|||||||
logging_ac = autocomplete_new();
|
logging_ac = autocomplete_new();
|
||||||
autocomplete_add(logging_ac, "chat");
|
autocomplete_add(logging_ac, "chat");
|
||||||
autocomplete_add(logging_ac, "group");
|
autocomplete_add(logging_ac, "group");
|
||||||
|
|
||||||
|
color_ac = autocomplete_new();
|
||||||
|
autocomplete_add(color_ac, "on");
|
||||||
|
autocomplete_add(color_ac, "off");
|
||||||
|
autocomplete_add(color_ac, "redgreen");
|
||||||
|
autocomplete_add(color_ac, "blue");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1205,6 +1213,7 @@ cmd_ac_reset(ProfWin *window)
|
|||||||
autocomplete_reset(status_ac);
|
autocomplete_reset(status_ac);
|
||||||
autocomplete_reset(status_state_ac);
|
autocomplete_reset(status_state_ac);
|
||||||
autocomplete_reset(logging_ac);
|
autocomplete_reset(logging_ac);
|
||||||
|
autocomplete_reset(color_ac);
|
||||||
|
|
||||||
autocomplete_reset(script_ac);
|
autocomplete_reset(script_ac);
|
||||||
if (script_show_ac) {
|
if (script_show_ac) {
|
||||||
@ -1349,6 +1358,7 @@ cmd_ac_uninit(void)
|
|||||||
autocomplete_free(status_ac);
|
autocomplete_free(status_ac);
|
||||||
autocomplete_free(status_state_ac);
|
autocomplete_free(status_state_ac);
|
||||||
autocomplete_free(logging_ac);
|
autocomplete_free(logging_ac);
|
||||||
|
autocomplete_free(color_ac);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1479,7 +1489,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ
|
|||||||
|
|
||||||
// autocomplete boolean settings
|
// autocomplete boolean settings
|
||||||
gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash",
|
gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash",
|
||||||
"/history", "/vercheck", "/privileges", "/wrap", "/carbons", "/lastactivity", "/color" };
|
"/history", "/vercheck", "/privileges", "/wrap", "/carbons", "/lastactivity"};
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) {
|
for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) {
|
||||||
result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice, previous);
|
result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice, previous);
|
||||||
@ -1597,6 +1607,7 @@ _cmd_ac_complete_params(ProfWin *window, const char *const input, gboolean previ
|
|||||||
g_hash_table_insert(ac_funcs, "/invite", _invite_autocomplete);
|
g_hash_table_insert(ac_funcs, "/invite", _invite_autocomplete);
|
||||||
g_hash_table_insert(ac_funcs, "/status", _status_autocomplete);
|
g_hash_table_insert(ac_funcs, "/status", _status_autocomplete);
|
||||||
g_hash_table_insert(ac_funcs, "/logging", _logging_autocomplete);
|
g_hash_table_insert(ac_funcs, "/logging", _logging_autocomplete);
|
||||||
|
g_hash_table_insert(ac_funcs, "/color", _color_autocomplete);
|
||||||
|
|
||||||
int len = strlen(input);
|
int len = strlen(input);
|
||||||
char parsed[len+1];
|
char parsed[len+1];
|
||||||
@ -3595,3 +3606,16 @@ _logging_autocomplete(ProfWin *window, const char *const input, gboolean previou
|
|||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char*
|
||||||
|
_color_autocomplete(ProfWin *window, const char *const input, gboolean previous)
|
||||||
|
{
|
||||||
|
char *result = NULL;
|
||||||
|
|
||||||
|
result = autocomplete_param_with_ac(input, "/color", color_ac, TRUE, previous);
|
||||||
|
if (result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
@ -2302,12 +2302,15 @@ static struct cmd_t command_defs[] =
|
|||||||
CMD_TAGS(
|
CMD_TAGS(
|
||||||
CMD_TAG_UI)
|
CMD_TAG_UI)
|
||||||
CMD_SYN(
|
CMD_SYN(
|
||||||
"/color on|off")
|
"/color on|off|redgreen|blue")
|
||||||
CMD_DESC(
|
CMD_DESC(
|
||||||
"Settings for consistent color generation for nicks (XEP-0392).")
|
"Settings for consistent color generation for nicks (XEP-0392). Including corrections for Color Vision Deficiencies")
|
||||||
CMD_ARGS(
|
CMD_ARGS(
|
||||||
{ "on|off", "Enable or disable nick colorization for MUC nicks." })
|
{ "on|off|redgreen|blue", "Enable or disable nick colorization for MUC nicks. 'redgreen' is for people with red/green blindess and 'blue' for people with blue blindness."})
|
||||||
CMD_NOEXAMPLES
|
CMD_EXAMPLES(
|
||||||
|
"/color off",
|
||||||
|
"/color on",
|
||||||
|
"/color blue")
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8630,6 +8630,33 @@ cmd_paste(ProfWin *window, const char *const command, gchar **args)
|
|||||||
gboolean
|
gboolean
|
||||||
cmd_color(ProfWin *window, const char *const command, gchar **args)
|
cmd_color(ProfWin *window, const char *const command, gchar **args)
|
||||||
{
|
{
|
||||||
_cmd_set_boolean_preference(args[0], command, "Consistent color generation for nicks", PREF_COLOR_NICK);
|
if (g_strcmp0(args[0], "on") == 0) {
|
||||||
|
prefs_set_string(PREF_COLOR_NICK, "true");
|
||||||
|
} else if (g_strcmp0(args[0], "off") == 0) {
|
||||||
|
prefs_set_string(PREF_COLOR_NICK, "false");
|
||||||
|
} else if (g_strcmp0(args[0], "redgreen") == 0) {
|
||||||
|
prefs_set_string(PREF_COLOR_NICK, "redgreen");
|
||||||
|
} else if (g_strcmp0(args[0], "blue") == 0) {
|
||||||
|
prefs_set_string(PREF_COLOR_NICK, "blue");
|
||||||
|
} else {
|
||||||
|
cons_bad_cmd_usage(command);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
cons_show("Consistent color generation for nicks set to: %s", args[0]);
|
||||||
|
|
||||||
|
char *theme = prefs_get_string(PREF_THEME);
|
||||||
|
if (theme) {
|
||||||
|
gboolean res = theme_load(theme);
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
cons_show("Theme reloaded: %s", theme);
|
||||||
|
} else {
|
||||||
|
theme_load("default");
|
||||||
|
}
|
||||||
|
|
||||||
|
prefs_free_string(theme);
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <math.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
#ifdef HAVE_NCURSESW_NCURSES_H
|
#ifdef HAVE_NCURSESW_NCURSES_H
|
||||||
@ -380,7 +381,7 @@ static int find_col(const char *col_name, int n)
|
|||||||
return COL_ERR;
|
return COL_ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int color_hash(const char *str)
|
static int color_hash(const char *str, color_profile profile)
|
||||||
{
|
{
|
||||||
GChecksum *cs = NULL;
|
GChecksum *cs = NULL;
|
||||||
guint8 buf[256] = {0};
|
guint8 buf[256] = {0};
|
||||||
@ -401,10 +402,14 @@ static int color_hash(const char *str)
|
|||||||
double h = ((buf[1] << 8) | buf[0]) / 65536. * 360.;
|
double h = ((buf[1] << 8) | buf[0]) / 65536. * 360.;
|
||||||
|
|
||||||
// red/green blindness correction
|
// red/green blindness correction
|
||||||
// h = fmod(fmod(h + 90., 180) - 90., 360.);
|
if (profile == COLOR_PROFILE_REDGREEN) {
|
||||||
|
h = fmod(fmod(h + 90., 180) - 90., 360.);
|
||||||
|
}
|
||||||
|
|
||||||
// blue blindness correction
|
// blue blindness correction
|
||||||
// h = fmod(h, 180.);
|
if (profile == COLOR_PROFILE_BLUE) {
|
||||||
|
h = fmod(h, 180.);
|
||||||
|
}
|
||||||
|
|
||||||
rc = find_closest_col((int)h, 100, 50);
|
rc = find_closest_col((int)h, 100, 50);
|
||||||
|
|
||||||
@ -487,9 +492,9 @@ static int _color_pair_cache_get(int fg, int bg)
|
|||||||
* hash a string into a color that will be used as fg
|
* hash a string into a color that will be used as fg
|
||||||
* use default color as bg
|
* use default color as bg
|
||||||
*/
|
*/
|
||||||
int color_pair_cache_hash_str(const char *str)
|
int color_pair_cache_hash_str(const char *str, color_profile profile)
|
||||||
{
|
{
|
||||||
int fg = color_hash(str);
|
int fg = color_hash(str, profile);
|
||||||
int bg = -1;
|
int bg = -1;
|
||||||
|
|
||||||
return _color_pair_cache_get(fg, bg);
|
return _color_pair_cache_get(fg, bg);
|
||||||
|
@ -41,6 +41,12 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
COLOR_PROFILE_DEFAULT,
|
||||||
|
COLOR_PROFILE_REDGREEN,
|
||||||
|
COLOR_PROFILE_BLUE,
|
||||||
|
} color_profile;
|
||||||
|
|
||||||
struct color_def {
|
struct color_def {
|
||||||
uint16_t h; uint8_t s, l;
|
uint16_t h; uint8_t s, l;
|
||||||
const char *name;
|
const char *name;
|
||||||
@ -48,7 +54,7 @@ struct color_def {
|
|||||||
extern const struct color_def color_names[];
|
extern const struct color_def color_names[];
|
||||||
|
|
||||||
/* hash string to color pair */
|
/* hash string to color pair */
|
||||||
int color_pair_cache_hash_str(const char *str);
|
int color_pair_cache_hash_str(const char *str, color_profile profile);
|
||||||
/* parse fg_bg string to color pair */
|
/* parse fg_bg string to color pair */
|
||||||
int color_pair_cache_get(const char *pair_name);
|
int color_pair_cache_get(const char *pair_name);
|
||||||
/* clear cache */
|
/* clear cache */
|
||||||
|
@ -673,7 +673,17 @@ theme_free_string(char *str)
|
|||||||
int
|
int
|
||||||
theme_hash_attrs(const char *str)
|
theme_hash_attrs(const char *str)
|
||||||
{
|
{
|
||||||
return COLOR_PAIR(color_pair_cache_hash_str(str));
|
color_profile profile = COLOR_PROFILE_DEFAULT;
|
||||||
|
|
||||||
|
char *color_pref = prefs_get_string(PREF_COLOR_NICK);
|
||||||
|
if (strcmp(color_pref, "redgreen") == 0) {
|
||||||
|
profile = COLOR_PROFILE_REDGREEN;
|
||||||
|
} else if (strcmp(color_pref, "blue") == 0) {
|
||||||
|
profile = COLOR_PROFILE_BLUE;
|
||||||
|
}
|
||||||
|
prefs_free_string(color_pref);
|
||||||
|
|
||||||
|
return COLOR_PAIR(color_pair_cache_hash_str(str, profile));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -1971,12 +1971,21 @@ cons_autoping_setting(void)
|
|||||||
void
|
void
|
||||||
cons_color_setting(void)
|
cons_color_setting(void)
|
||||||
{
|
{
|
||||||
if (prefs_get_boolean(PREF_COLOR_NICK))
|
char *color_pref = prefs_get_string(PREF_COLOR_NICK);
|
||||||
|
|
||||||
|
if (strcmp(color_pref, "true") == 0) {
|
||||||
cons_show("Consistent color generation for nicks (/color) : ON");
|
cons_show("Consistent color generation for nicks (/color) : ON");
|
||||||
else
|
} else if (strcmp(color_pref, "redgreen") == 0) {
|
||||||
|
cons_show("Consistent color generation for nicks (/color) : REDGREEN");
|
||||||
|
} else if (strcmp(color_pref, "blue") == 0) {
|
||||||
|
cons_show("Consistent color generation for nicks (/color) : BLUE");
|
||||||
|
} else {
|
||||||
cons_show("Consistent color generation for nicks (/color) : OFF");
|
cons_show("Consistent color generation for nicks (/color) : OFF");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prefs_free_string(color_pref);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cons_show_connection_prefs(void)
|
cons_show_connection_prefs(void)
|
||||||
{
|
{
|
||||||
|
@ -1453,9 +1453,11 @@ _win_print(ProfWin *window, const char show_char, int pad_indent, GDateTime *tim
|
|||||||
colour = theme_attrs(THEME_THEM);
|
colour = theme_attrs(THEME_THEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (prefs_get_boolean(PREF_COLOR_NICK)) {
|
char *color_pref = prefs_get_string(PREF_COLOR_NICK);
|
||||||
|
if (color_pref != NULL && (strcmp(color_pref, "false") != 0)) {
|
||||||
colour = theme_hash_attrs(from);
|
colour = theme_hash_attrs(from);
|
||||||
}
|
}
|
||||||
|
prefs_free_string(color_pref);
|
||||||
|
|
||||||
if (flags & NO_COLOUR_FROM) {
|
if (flags & NO_COLOUR_FROM) {
|
||||||
colour = 0;
|
colour = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user