From 1e348993f9f5724fe7325ab3358552d77171ad51 Mon Sep 17 00:00:00 2001 From: Tim Stack Date: Sun, 21 Apr 2024 07:30:47 -0700 Subject: [PATCH] [readline] skip adding append character to suggestion --- src/lnav_commands.cc | 2 +- src/readline_context.hh | 2 +- src/readline_curses.cc | 33 +++++++++++++++++++-------------- src/sql_commands.cc | 2 +- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/lnav_commands.cc b/src/lnav_commands.cc index dd41261e..f52b692f 100644 --- a/src/lnav_commands.cc +++ b/src/lnav_commands.cc @@ -481,7 +481,7 @@ com_set_file_timezone_prompt(exec_context& ec, const std::string& cmdline) return {new_prompt}; } - return {"", file_zone}; + return {"", file_zone + " "}; } catch (const std::runtime_error& e) { log_error("cannot get timezones: %s", e.what()); } diff --git a/src/readline_context.hh b/src/readline_context.hh index 1152c6a8..99f17421 100644 --- a/src/readline_context.hh +++ b/src/readline_context.hh @@ -200,7 +200,7 @@ private: std::map> rc_prototypes; std::map rc_commands; bool rc_case_sensitive; - int rc_append_character; + int rc_append_character{' '}; const char* rc_quote_chars; readline_highlighter_t rc_highlighter; std::vector rc_vars; diff --git a/src/readline_curses.cc b/src/readline_curses.cc index d51d8853..326b4534 100644 --- a/src/readline_curses.cc +++ b/src/readline_curses.cc @@ -414,6 +414,7 @@ readline_context::attempted_completion(const char* text, int start, int end) suggestion_possibilities.clear(); suggestion_possibilities.emplace(rc_local_suggestion); arg_possibilities = &suggestion_possibilities; + rl_completion_append_character = 0; } else if (at_start && loaded_context->rc_possibilities.find(cmd_key) != loaded_context->rc_possibilities.end()) @@ -680,8 +681,6 @@ readline_context::readline_context(std::string name, auto hpath = (config_dir / this->rc_name).string() + ".history"; read_history(hpath.c_str()); this->save(); - - this->rc_append_character = ' '; } void @@ -974,7 +973,6 @@ readline_curses::start() } else { uint64_t h1 = 1, h2 = 2; - rc_local_suggestion.clear(); if (rl_last_func == readline_context::command_complete) { rl_last_func = rl_menu_complete; } @@ -1014,14 +1012,17 @@ readline_curses::start() if (h1 == last_h1 && h2 == last_h2) { // do nothing - } else if (sendcmd(this->rc_command_pipe[RCF_SLAVE], - complete_done ? 'l' : 'c', - rl_line_buffer, - rl_end) - != 0) - { - perror("line: write failed"); - _exit(1); + } else { + rc_local_suggestion.clear(); + if (sendcmd(this->rc_command_pipe[RCF_SLAVE], + complete_done ? 'l' : 'c', + rl_line_buffer, + rl_end) + != 0) + { + perror("line: write failed"); + _exit(1); + } } last_h1 = h1; last_h2 = h2; @@ -1057,10 +1058,14 @@ readline_curses::start() if (rl_prompt) { new_point -= strlen(rl_prompt); } - if (0 <= new_point && new_point <= rl_end) { - rl_point = new_point; - rl_redisplay(); + if (new_point < 0) { + new_point = 0; } + if (new_point > rl_end) { + new_point = rl_end; + } + rl_point = new_point; + rl_redisplay(); } else if (sscanf(msg, "i:%d:%n", &rl_point, &prompt_start) == 1) { diff --git a/src/sql_commands.cc b/src/sql_commands.cc index e526d206..34f0603c 100644 --- a/src/sql_commands.cc +++ b/src/sql_commands.cc @@ -262,7 +262,7 @@ prql_cmd_from_prompt(exec_context& ec, const std::string& cmdline) = line_pair->first->get_format_ptr()->get_name().to_string(); return { "", - lnav::prql::quote_ident(format_name), + lnav::prql::quote_ident(format_name) + " ", }; }