+ if(opt_get_bool(BOOL_USE_COLORS)) {
+ start_color();
+ use_default_colors();
+ ui_init_color_pairs_user();
+ }
+}
+
+void
+ui_enable_mouse(bool enabled)
+{
+ mmask_t mask;
+ if(enabled) {
+ mask = BUTTON1_CLICKED | BUTTON4_PRESSED;
+#if NCURSES_MOUSE_VERSION == 2
+ mask |= BUTTON5_PRESSED;
+#endif
+ } else {
+ mask = 0;
+ }
+ mousemask(mask, NULL);
+}
+
+/** Check the time elapsed since last click and tell if it should be
+ * interpreted as a double click
+ */
+static bool
+was_double_click() {
+ struct timeval click_time, click_diff, maxdiff;
+ maxdiff.tv_sec = double_click_interval / 1000;
+ maxdiff.tv_usec = (double_click_interval % 1000)*1000;
+ gettimeofday(&click_time, NULL);
+
+ timersub(&click_time, &last_click_time, &click_diff);
+ last_click_time = click_time;
+ return !timercmp(&click_diff, &maxdiff, >);
+}
+
+#define CHECK_COLOR_NAME(value, name, DEFNAME) \
+ if(!strcmp((name), (value))){ \
+ return DEFNAME; \
+ }
+short
+opt_color_to_color(enum str_opts enum_name)
+{
+ char* name = opt_get_str(enum_name);
+ CHECK_COLOR_NAME(name, "default", COLOR_DEFAULT)
+ else CHECK_COLOR_NAME(name, "black", COLOR_BLACK)
+ else CHECK_COLOR_NAME(name, "red", COLOR_RED)
+ else CHECK_COLOR_NAME(name, "green", COLOR_GREEN)
+ else CHECK_COLOR_NAME(name, "yellow", COLOR_YELLOW)
+ else CHECK_COLOR_NAME(name, "blue", COLOR_BLUE)
+ else CHECK_COLOR_NAME(name, "magenta", COLOR_MAGENTA)
+ else CHECK_COLOR_NAME(name, "cyan", COLOR_CYAN)
+ else CHECK_COLOR_NAME(name, "white", COLOR_WHITE)
+ else return COLOR_DEFAULT;
+}
+
+void
+ui_init_color_pairs_user()
+{
+ init_pair(CP_HEADER, opt_color_to_color(STR_COLOR_HEADER_FG),
+ opt_color_to_color(STR_COLOR_HEADER_BG));
+ init_pair(CP_FOOTER, opt_color_to_color(STR_COLOR_FOOTER_FG),
+ opt_color_to_color(STR_COLOR_FOOTER_BG));
+ init_pair(CP_LIST_EVEN, opt_color_to_color(STR_COLOR_LIST_EVEN_FG),
+ opt_color_to_color(STR_COLOR_LIST_EVEN_BG));
+ init_pair(CP_LIST_ODD, opt_color_to_color(STR_COLOR_LIST_ODD_FG),
+ opt_color_to_color(STR_COLOR_LIST_ODD_BG));
+ init_pair(CP_LIST_HEADER, opt_color_to_color(STR_COLOR_LIST_HEADER_FG),
+ opt_color_to_color(STR_COLOR_LIST_HEADER_BG));
+ init_pair(CP_LIST_HIGHLIGHT, opt_color_to_color(STR_COLOR_LIST_HIGHLIGHT_FG),
+ opt_color_to_color(STR_COLOR_LIST_HIGHLIGHT_BG));
+ init_pair(CP_TAB_BORDER, opt_color_to_color(STR_COLOR_TAB_BORDER_FG),
+ opt_color_to_color(STR_COLOR_TAB_BORDER_BG));
+ init_pair(CP_TAB_LABEL, opt_color_to_color(STR_COLOR_TAB_LABEL_FG),
+ opt_color_to_color(STR_COLOR_TAB_LABEL_BG));
+ init_pair(CP_FIELD_NAME, opt_color_to_color(STR_COLOR_FIELD_NAME_FG),
+ opt_color_to_color(STR_COLOR_FIELD_NAME_BG));
+ init_pair(CP_FIELD_VALUE, opt_color_to_color(STR_COLOR_FIELD_VALUE_FG),
+ opt_color_to_color(STR_COLOR_FIELD_VALUE_BG));
+}
+
+int
+init_ui()
+{
+ ui_init_curses();