From 3815d708662e2a3c288b70009b2799bbce4fc964 Mon Sep 17 00:00:00 2001 From: Bradley Smith Date: Sat, 8 Mar 2008 23:17:19 +0000 Subject: Add readline support to text plugin. Signed-off-by: Bradley Smith --- ChangeLog | 8 ++++++++ lib/Makefile.am | 2 +- lib/textplugin.c | 22 +++++++++++++++++++--- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index decaefd..3446a76 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,12 @@ * src/main.c: Add error message when given an invalid instruction. Add initial ui update to avoid corruption. + * lib/textplugin.c: + Add readline support to text plugin + * lib/Makefile.am: + Add readline libs/includes to text plugin + * src/Makefile.am: + Change binary name to gnurobots 2008-03-07 Bradley Smith @@ -17,6 +23,8 @@ Add readline/history support to command line. * various: Fix code to compile with stricter flags. + * lib/Makefile.am: + Add readline libs/includes to x11 plugin 2005-09-06 Zeeshan Ali Khattak * src/main.c src/api.c include/api.h include/main.h: diff --git a/lib/Makefile.am b/lib/Makefile.am index 36a2a6c..f0ec6ab 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -36,7 +36,7 @@ pkglib_LTLIBRARIES = libgrobots-text.la $(CURSES_PLUGIN) $(X11_PLUGIN) libgrobots_text_la_SOURCES = textplugin.c libgrobots_text_la_LDFLAGS = -module -avoid-version -libgrobots_text_la_LIBADD = $(GLIB2_LIBS) +libgrobots_text_la_LIBADD = $(GLIB2_LIBS) $(READLINE_LIBS) libgrobots_curses_la_SOURCES = cursesplugin.c libgrobots_curses_la_LDFLAGS = -module -avoid-version diff --git a/lib/textplugin.c b/lib/textplugin.c index 61110d5..0c3059c 100644 --- a/lib/textplugin.c +++ b/lib/textplugin.c @@ -23,13 +23,17 @@ #include #include #include +#include #include "configs.h" #include "textplugin.h" +#include +#include + enum { ARG_0, - ARG_MAP + ARG_MAP }; GType _text_plugin_type = 0; @@ -350,8 +354,20 @@ inline void text_plugin_get_string (TextPlugin *text, gchar *buff, gint len) { - fputs (prompt, stdout); - fgets (buff, len, stdin); + char* line = (char*)NULL; + + line = readline(prompt); + + if(line && *line) + { + add_history(line); + + g_strlcpy(buff, line, len); + } + else + buff = ""; + + free(line); } inline void text_plugin_update_status (TextPlugin *text, -- cgit v1.1