From 55cac6f2e54b6b620f6c1e6dcf0056fe8ad7c888 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Mon, 11 May 2020 22:04:01 +0300 Subject: [PATCH] mu-server: disable readline support for now Seems to be causing problem in non-interactive mode --- mu/mu-cmd-server.cc | 91 ++------------------------------------------- 1 file changed, 3 insertions(+), 88 deletions(-) diff --git a/mu/mu-cmd-server.cc b/mu/mu-cmd-server.cc index d6261d60..11811d09 100644 --- a/mu/mu-cmd-server.cc +++ b/mu/mu-cmd-server.cc @@ -20,7 +20,6 @@ #include "config.h" #include "mu-cmd.h" - #include #include #include @@ -29,33 +28,6 @@ #include #include -#ifdef HAVE_LIBREADLINE -# if defined(HAVE_READLINE_READLINE_H) -# include -# elif defined(HAVE_READLINE_H) -# include -# else /* !defined(HAVE_READLINE_H) */ -extern char *readline (); -# endif /* !defined(HAVE_READLINE_H) */ -char *cmdline = NULL; -#else /* !defined(HAVE_READLINE_READLINE_H) */ - /* no readline */ -#endif /* HAVE_LIBREADLINE */ - -#ifdef HAVE_READLINE_HISTORY -# if defined(HAVE_READLINE_HISTORY_H) -# include -# elif defined(HAVE_HISTORY_H) -# include -# else /* !defined(HAVE_HISTORY_H) */ -extern void add_history (); -extern int write_history (); -extern int read_history (); -# endif /* defined(HAVE_READLINE_HISTORY_H) */ - /* no history */ -#endif /* HAVE_READLINE_HISTORY */ - - #include "mu-runtime.h" #include "mu-cmd.h" #include "mu-maildir.h" @@ -1299,59 +1271,8 @@ make_command_map (Context& context) } -struct Readline { - Readline (const std::string& histpath, size_t max_lines); - ~Readline(); - std::string read_line(bool& do_quit); - void save_line(const std::string& line); - std::string histpath_; - size_t max_lines_{0}; -}; - -/// Wrapper around readline (if available) or nothing otherwise. -#if defined(HAVE_LIBREADLINE) && defined(HAVE_READLINE_HISTORY) -Readline::Readline (const std::string& histpath, size_t max_lines): - histpath_{histpath}, max_lines_{max_lines} -{ - rl_bind_key('\t', rl_insert); // default (filenames) is not useful - using_history(); - read_history (histpath_.c_str()); - - if (max_lines_ > 0) - stifle_history(max_lines_); -} - -Readline::~Readline () { - write_history(histpath_.c_str()); - if (max_lines_ > 0) - history_truncate_file (histpath_.c_str(), max_lines_); -} - -std::string -Readline::read_line(bool& do_quit) -{ - auto buf = readline(";; mu% "); - if (!buf) { - do_quit = true; - return {}; - } - std::string line{buf}; - ::free (buf); - return line; -} - -void -Readline::save_line(const std::string& line) -{ - add_history(line.c_str()); -} -#else -Readline::Readline (const std::string& histpath, size_t max_lines) {} -Readline::~Readline() {} -void Readline::save_line(const std::string& line) {} - -std::string -Readline::read_line(bool& do_quit) +static std::string +read_line(bool& do_quit) { std::string line; std::cout << ";; mu> "; @@ -1359,8 +1280,6 @@ Readline::read_line(bool& do_quit) do_quit = true; return line; } -#endif // ! defined(HAVE_LIBREADLINE) && defined(HAVE_READLINE_HISTORY) - MuError mu_cmd_server (MuConfig *opts, GError **err) try @@ -1381,9 +1300,6 @@ mu_cmd_server (MuConfig *opts, GError **err) try return MU_OK; } - const auto histpath{std::string{mu_runtime_path(MU_RUNTIME_PATH_CACHE)} + "/history"}; - Readline readline(histpath, 50); - install_sig_handler(); std::cout << ";; Welcome to the " << PACKAGE_STRING << " command-server\n" << ";; Use (help) to get a list of commands, (quit) to quit.\n"; @@ -1392,12 +1308,11 @@ mu_cmd_server (MuConfig *opts, GError **err) try std::string line; try { - line = readline.read_line(context.do_quit); + line = read_line(context.do_quit); if (line.find_first_not_of(" \t") == std::string::npos) continue; // skip whitespace-only lines auto call{Sexp::parse(line)}; - readline.save_line(line); invoke(context.command_map, call);