23
23
#include <gio/gunixinputstream.h>
24
24
#include <gtk/gtk.h>
27
#include <readline/readline.h>
28
#include <readline/history.h>
32
26
#include <hud-client.h>
35
29
static void print_suggestions(const char * query);
36
static void update(char *string);
39
WINDOW *twindow = NULL;
41
31
static HudClientQuery * client_query = NULL;
53
char *line = (char*) malloc(256 * sizeof(char));
55
signal(SIGINT, sighandler);
58
if (!isatty (STDIN_FILENO) ) {
61
r = getline (&line, &a, stdin);
64
perror("Error reading from pipe");
69
if( line[r-1] == '\n' )
72
printf("\nsearch token: %s\n", line);
73
print_suggestions( line );
75
// read command line parameter - hud-cli "search string"
77
printf("\nsearch token: %s\n", argv[1]);
78
print_suggestions( argv[1] );
89
/* initialize the query screen */
92
/* interactive shell interface */
95
single_char = getch();
96
/* need to go left in the buffer */
97
if ( single_char == KEY_BACKSPACE ){
98
/* don't go too far left */
105
; /* we are at the beginning of the buffer already */
107
/* ENTER will trigger the action for the first selected suggestion */
108
else if ( single_char == '\n' ){
110
/* FIXME: execute action on RETURN */
113
/* add character to the buffer and terminate string */
114
else if ( single_char != KEY_RESIZE ) {
115
if ( pos < 256 -1 ){ // -1 for \0
116
line[pos] = single_char;
40
const gchar * search = "";
46
printf("\nsearch token: %s\n", search);
47
print_suggestions(search);
134
49
g_clear_object(&client_query);
140
update( char *string ){
143
mvwprintw(twindow, 7, 10, "Search: %s", string);
145
print_suggestions( string );
147
// move cursor back to input line
148
wmove( twindow, 7, 10 + 8 + strlen(string) );
154
55
wait_for_sync_notify (GObject * object, GParamSpec * pspec, gpointer user_data)
192
95
DeeModelIter * iter = NULL;
194
97
for (iter = dee_model_get_first_iter(model); !dee_model_is_last(model, iter); iter = dee_model_next(model, iter), i++) {
195
const gchar * suggestion = hud_client_query_results_get_command_name(client_query, iter);
197
mvwprintw(twindow, 9 + i, 15, "%s", suggestion);
199
gchar * clean_line = NULL;
200
pango_parse_markup(suggestion, -1, 0, NULL, &clean_line, NULL, NULL);
201
printf("\t%s\n", clean_line);
98
const gchar * suggestion = dee_model_get_string(model, iter, 1);
100
gchar * clean_line = NULL;
101
pango_parse_markup(suggestion, -1, 0, NULL, &clean_line, NULL, NULL);
102
printf("\t%s\n", clean_line);
210
void sighandler(int signal){
212
g_clear_object(&client_query);