Change how word splitting works when completing
Previously, I relied on replxx to correctly split words based on
word-splitting characters. However, as completion gets more complex and
completions possibly insert word-splitting characters, it starts to do
weird stuff like deleting some of your input. Fortunately, replxx allows
you to set the context length for completion - that is, how many
character it should consider as part of the word you're completing.
Change-Id: I035ac5059c8ab125efedb90cbeb2910f20da04a7
diff --git a/src/main.cpp b/src/main.cpp
index f1a2603..c6e3fce 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -38,16 +38,15 @@
SysrepoAccess datastore("netconf-cli");
Parser parser(datastore.schema());
replxx::Replxx lineEditor;
- lineEditor.set_completion_callback([&parser](const std::string& input, int&) {
+ lineEditor.set_completion_callback([&parser](const std::string& input, int& context) {
std::stringstream stream;
- auto completionsSet = parser.completeCommand(input, stream);
+ auto completions = parser.completeCommand(input, stream);
std::vector<replxx::Replxx::Completion> res;
- std::transform(completionsSet.begin(), completionsSet.end(), std::back_inserter(res),
- [input](auto it) { return it; });
+ std::copy(completions.m_completions.begin(), completions.m_completions.end(), std::back_inserter(res));
+ context = completions.m_contextLength;
return res;
});
- lineEditor.set_word_break_characters(" '/[");
std::optional<std::string> historyFile;
if (auto xdgHome = getenv("XDG_DATA_HOME")) {