Skip to content
Snippets Groups Projects
Commit cce69eae authored by Jan Trávníček's avatar Jan Trávníček
Browse files

go around global variable

parent 8ca151ee
No related branches found
No related tags found
1 merge request!50aql: basic tab-completion using readline
...@@ -76,7 +76,9 @@ int main ( int argc, char * argv[] ) { ...@@ -76,7 +76,9 @@ int main ( int argc, char * argv[] ) {
   
measurements::start ( "Overal", measurements::Type::OVERALL ); measurements::start ( "Overal", measurements::Type::OVERALL );
   
cli::Environment environment; Prompt & p = Prompt::getPrompt ( );
cli::Environment & environment = p.getEnvironment ( );
environment.setBinding ( "stdin", "-" ); environment.setBinding ( "stdin", "-" );
environment.setBinding ( "stdout", "-" ); environment.setBinding ( "stdout", "-" );
   
...@@ -84,8 +86,6 @@ int main ( int argc, char * argv[] ) { ...@@ -84,8 +86,6 @@ int main ( int argc, char * argv[] ) {
environment.setBinding ( param.first, param.second ); environment.setBinding ( param.first, param.second );
} }
   
Prompt p ( std::move ( environment ) );
cli::Command::Result result = cli::Command::Result::OK; cli::Command::Result result = cli::Command::Result::OK;
if ( queries.getValue ( ).empty ( ) ) { if ( queries.getValue ( ).empty ( ) ) {
result = p.run ( ); result = p.run ( );
......
...@@ -67,10 +67,8 @@ Prompt::Prompt ( cli::Environment environment ) : m_history_file ( std::string ( ...@@ -67,10 +67,8 @@ Prompt::Prompt ( cli::Environment environment ) : m_history_file ( std::string (
++ i; ++ i;
} }
   
// register readline completion function, pass environment // register readline completion function, pass environment
rl_attempted_completion_function = readline_completion; rl_attempted_completion_function = readline_completion;
rl_aql_environment = & m_environment;
} }
   
Prompt::~Prompt ( ) { Prompt::~Prompt ( ) {
......
...@@ -29,10 +29,15 @@ class Prompt { ...@@ -29,10 +29,15 @@ class Prompt {
   
cli::Environment m_environment; cli::Environment m_environment;
   
public:
Prompt ( cli::Environment environment ); Prompt ( cli::Environment environment );
~Prompt ( ); ~Prompt ( );
   
public:
static Prompt & getPrompt ( ) {
static Prompt instance { cli::Environment ( ) };
return instance;
}
cli::Command::Result run ( ); cli::Command::Result run ( );
   
template < class T > template < class T >
...@@ -50,7 +55,7 @@ public: ...@@ -50,7 +55,7 @@ public:
} }
} }
   
const cli::Environment & getEnvironment ( ) const { cli::Environment & getEnvironment ( ) {
return m_environment; return m_environment;
} }
}; };
......
...@@ -12,9 +12,7 @@ ...@@ -12,9 +12,7 @@
#include <registry/Registry.h> #include <registry/Registry.h>
   
#include "ReadlinePromptCompletion.h" #include "ReadlinePromptCompletion.h"
#include "Prompt.h"
const cli::Environment* rl_aql_environment = nullptr;
   
/* ========================================================================= */ /* ========================================================================= */
   
...@@ -65,15 +63,11 @@ std::set < std::string > fetchCommandsIntrospect ( const char *text ) { ...@@ -65,15 +63,11 @@ std::set < std::string > fetchCommandsIntrospect ( const char *text ) {
} }
   
std::set < std::string > fetchBindings ( const char *text ) { std::set < std::string > fetchBindings ( const char *text ) {
if ( rl_aql_environment ) return filter_completions ( addPrefix ( Prompt::getPrompt ( ).getEnvironment ( ).getBindingNames ( ), "#" ), text );
return filter_completions ( addPrefix ( rl_aql_environment -> getBindingNames ( ), "#" ), text );
return std::set < std::string > ( );
} }
   
std::set < std::string > fetchVariables ( const char *text ) { std::set < std::string > fetchVariables ( const char *text ) {
if ( rl_aql_environment ) return filter_completions ( addPrefix ( Prompt::getPrompt ( ).getEnvironment ( ).getVariableNames ( ), "$" ), text );
return filter_completions ( addPrefix ( rl_aql_environment -> getVariableNames ( ), "$" ), text );
return std::set < std::string > ( );
} }
   
std::set < std::string > fetchFilepath ( const char *text ) { std::set < std::string > fetchFilepath ( const char *text ) {
......
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
#include <readline/readline.h> #include <readline/readline.h>
#include <environment/Environment.h> #include <environment/Environment.h>
   
extern const cli::Environment* rl_aql_environment;
enum class CompletionContext { enum class CompletionContext {
COMMAND, COMMAND,
COMMAND_INTROSPECT, COMMAND_INTROSPECT,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment