Beispiel #1
0
void
gui_color_palette_build_aliases ()
{
    int i;
    struct t_gui_color_palette *color_palette;
    char str_number[64];

    if (!gui_color_hash_palette_alias || !gui_color_list_with_alias
        || !gui_color_hash_palette_color)
    {
        gui_color_palette_alloc_structs ();
    }

    hashtable_remove_all (gui_color_hash_palette_alias);
    weelist_remove_all (gui_color_list_with_alias);
    for (i = 0; i < GUI_CURSES_NUM_WEECHAT_COLORS; i++)
    {
        weelist_add (gui_color_list_with_alias,
                     gui_weechat_colors[i].string,
                     WEECHAT_LIST_POS_END,
                     NULL);
    }
    for (i = 0; i <= gui_color_term_colors; i++)
    {
        color_palette = gui_color_palette_get (i);
        if (color_palette)
        {
            weelist_add (gui_color_list_with_alias,
                         color_palette->alias,
                         WEECHAT_LIST_POS_END,
                         NULL);
        }
        else
        {
            snprintf (str_number, sizeof (str_number),
                      "%d", i);
            weelist_add (gui_color_list_with_alias,
                         str_number,
                         WEECHAT_LIST_POS_END,
                         NULL);
        }
    }
    hashtable_map (gui_color_hash_palette_color,
                   &gui_color_palette_add_alias_cb, NULL);
}
Beispiel #2
0
const char *
gui_color_get_name (int num_color)
{
    static char color[16][64];
    static int index_color = 0;
    char str_attr[8];
    struct t_gui_color_palette *ptr_color_palette;

    /* init color string */
    index_color = (index_color + 1) % 16;
    color[index_color][0] = '\0';

    /* build string with extra-attributes */
    gui_color_attr_build_string (num_color, str_attr);

    if (num_color & GUI_COLOR_EXTENDED_FLAG)
    {
        /* search alias */
        ptr_color_palette = gui_color_palette_get (num_color & GUI_COLOR_EXTENDED_MASK);
        if (ptr_color_palette && ptr_color_palette->alias)
        {
            /* alias */
            snprintf (color[index_color], sizeof (color[index_color]),
                      "%s%s", str_attr, ptr_color_palette->alias);
        }
        else
        {
            /* color number */
            snprintf (color[index_color], sizeof (color[index_color]),
                      "%s%d", str_attr, num_color & GUI_COLOR_EXTENDED_MASK);
        }
    }
    else
    {
        snprintf (color[index_color], sizeof (color[index_color]),
                  "%s%s",
                  str_attr,
                  gui_weechat_colors[num_color & GUI_COLOR_EXTENDED_MASK].string);
    }

    return color[index_color];
}
Beispiel #3
0
void
gui_color_buffer_display ()
{
    int y, i, lines, line, col, color, max_color, num_items;
    char str_line[1024], str_color[64], str_rgb[64], **items;
    struct t_gui_color_palette *color_palette;

    if (!gui_color_buffer)
        return;

    gui_buffer_clear (gui_color_buffer);

    /* set title buffer */
    gui_buffer_set_title (gui_color_buffer,
                          _("WeeChat colors | Actions: "
                            "[e] Display extra infos [r] Refresh "
                            "[z] Reset colors [q] Close buffer | "
                            "Keys: [alt-c] Temporarily switch to terminal "
                            "colors"));

    /* display terminal/colors infos */
    y = 0;
    gui_color_info_term_colors (str_line, sizeof (str_line));
    gui_chat_printf_y (gui_color_buffer, y++, "%s", str_line);

    /* display palette of colors */
    y++;
    if (gui_color_use_term_colors)
    {
        gui_color_buffer_display_timer ();
        y++;
    }
    else
    {
        gui_chat_printf_y (gui_color_buffer, y++,
                           _("WeeChat color pairs (in use: %d, left: %d):"),
                           gui_color_pairs_used,
                           gui_color_num_pairs - gui_color_pairs_used);
    }
    max_color = (gui_color_use_term_colors) ?
        gui_color_term_colors - 1 : gui_color_num_pairs;
    if (max_color > 255)
        max_color = 255;
    lines = (max_color <= 64) ? 8 : 16;
    for (line = 0; line < lines; line++)
    {
        str_line[0] = '\0';
        for (col = 0; col < 16; col++)
        {
            color = (col * lines) + line;
            if (color <= max_color)
            {
                if (color == 0)
                {
                    snprintf (str_color, sizeof (str_color),
                              "     ");
                }
                else if (gui_color_use_term_colors
                         || (color <= gui_color_pairs_used))
                {
                    snprintf (str_color, sizeof (str_color),
                              "%c%c%05d%c%03d%c",
                              GUI_COLOR_COLOR_CHAR,
                              GUI_COLOR_EXTENDED_CHAR,
                              color,
                              (color == 0) ? '<' : ' ',
                              color,
                              (color == 0) ? '>' : ' ');
                }
                else
                {
                    snprintf (str_color, sizeof (str_color),
                              "%s  -  ",
                              GUI_NO_COLOR);
                }
                strcat (str_line, str_color);
            }
            else
            {
                snprintf (str_color, sizeof (str_color),
                          "%s     ",
                          GUI_COLOR(GUI_COLOR_CHAT));
                strcat (str_line, str_color);
            }
        }
        gui_chat_printf_y (gui_color_buffer, y++,
                           " %s",
                           str_line);
    }

    if (gui_color_buffer_extra_info)
    {
        /* display time of last auto reset of color pairs */
        y++;
        gui_chat_printf_y (gui_color_buffer, y++,
                           _("Last auto reset of pairs: %s"),
                           (gui_color_pairs_auto_reset_last == 0) ?
                           "-" : ctime (&gui_color_pairs_auto_reset_last));

        /* display WeeChat basic colors */
        y++;
        gui_chat_printf_y (gui_color_buffer, y++,
                           _("WeeChat basic colors:"));
        str_line[0] = '\0';
        for (i = 0; i < GUI_CURSES_NUM_WEECHAT_COLORS; i++)
        {
            if (gui_color_use_term_colors)
            {
                snprintf (str_color, sizeof (str_color),
                          " %s",
                          gui_weechat_colors[i].string);
            }
            else
            {
                snprintf (str_color, sizeof (str_color),
                          "%c%c%02d %s",
                          GUI_COLOR_COLOR_CHAR,
                          GUI_COLOR_FG_CHAR,
                          i,
                          gui_weechat_colors[i].string);
            }
            if (gui_chat_strlen_screen (str_line) + gui_chat_strlen_screen (str_color) > 80)
            {
                gui_chat_printf_y (gui_color_buffer, y++,
                                   " %s", str_line);
                str_line[0] = '\0';
            }
            strcat (str_line, str_color);
        }
        if (str_line[0])
        {
            gui_chat_printf_y (gui_color_buffer, y++,
                               " %s", str_line);
        }

        /* display nick colors */
        y++;
        gui_chat_printf_y (gui_color_buffer, y++,
                           _("Nick colors:"));
        items = string_split (CONFIG_STRING(config_color_chat_nick_colors),
                              ",", 0, 0, &num_items);
        if (items)
        {
            str_line[0] = '\0';
            for (i = 0; i < num_items; i++)
            {
                if (gui_color_use_term_colors)
                {
                    snprintf (str_color, sizeof (str_color),
                              " %s",
                              items[i]);
                }
                else
                {
                    snprintf (str_color, sizeof (str_color),
                              "%s %s",
                              gui_color_get_custom (items[i]),
                              items[i]);
                }
                if (gui_chat_strlen_screen (str_line) + gui_chat_strlen_screen (str_color) > 80)
                {
                    gui_chat_printf_y (gui_color_buffer, y++,
                                       " %s", str_line);
                    str_line[0] = '\0';
                }
                strcat (str_line, str_color);
            }
            if (str_line[0])
            {
                gui_chat_printf_y (gui_color_buffer, y++,
                                   " %s", str_line);
            }
            string_free_split (items);
        }

        /* display palette colors */
        if (gui_color_hash_palette_color->items_count > 0)
        {
            y++;
            gui_chat_printf_y (gui_color_buffer, y++,
                               _("Color aliases:"));
            for (i = 1; i <= gui_color_num_pairs; i++)
            {
                color_palette = gui_color_palette_get (i);
                if (color_palette)
                {
                    str_color[0] = '\0';
                    if (!gui_color_use_term_colors)
                    {
                        snprintf (str_color, sizeof (str_color),
                                  "%c%c%c%05d",
                                  GUI_COLOR_COLOR_CHAR,
                                  GUI_COLOR_FG_CHAR,
                                  GUI_COLOR_EXTENDED_CHAR,
                                  i);
                    }
                    str_rgb[0] = '\0';
                    if ((color_palette->r >= 0) && (color_palette->g >= 0)
                        && (color_palette->b >= 0))
                    {
                        snprintf (str_rgb, sizeof (str_rgb),
                                  " (%d/%d/%d)",
                                  color_palette->r,
                                  color_palette->g,
                                  color_palette->b);
                    }
                    gui_chat_printf_y (gui_color_buffer, y++,
                                       " %5d: %s%s%s",
                                       i,
                                       str_color,
                                       (color_palette->alias) ? color_palette->alias : "",
                                       str_rgb);
                }
            }
        }

        /* display content of colors */
        if (gui_color_term_color_content)
        {
            y++;
            gui_chat_printf_y (gui_color_buffer, y++,
                               _("Content of colors (r/g/b):"));
            for (i = 0; i < gui_color_term_colors; i++)
            {
                gui_chat_printf_y (gui_color_buffer, y++,
                                   " %3d: %4hd / %4hd / %4hd",
                                   i,
                                   gui_color_term_color_content[i * 3],
                                   gui_color_term_color_content[(i* 3) + 1],
                                   gui_color_term_color_content[(i* 3) + 2]);
            }
        }
    }
}
Beispiel #4
0
int
completion_list_add_config_option_values_cb (void *data,
                                             const char *completion_item,
                                             struct t_gui_buffer *buffer,
                                             struct t_gui_completion *completion)
{
    char *pos_space, *option_full_name, *pos_section, *pos_option;
    char *file, *section, *value_string, str_number[64];
    const char *color_name;
    int length, i, num_colors;
    struct t_config_file *ptr_config;
    struct t_config_section *ptr_section, *section_found;
    struct t_config_option *option_found;
    struct t_gui_color_palette *color_palette;

    /* make C compiler happy */
    (void) data;
    (void) completion_item;
    (void) buffer;

    if (completion->args)
    {
        pos_space = strchr (completion->args, ' ');
        if (pos_space)
            option_full_name = string_strndup (completion->args,
                                               pos_space - completion->args);
        else
            option_full_name = strdup (completion->args);

        if (option_full_name)
        {
            file = NULL;
            section = NULL;
            pos_option = NULL;

            pos_section = strchr (option_full_name, '.');
            pos_option = (pos_section) ? strchr (pos_section + 1, '.') : NULL;

            if (pos_section && pos_option)
            {
                file = string_strndup (option_full_name,
                                       pos_section - option_full_name);
                section = string_strndup (pos_section + 1,
                                          pos_option - pos_section - 1);
                pos_option++;
            }
            if (file && section && pos_option)
            {
                ptr_config = config_file_search (file);
                if (ptr_config)
                {
                    ptr_section = config_file_search_section (ptr_config,
                                                              section);
                    if (ptr_section)
                    {
                        config_file_search_section_option (ptr_config,
                                                           ptr_section,
                                                           pos_option,
                                                           &section_found,
                                                           &option_found);
                        if (option_found)
                        {
                            switch (option_found->type)
                            {
                                case CONFIG_OPTION_TYPE_BOOLEAN:
                                    gui_completion_list_add (completion, "on",
                                                             0, WEECHAT_LIST_POS_SORT);
                                    gui_completion_list_add (completion, "off",
                                                             0, WEECHAT_LIST_POS_SORT);
                                    gui_completion_list_add (completion, "toggle",
                                                             0, WEECHAT_LIST_POS_END);
                                    if (option_found->value)
                                    {
                                        if (CONFIG_BOOLEAN(option_found) == CONFIG_BOOLEAN_TRUE)
                                            gui_completion_list_add (completion, "on",
                                                                     0, WEECHAT_LIST_POS_BEGINNING);
                                        else
                                            gui_completion_list_add (completion, "off",
                                                                     0, WEECHAT_LIST_POS_BEGINNING);
                                    }
                                    else
                                    {
                                        gui_completion_list_add (completion,
                                                                 WEECHAT_CONFIG_OPTION_NULL,
                                                                 0, WEECHAT_LIST_POS_BEGINNING);
                                    }
                                    break;
                                case CONFIG_OPTION_TYPE_INTEGER:
                                    if (option_found->string_values)
                                    {
                                        for (i = 0; option_found->string_values[i]; i++)
                                        {
                                            gui_completion_list_add (completion,
                                                                     option_found->string_values[i],
                                                                     0, WEECHAT_LIST_POS_SORT);
                                        }
                                        gui_completion_list_add (completion, "++1",
                                                                 0, WEECHAT_LIST_POS_END);
                                        gui_completion_list_add (completion, "--1",
                                                                 0, WEECHAT_LIST_POS_END);
                                        if (option_found->value)
                                        {
                                            gui_completion_list_add (completion,
                                                                     option_found->string_values[CONFIG_INTEGER(option_found)],
                                                                     0, WEECHAT_LIST_POS_BEGINNING);
                                        }
                                        else
                                        {
                                            gui_completion_list_add (completion,
                                                                     WEECHAT_CONFIG_OPTION_NULL,
                                                                     0, WEECHAT_LIST_POS_BEGINNING);
                                        }
                                    }
                                    else
                                    {
                                        if (option_found->value && CONFIG_INTEGER(option_found) > option_found->min)
                                            gui_completion_list_add (completion, "--1",
                                                                     0, WEECHAT_LIST_POS_BEGINNING);
                                        if (option_found->value && CONFIG_INTEGER(option_found) < option_found->max)
                                            gui_completion_list_add (completion, "++1",
                                                                     0, WEECHAT_LIST_POS_BEGINNING);
                                        if (option_found->value)
                                        {
                                            length = 64;
                                            value_string = malloc (length);
                                            if (value_string)
                                            {
                                                snprintf (value_string, length,
                                                          "%d", CONFIG_INTEGER(option_found));
                                                gui_completion_list_add (completion,
                                                                         value_string,
                                                                         0, WEECHAT_LIST_POS_BEGINNING);
                                                free (value_string);
                                            }
                                        }
                                        else
                                        {
                                            gui_completion_list_add (completion,
                                                                     WEECHAT_CONFIG_OPTION_NULL,
                                                                     0, WEECHAT_LIST_POS_BEGINNING);
                                        }
                                    }
                                    break;
                                case CONFIG_OPTION_TYPE_STRING:
                                    gui_completion_list_add (completion,
                                                             "\"\"",
                                                             0, WEECHAT_LIST_POS_BEGINNING);
                                    if (option_found->value)
                                    {
                                        length = strlen (CONFIG_STRING(option_found)) + 2 + 1;
                                        value_string = malloc (length);
                                        if (value_string)
                                        {
                                            snprintf (value_string, length,
                                                      "\"%s\"",
                                                      CONFIG_STRING(option_found));
                                            gui_completion_list_add (completion,
                                                                     value_string,
                                                                     0, WEECHAT_LIST_POS_BEGINNING);
                                            free (value_string);
                                        }
                                    }
                                    else
                                    {
                                        gui_completion_list_add (completion,
                                                                 WEECHAT_CONFIG_OPTION_NULL,
                                                                 0, WEECHAT_LIST_POS_BEGINNING);
                                    }
                                    break;
                                case CONFIG_OPTION_TYPE_COLOR:
                                    num_colors = gui_color_get_weechat_colors_number ();
                                    for (i = 0; i < num_colors; i++)
                                    {
                                        color_name = gui_color_get_name (i);
                                        if (color_name)
                                        {
                                            gui_completion_list_add (completion,
                                                                     color_name,
                                                                     0, WEECHAT_LIST_POS_SORT);
                                        }
                                    }
                                    num_colors = gui_color_get_term_colors ();
                                    for (i = 0; i <= num_colors; i++)
                                    {
                                        color_palette = gui_color_palette_get (i);
                                        if (color_palette)
                                        {
                                            gui_completion_list_add (completion,
                                                                     color_palette->alias,
                                                                     0, WEECHAT_LIST_POS_END);
                                        }
                                        else
                                        {
                                            snprintf (str_number,
                                                      sizeof (str_number),
                                                      "%d",
                                                      i);
                                            gui_completion_list_add (completion,
                                                                     str_number,
                                                                     0, WEECHAT_LIST_POS_END);
                                        }
                                    }
                                    gui_completion_list_add (completion, "++1",
                                                             0, WEECHAT_LIST_POS_END);
                                    gui_completion_list_add (completion, "--1",
                                                             0, WEECHAT_LIST_POS_END);
                                    if (option_found->value)
                                    {
                                        color_name = gui_color_get_name (CONFIG_INTEGER(option_found));
                                        if (color_name)
                                        {
                                            gui_completion_list_add (completion,
                                                                     color_name,
                                                                     0, WEECHAT_LIST_POS_BEGINNING);
                                        }
                                    }
                                    else
                                    {
                                        gui_completion_list_add (completion,
                                                                 WEECHAT_CONFIG_OPTION_NULL,
                                                                 0, WEECHAT_LIST_POS_BEGINNING);
                                    }
                                    break;
                                case CONFIG_NUM_OPTION_TYPES:
                                    break;
                            }
                            if (option_found->value
                                && option_found->null_value_allowed)
                            {
                                gui_completion_list_add (completion,
                                                         WEECHAT_CONFIG_OPTION_NULL,
                                                         0,
                                                         WEECHAT_LIST_POS_END);
                            }
                        }
                    }
                }
            }
            if (file)
                free (file);
            if (section)
                free (section);
        }
    }

    return WEECHAT_RC_OK;
}