From 0a40624443576a8929d9f2370d52248cab9245fe Mon Sep 17 00:00:00 2001 From: Kalle Wallin Date: Fri, 18 Jun 2004 14:21:53 +0000 Subject: [PATCH] Added completion stuff git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1556 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/screen_utils.c | 22 ++++++++++++++++++++++ src/screen_utils.h | 9 +++++++-- src/wreadln.c | 8 +++++++- src/wreadln.h | 8 ++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/screen_utils.c b/src/screen_utils.c index 398fdd9..16359c6 100644 --- a/src/screen_utils.c +++ b/src/screen_utils.c @@ -159,4 +159,26 @@ screen_find(screen_t *screen, return 0; } +void +screen_display_completion_list(screen_t *screen, GList *list) +{ + WINDOW *w = screen->main_window.w; + gint y=0; + colors_use(w, COLOR_STATUS_ALERT); + while( ymain_window.rows ) + { + wmove(w, y++, 0); + wclrtoeol(w); + if( list ) + { + gchar *tmp = g_strdup(list->data); + waddstr(w, basename(tmp)); + g_free(tmp); + list = list->next; + } + } + wrefresh(w); + doupdate(); + colors_use(w, COLOR_LIST); +} diff --git a/src/screen_utils.h b/src/screen_utils.h index b6e8d11..d60a338 100644 --- a/src/screen_utils.h +++ b/src/screen_utils.h @@ -1,9 +1,13 @@ +#ifndef SCREEN_UTILS_H +#define SCREEN_UTILS_H /* read a characher from the status window */ int screen_getch(WINDOW *w, char *prompt); /* read a string from the status window */ char *screen_getstr(WINDOW *w, char *prompt); +char *screen_readln(WINDOW *w, char *prompt, char *value, + GList **history, GCompletion *gcmp); /* query user for a string and find it in a list window */ int screen_find(screen_t *screen, @@ -14,5 +18,6 @@ int screen_find(screen_t *screen, list_window_callback_fn_t callback_fn); -int my_waddstr(WINDOW *, const char *, int); -int my_mvwaddstr(WINDOW *, int, int, const char *, int); +void screen_display_completion_list(screen_t *screen, GList *list); + +#endif diff --git a/src/wreadln.c b/src/wreadln.c index 6ac94b7..b5caef7 100644 --- a/src/wreadln.c +++ b/src/wreadln.c @@ -39,6 +39,8 @@ unsigned int wrln_max_line_size = WRLN_MAX_LINE_SIZE; unsigned int wrln_max_history_length = WRLN_MAX_HISTORY_LENGTH; GVoidFunc wrln_resize_callback = NULL; +wrln_gcmp_pre_cb_t wrln_pre_completion_callback = NULL; +wrln_gcmp_post_cb_t wrln_post_completion_callback = NULL; char * @@ -183,7 +185,9 @@ wreadln(WINDOW *w, char *prefix = NULL; GList *list; - list = g_completion_complete(gcmp, line, &prefix); + if(wrln_pre_completion_callback) + wrln_pre_completion_callback(gcmp, line); + list = g_completion_complete(gcmp, line, &prefix); if( prefix ) { int len = strlen(prefix); @@ -193,6 +197,8 @@ wreadln(WINDOW *w, } else beep(); + if( wrln_post_completion_callback ) + wrln_post_completion_callback(gcmp, line, list); } break; diff --git a/src/wreadln.h b/src/wreadln.h index 270d73f..520ba2a 100644 --- a/src/wreadln.h +++ b/src/wreadln.h @@ -10,6 +10,14 @@ extern unsigned int wrln_max_history_length; /* a callback function for KEY_RESIZE */ extern GVoidFunc wrln_resize_callback; +/* called after TAB is pressed but before g_completion_complete */ +typedef void (*wrln_gcmp_pre_cb_t) (GCompletion *gcmp, gchar *buf); +extern wrln_gcmp_pre_cb_t wrln_pre_completion_callback; + +/* post completion callback */ +typedef void (*wrln_gcmp_post_cb_t) (GCompletion *gcmp, gchar *s, GList *l); +extern wrln_gcmp_post_cb_t wrln_post_completion_callback; + /* Note, wreadln calls curs_set() and noecho(), to enable cursor and * disable echo. wreadln will not restore these settings when exiting! */ char *wreadln(WINDOW *w, /* the curses window to use */ -- 2.30.2