From 4ca413444117306c3c56982cbb2782b271b07d5d Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Thu, 7 Nov 2019 20:56:30 +0100
Subject: [PATCH] redesign readline interface classes

---
 aql2/src/aql.cpp                           |  2 ++
 aql2/src/prompt/ReadlineLineInterface.cpp  | 32 ++++++++++++++++++++++
 aql2/src/prompt/ReadlineLineInterface.h    | 22 ++-------------
 aql2/src/prompt/ReadlinePromptCompletion.h |  4 +--
 4 files changed, 39 insertions(+), 21 deletions(-)
 create mode 100644 aql2/src/prompt/ReadlineLineInterface.cpp

diff --git a/aql2/src/aql.cpp b/aql2/src/aql.cpp
index 8006b1c947..ab47823236 100644
--- a/aql2/src/aql.cpp
+++ b/aql2/src/aql.cpp
@@ -43,6 +43,8 @@ std::istream& operator>> ( std::istream & in, std::pair < T, U > & value ) {
 #include <readline/IstreamLineInterface.h>
 #include <readline/StringLineInterface.h>
 
+#include <prompt/ReadlinePromptHistory.h>
+
 namespace TCLAP {
 
 template < class T, class U >
diff --git a/aql2/src/prompt/ReadlineLineInterface.cpp b/aql2/src/prompt/ReadlineLineInterface.cpp
new file mode 100644
index 0000000000..e1013ec93f
--- /dev/null
+++ b/aql2/src/prompt/ReadlineLineInterface.cpp
@@ -0,0 +1,32 @@
+/*
+ * ReadlineLineInterface.cpp
+ *
+ *  Created on: 20. 3. 2017
+ *	  Author: Jan Travnicek
+ */
+
+#include "ReadlineLineInterface.h"
+
+#include <cctype>
+
+#include <readline/readline.h>
+
+#include "ReadlinePromptHistory.h"
+
+bool ReadlineLineInterface::readline ( std::string & line, bool first ) {
+	char * read = ::readline ( first ? "> ": "+ " );
+	if ( read == nullptr ) {
+		std::cout << std::endl;
+		return false;
+	}
+
+	line = read;
+	free ( read );
+
+	return true;
+}
+
+void ReadlineLineInterface::lineCallback ( const std::string & line ) const {
+	if ( m_allowHistory )
+		ReadlinePromptHistory::addHistory ( ( std::string ) ext::trim ( line ) );
+}
diff --git a/aql2/src/prompt/ReadlineLineInterface.h b/aql2/src/prompt/ReadlineLineInterface.h
index bc4066d4b7..74b2a33713 100644
--- a/aql2/src/prompt/ReadlineLineInterface.h
+++ b/aql2/src/prompt/ReadlineLineInterface.h
@@ -8,33 +8,17 @@
 #ifndef _READLINE_LINE_INTERFACE_H_
 #define _READLINE_LINE_INTERFACE_H_
 
-#include <cctype>
 #include <string>
 
-#include <readline/readline.h>
-
-#include "ReadlinePromptHistory.h"
+#include <readline/LineInterface.h>
 
 class ReadlineLineInterface final : public cli::LineInterface {
 	bool m_allowHistory;
 
-	bool readline ( std::string & line, bool first ) override {
-		char * read = ::readline ( first ? "> ": "+ " );
-		if ( read == nullptr ) {
-			std::cout << std::endl;
-			return false;
-		}
-
-		line = read;
-		free ( read );
+	bool readline ( std::string & line, bool first ) override;
 
-		return true;
-	}
+	void lineCallback ( const std::string & line ) const override;
 
-	void lineCallback ( const std::string & line ) const override {
-		if ( m_allowHistory )
-			ReadlinePromptHistory::addHistory ( ( std::string ) ext::trim ( line ) );
-	}
 public:
 	ReadlineLineInterface ( bool allowHistory ) : m_allowHistory ( allowHistory ) {
 	}
diff --git a/aql2/src/prompt/ReadlinePromptCompletion.h b/aql2/src/prompt/ReadlinePromptCompletion.h
index b9f0fb2aa5..391b4e6811 100644
--- a/aql2/src/prompt/ReadlinePromptCompletion.h
+++ b/aql2/src/prompt/ReadlinePromptCompletion.h
@@ -8,8 +8,6 @@
 #ifndef _READLINE_PROMPT_COMPLETION_H
 #define _READLINE_PROMPT_COMPLETION_H
 
-#include <readline/readline.h>
-
 #include <alib/vector>
 #include <alib/set>
 #include <alib/map>
@@ -21,6 +19,8 @@
 #include <environment/Environment.h>
 #include <prompt/Prompt.h>
 
+#include <readline/readline.h>
+
 class ReadlinePromptCompletion {
 	static std::set < std::string > fetchAlgorithmsFullyQualifiedName ( const char *text ) {
 		std::set < std::string > fullyQualifiedNames;
-- 
GitLab