From cd0e606efe969d8361fd38b4ca959183feeddc9b Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 4 Sep 2009 13:47:12 +0200 Subject: Don't use GNU readline --- src/madc.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) (limited to 'src/madc.cpp') diff --git a/src/madc.cpp b/src/madc.cpp index 1017912..fc95266 100644 --- a/src/madc.cpp +++ b/src/madc.cpp @@ -36,14 +36,10 @@ #include +#include #include -#ifdef EDITLINE_FOUND -# include -#else -# include -# include -#endif +#include using namespace Mad; @@ -53,6 +49,10 @@ static void usage(const std::string &cmd) { std::cerr << "Usage: " << cmd << " [host[:port]]" << std::endl; } +static char* prompt(EditLine* /*e*/) { + return const_cast("mad> "); +} + int main(int argc, char *argv[]) { if(argc > 2) { usage(argv[0]); @@ -125,19 +125,33 @@ int main(int argc, char *argv[]) { Client::CommandParser commandParser(&application, connection); + EditLine *el = el_init(argv[0], stdin, stdout, stderr); + + el_set(el, EL_EDITOR, "emacs"); + el_set(el, EL_PROMPT, &prompt); + + HistEvent histEv; + History *hist = history_init(); + history(hist, &histEv, H_SETSIZE, 800); + + el_set(el, EL_HIST, history, hist); + while(connection->isConnected() && !commandParser.willDisconnect()) { - char *cmd = readline("mad> "); + const char *cmd = el_gets(el, 0); if(!cmd) { commandParser.requestDisconnect(); } else if(*cmd) { commandParser.parse(cmd); - add_history(cmd); + history(hist, &histEv, H_ENTER, cmd); } else continue; } + history_end(hist); + el_end(el); + connection->waitWhileConnected(); application.getUserManager()->unregisterBackend(networkUserBackend); -- cgit v1.2.3