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

static void copy(GtkWidget *button, GtkWidget *term)
{
    vte_terminal_copy_clipboard_format(VTE_TERMINAL(term), VTE_FORMAT_TEXT);
}

static void paste(GtkWidget *button, GtkWidget *term)
{
    vte_terminal_paste_clipboard(VTE_TERMINAL(term));
}

static void reset(GtkWidget *button, GtkWidget *term)
{
    vte_terminal_reset(VTE_TERMINAL(term), FALSE, FALSE);
}

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

    GtkWidget *copy_button = gtk_button_new_with_label("Copy");
    GtkWidget *paste_button = gtk_button_new_with_label("Paste");
    GtkWidget *reset_button = gtk_button_new_with_label("Reset");

    GtkWidget *term = vte_terminal_new();
    g_signal_connect(copy_button, "clicked", G_CALLBACK(copy), term);
    g_signal_connect(paste_button, "clicked", G_CALLBACK(paste), term);
    g_signal_connect(reset_button, "clicked", G_CALLBACK(reset), term);

    GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
    gtk_box_pack_start(GTK_BOX(box), copy_button, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(box), paste_button, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(box), reset_button, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(box), term, TRUE, TRUE, 0);

    GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_container_add(GTK_CONTAINER(window), box);
    gtk_widget_show_all(window);

    char *cmd[] = {"/bin/bash", NULL};
    vte_terminal_spawn_async(VTE_TERMINAL(term), VTE_PTY_DEFAULT, NULL, cmd,
                             NULL, G_SPAWN_DEFAULT, NULL, NULL, NULL, -1, NULL,
                             NULL, NULL);

    g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
    g_signal_connect(term, "child-exited", G_CALLBACK(gtk_main_quit), NULL);

    gtk_main();

    return 0;
}
