Switch from linenoise to replxx

Change-Id: Id3e04eca8dbd7e68cef080713296fef3fdc683c5
diff --git a/src/main.cpp b/src/main.cpp
index 3c973dd..4fe798f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -5,11 +5,10 @@
  * Written by Václav Kubernát <kubervac@fit.cvut.cz>
  *
 */
-
 #include <docopt.h>
 #include <experimental/filesystem>
 #include <iostream>
-#include <linenoise.hpp>
+#include <replxx.hxx>
 #include "NETCONF_CLI_VERSION.h"
 #include "interpreter.hpp"
 #include "sysrepo_access.hpp"
@@ -37,24 +36,27 @@
 
     SysrepoAccess datastore("netconf-cli");
     Parser parser(datastore.schema());
+    replxx::Replxx lineEditor;
+    lineEditor.set_completion_callback([&parser](const std::string& input, int&) {
+        std::stringstream stream;
+        auto completionsSet = parser.completeCommand(input, stream);
+
+        std::vector<std::string> res;
+        std::transform(completionsSet.begin(), completionsSet.end(), std::back_inserter(res),
+                [input](auto it) { return it; });
+        return res;
+    });
+    lineEditor.set_word_break_characters(" '/[");
 
     while (true) {
-        linenoise::SetCompletionCallback([&parser](const char* editBuffer, std::vector<std::string>& completions) {
-            std::stringstream stream;
-            auto completionsSet = parser.completeCommand(editBuffer, stream);
-            std::transform(completionsSet.begin(), completionsSet.end(), std::back_inserter(completions),
-                           [editBuffer](auto it) { return std::string(editBuffer) + it; });
-        });
-        linenoise::SetHistoryMaxLen(4);
-        linenoise::SetMultiLine(true);
-        std::string line;
-        auto quit = linenoise::Readline((parser.currentNode() + "> ").c_str(), line);
-        if (quit) {
+        auto line = lineEditor.input(parser.currentNode() + "> ");
+        if (!line) {
             break;
         }
 
         std::locale C_locale("C");
-        if (std::all_of(line.begin(), line.end(),
+        std::string_view view{line};
+        if (std::all_of(view.begin(), view.end(),
                         [C_locale](const auto c) { return std::isspace(c, C_locale);})) {
             continue;
         }
@@ -66,7 +68,7 @@
             std::cerr << ex.what() << std::endl;
         }
 
-        linenoise::AddHistory(line.c_str());
+        lineEditor.history_add(line);
     }
 
     return 0;
diff --git a/src/parser.cpp b/src/parser.cpp
index 2dbea6b..ba6690d 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -53,7 +53,7 @@
     ];
     x3::phrase_parse(it, line.end(), grammar, space, parsedCommand);
 
-    return filterAndErasePrefix(ctx.m_suggestions, std::string(ctx.m_completionIterator, line.end()));
+    return filterByPrefix(ctx.m_suggestions, std::string(ctx.m_completionIterator, line.end()));
 }
 
 void Parser::changeNode(const dataPath_& name)
diff --git a/src/utils.cpp b/src/utils.cpp
index 358bc05..595dc7a 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -67,17 +67,11 @@
     return fullNodeName(dataPathToSchemaPath(location), pair);
 }
 
-std::set<std::string> filterAndErasePrefix(const std::set<std::string>& set, const std::string_view prefix)
+std::set<std::string> filterByPrefix(const std::set<std::string>& set, const std::string_view prefix)
 {
     std::set<std::string> filtered;
     std::copy_if(set.begin(), set.end(),
             std::inserter(filtered, filtered.end()),
             [prefix] (auto it) { return boost::starts_with(it, prefix); });
-
-    std::set<std::string> withoutPrefix;
-    std::transform(filtered.begin(), filtered.end(),
-            std::inserter(withoutPrefix, withoutPrefix.end()),
-            [prefix] (auto it) { boost::erase_first(it, prefix); return it; });
-    return withoutPrefix;
+    return filtered;
 }
-
diff --git a/src/utils.hpp b/src/utils.hpp
index 38db0af..dcaefb3 100644
--- a/src/utils.hpp
+++ b/src/utils.hpp
@@ -19,7 +19,5 @@
 std::string leafDataTypeToString(yang::LeafDataTypes type);
 std::string fullNodeName(const schemaPath_& location, const ModuleNodePair& pair);
 std::string fullNodeName(const dataPath_& location, const ModuleNodePair& pair);
-/** Returns a subset of the original set with only the strings starting with prefix
- * and with the actual prefix deleted from the string
- */
-std::set<std::string> filterAndErasePrefix(const std::set<std::string>& set, const std::string_view prefix);
+/** Returns a subset of the original set with only the strings starting with prefix */
+std::set<std::string> filterByPrefix(const std::set<std::string>& set, const std::string_view prefix);