diff --git a/Makefile b/Makefile index e63a92b3..335752b8 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ history.o: history.h prof_history.h contact_list.o: contact_list.h contact.h prof_autocomplete.h prof_history.o: prof_history.h contact.o: contact.h -preferences.o: preferences.h +preferences.o: preferences.h log.h prof_autocomplete.o: prof_autocomplete.h common.h main.o: profanity.h diff --git a/input_win.c b/input_win.c index 1a1049ff..1c9fdd02 100644 --- a/input_win.c +++ b/input_win.c @@ -59,6 +59,7 @@ void create_input_window(void) getmaxyx(stdscr, rows, cols); inp_win = newwin(1, cols, rows-1, 0); + wbkgd(inp_win, COLOR_PAIR(1)); keypad(inp_win, TRUE); wattrset(inp_win, A_BOLD); wmove(inp_win, 0, 1); diff --git a/preferences.c b/preferences.c index 65cc3dc1..2eabb028 100644 --- a/preferences.c +++ b/preferences.c @@ -26,6 +26,7 @@ #include #include +#include "log.h" #include "preferences.h" #include "prof_autocomplete.h" @@ -39,9 +40,10 @@ struct colour_string_t { char *str; NCURSES_COLOR_T colour; }; -/* + +static int num_colours = 7; static struct colour_string_t colours[] = { - { "bkgnd", -1 }, + { "default", -1 }, { "white", COLOR_WHITE }, { "green", COLOR_GREEN }, { "red", COLOR_RED }, @@ -49,7 +51,7 @@ static struct colour_string_t colours[] = { { "blue", COLOR_BLUE }, { "cyan", COLOR_CYAN }, }; -*/ + // colour preferences static struct colours_t { NCURSES_COLOR_T bkgnd; @@ -61,6 +63,7 @@ static struct colours_t { NCURSES_COLOR_T bar_text; } colour_prefs; +static NCURSES_COLOR_T _lookup_colour(const char * const colour); static void _load_colours(void); static void _save_prefs(void); @@ -86,10 +89,61 @@ void prefs_load(void) _load_colours(); } +static NCURSES_COLOR_T _lookup_colour(const char * const colour) +{ + int i; + for (i = 0; i < num_colours; i++) { + if (strcmp(colours[i].str, colour) == 0) { + return colours[i].colour; + } + } + + return -99; +} +/* +static void _set_colour(gchar *val, NCURSES_COLOR_T *pref, + NCURSES_COLOR_T def) +{ + if(!val) { + *pref = def; + } else { + NCURSES_COLOR_T col = _lookup_colour(val); + if (col == -99) { + *pref = def; + } else { + *pref = col; + } + } +} +*/ static void _load_colours(void) { - colour_prefs.bkgnd = -1; - colour_prefs.text = COLOR_WHITE; + gchar *bkgnd_val = g_key_file_get_string(prefs, "colours", "bkgnd", NULL); + + if(!bkgnd_val) { + colour_prefs.bkgnd = -1; + } else { + NCURSES_COLOR_T col = _lookup_colour(bkgnd_val); + if (col == -99) { + colour_prefs.bkgnd = -1; + } else { + colour_prefs.bkgnd = col; + } + } + + gchar *text_val = g_key_file_get_string(prefs, "colours", "text", NULL); + + if(!text_val) { + colour_prefs.text = COLOR_WHITE; + } else { + NCURSES_COLOR_T col = _lookup_colour(text_val); + if (col == -99) { + colour_prefs.text = COLOR_WHITE; + } else { + colour_prefs.text = col; + } + } + colour_prefs.online = COLOR_GREEN; colour_prefs.err = COLOR_RED; colour_prefs.inc = COLOR_YELLOW; diff --git a/profanity.c b/profanity.c index bd93467c..7df6ba3a 100644 --- a/profanity.c +++ b/profanity.c @@ -65,8 +65,8 @@ void profanity_run(void) void profanity_init(const int disable_tls) { - prefs_load(); log_init(); + prefs_load(); gui_init(); jabber_init(disable_tls); command_init(); diff --git a/windows.c b/windows.c index bf82766b..08de9c93 100644 --- a/windows.c +++ b/windows.c @@ -387,6 +387,7 @@ static void _create_windows(void) struct prof_win cons; strcpy(cons.from, CONS_WIN_TITLE); cons.win = newpad(PAD_SIZE, cols); + wbkgd(cons.win, COLOR_PAIR(1)); cons.y_pos = 0; cons.paged = 0; scrollok(cons.win, TRUE); @@ -411,6 +412,7 @@ static void _create_windows(void) struct prof_win chat; strcpy(chat.from, ""); chat.win = newpad(PAD_SIZE, cols); + wbkgd(chat.win, COLOR_PAIR(1)); chat.y_pos = 0; chat.paged = 0; wattrset(chat.win, A_BOLD);