diff --git a/aql2/src/aql.cpp b/aql2/src/aql.cpp index 8006b1c9474221b3a5c2e4bb8ee754b433de12f0..ab47823236ec86ed0763e9089fae838a6ab5609a 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 0000000000000000000000000000000000000000..e1013ec93f04bc55a820bfd134c3c17e22df91c1 --- /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 bc4066d4b7b369e92ee3a27a3157ac5b866d23bb..74b2a3371319da6e830271d96ff8b7391efaf472 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 b9f0fb2aa58009e571c4f7e887135778436fa3f6..391b4e6811a6e90c7cc42b32252215daf85bf16b 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;