Skip to content

Instantly share code, notes, and snippets.

@felipec
Last active March 20, 2023 15:49
Show Gist options
  • Save felipec/d6eb46d471dea2ed3b2b354e71f1aa6b to your computer and use it in GitHub Desktop.
Save felipec/d6eb46d471dea2ed3b2b354e71f1aa6b to your computer and use it in GitHub Desktop.
Test for vte buggy code
#include <vte/vte.h>
char *cmd = "(for i in $(seq 1 10); do echo $i; sleep 1; done) & exit";
static void run(VteTerminal *terminal)
{
char * const argv[] = { "/bin/bash", "-i", "-c", cmd, NULL };
vte_terminal_spawn_async(terminal,
0, NULL, (char **)argv, NULL, 0, NULL, NULL, NULL, -1, NULL, NULL, NULL);
}
static void child_exited(VteTerminal *terminal)
{
printf("child_exited: ignoring\n");
}
static void eof(VteTerminal *terminal)
{
printf("eof: running again\n");
run(terminal);
}
static void activate(GtkApplication* app)
{
GtkWidget *window = gtk_application_window_new(app);
GtkWidget *terminal = vte_terminal_new();
gtk_window_set_default_size(GTK_WINDOW(window), 800, 400);
g_signal_connect(G_OBJECT(terminal), "child-exited", G_CALLBACK(child_exited), NULL);
g_signal_connect(G_OBJECT(terminal), "eof", G_CALLBACK(eof), NULL);
gtk_container_add(GTK_CONTAINER(window), terminal);
gtk_widget_show_all(window);
run(VTE_TERMINAL(terminal));
}
int main(int argc, char *argv[])
{
GtkApplication *app = gtk_application_new("org.gtk.vte-client", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect(app, "activate", G_CALLBACK(activate), NULL);
if (argc > 1)
cmd = argv[1];
return g_application_run(G_APPLICATION(app), 0, NULL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment