From 3e1bb777ce9c8de3dbe55dee4e454241eddc98d1 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 4 Nov 2013 21:53:10 +0000 Subject: Add automatic completion display in prompt mode Controlled by the autoshowcompl option Completers now take a CompletionFlag parameter, used to specify we want fast completion (tag completion can be slow, we do not want to run it if not explicitely wanted by the user). --- src/client.cc | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'src/client.cc') diff --git a/src/client.cc b/src/client.cc index a596a961..d999816f 100644 --- a/src/client.cc +++ b/src/client.cc @@ -267,7 +267,7 @@ public: display_line.insert(display_line.begin(), { "filter:"_str, get_color("Prompt") }); context().print_status(display_line); } - } + } String description() const override { @@ -410,9 +410,9 @@ public: const bool reverse = (key == Key::BackTab); CandidateList& candidates = m_completions.candidates; // first try, we need to ask our completer for completions - if (m_current_completion == -1) + if (candidates.empty()) { - m_completions = m_completer(context(), line, + m_completions = m_completer(context(), CompletionFlags::None, line, line.byte_count_to(m_line_editor.cursor_pos())); if (candidates.empty()) return; @@ -451,13 +451,26 @@ public: // when we have only one completion candidate, make next tab complete // from the new content. if (candidates.size() == 1) - m_current_completion = -1; + candidates.clear(); } else { - context().ui().menu_hide(); - m_current_completion = -1; m_line_editor.handle_key(key); + m_current_completion = -1; + context().ui().menu_hide(); + + if (context().options()["autoshowcompl"].get()) try + { + m_completions = m_completer(context(), CompletionFlags::Fast, line, + line.byte_count_to(m_line_editor.cursor_pos())); + CandidateList& candidates = m_completions.candidates; + if (not candidates.empty()) + { + DisplayCoord menu_pos{ context().ui().dimensions().line, 0_char }; + context().ui().menu_show(candidates, menu_pos, get_color("MenuForeground"), + get_color("MenuBackground"), MenuStyle::Prompt); + } + } catch (runtime_error&) {} } display(); m_callback(line, PromptEvent::Change, context()); -- cgit v1.2.3