From 25ecf2d21f41cff57758f35ec36ce060fdf5696f Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sat, 2 Jun 2012 08:46:46 -0400 Subject: [PATCH] start implementation of scrollback completion --- termite.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/termite.c b/termite.c index 03be86a..b77f836 100644 --- a/termite.c +++ b/termite.c @@ -1,4 +1,7 @@ +#define _POSIX_C_SOURCE 200809L + #include +#include #include #include @@ -20,6 +23,37 @@ typedef struct search_panel_info { bool reverse; } search_panel_info; +static gboolean always_selected(VteTerminal *vte, glong column, glong row) { + return TRUE; +} + +static void complete(VteTerminal *vte) { + // TODO: get the full buffer + gchar *content = vte_terminal_get_text(vte, + (VteSelectionFunc)always_selected, + NULL, + NULL); + + if (!content) { + fputs("no content", stderr); + return; + } + + char *s_ptr = content, *saveptr; + + for (int j = 1; ; j++, s_ptr = NULL) { + char *token = strtok_r(s_ptr, " \n", &saveptr); + if (!token) { + break; + } + printf("token %d: %s\n", j, token); + } + + // TODO: GtkEntryCompletion widget + + g_free(content); +} + static void search(VteTerminal *vte, const char *pattern, bool reverse) { GRegex *regex = vte_terminal_search_get_gregex(vte); if (regex) g_regex_unref(regex); @@ -87,6 +121,10 @@ static gboolean key_press_cb(VteTerminal *vte, GdkEventKey *event, search_panel_ return TRUE; } } + if (modifiers == GDK_CONTROL_MASK && event->keyval == GDK_KEY_Tab) { + complete(vte); + return TRUE; + } return FALSE; }