// compile with: gcc -std=c99 dim_bug.c `pkg-config --libs --cflags gtk+-3.0 vte-2.90`
// run the program, and then: echo -e $(tput setaf 5)'normal \e[2mdim'
// expected output: the dim text should be black

#include <gtk/gtk.h>
#include <vte/vte.h>

int main(int argc, char **argv) {
    gtk_init(&argc, &argv);

    GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    GtkWidget *vte = vte_terminal_new();
    gtk_container_add(GTK_CONTAINER(window), vte);

    char *command[] = {vte_get_user_shell(), NULL};

    vte_terminal_fork_command_full(VTE_TERMINAL(vte), VTE_PTY_DEFAULT, NULL, command, NULL, 0, NULL, NULL, NULL, NULL);

    const char *colors[24] = {"#333", "#755", "#6ba", "#da8", "#d8c", "#d8c", "#898", "#ddc",
                              "#798", "#cb9", "#6c6", "#dfd", "#595", "#e9d", "#248", "#532",
                              "#000", "#000", "#000", "#000", "#000", "#000", "#000", "#000"};

    GdkColor palette[24];

    for (unsigned i = 0; i < 24; i++) {
        if (!gdk_color_parse(colors[i], &palette[i])) {
            return 1;
        }
    }

    vte_terminal_set_colors(VTE_TERMINAL(vte), NULL, NULL, palette, 24);

    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
    g_signal_connect(vte, "child-exited", G_CALLBACK(gtk_main_quit), NULL);

    gtk_widget_show_all(window);
    gtk_main();
    return 0;
}
