diff --git a/alib2cli/src/lexer/Lexer.h b/alib2cli/src/lexer/Lexer.h index 9fad02d97fbce27964bfc8c6f90833ce3c09c24a..cf57b93c42ba4c5fa32eec7a0a6d5229d85e366b 100644 --- a/alib2cli/src/lexer/Lexer.h +++ b/alib2cli/src/lexer/Lexer.h @@ -121,6 +121,10 @@ public: } Token nextToken ( ); + + const std::string & getLine ( ) const { + return m_line; + } }; } /* cli */ diff --git a/aql2/src/prompt/Prompt.cpp b/aql2/src/prompt/Prompt.cpp index 763eb583a2e80cb2f60d26ca7eb719eb1131bfae..31bcdb496fb9234af772eda1b3363e17fa1997bd 100644 --- a/aql2/src/prompt/Prompt.cpp +++ b/aql2/src/prompt/Prompt.cpp @@ -49,12 +49,11 @@ cli::Command::Result Prompt::run ( ) { char * line = readline ( m_prefix.c_str ( ) ); if ( ! line ) - continue; + break; char * s = stripwhite ( line ); if ( * s ) { - add_history ( s ); state = execute_line ( std::string ( s ) ); } @@ -64,9 +63,23 @@ cli::Command::Result Prompt::run ( ) { return state; } +class HistoryRegister { + cli::Lexer & m_lexer; + +public: + HistoryRegister ( cli::Lexer & lexer ) : m_lexer ( lexer ) { + } + + ~HistoryRegister ( ) { + add_history ( m_lexer.getLine ( ).c_str ( ) ); + } +}; + cli::Command::Result Prompt::execute_line ( std::string line ) { try { - cli::Parser parser = cli::Parser ( cli::Lexer ( line ) ); + cli::Lexer lexer ( line ); + HistoryRegister historyRegister ( lexer ); + cli::Parser parser = cli::Parser ( lexer ); return parser.parse ( )->run ( m_environment ); } catch ( const exception::CommonException & exception ) { factory::XmlDataFactory::toStdout ( exception );