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

make readline registration standalone

parent 29b93a6c
No related branches found
No related tags found
No related merge requests found
#include <extensions/registration.hpp>
/*
* registration.hpp
*
* This file is part of Algorithms library toolkit.
* Copyright (C) 2017 Jan Travnicek (jan.travnicek@fit.cvut.cz)
* Algorithms library toolkit is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Algorithms library toolkit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with Algorithms library toolkit. If not, see <http://www.gnu.org/licenses/>.
*
* Created on: Jan 26, 2019
* Author: Jan Travnice
*/
#ifndef __REGISTRATION_HPP_
#define __REGISTRATION_HPP_
#include <functional>
namespace ext {
class Register {
std::function < void ( ) > m_finish;
public:
template < class InitCallback, class FinalizeCallback >
Register ( InitCallback init, FinalizeCallback finish ) : m_finish ( finish ) {
init ( );
}
template < class InitCallback >
Register ( InitCallback init ) : Register ( init, [](){} ) {
}
~Register ( ) {
m_finish ( );
}
};
} /* namespace ext */
#endif /* __REGISTRATION_HPP_ */
......@@ -11,8 +11,6 @@
 
Prompt::Prompt ( cli::Environment environment ) : m_history_file ( std::string ( std::getenv ( "HOME" ) ) + "/.aql_history" ), m_environment ( std::move ( environment ) ) {
ReadlinePromptHistory::readHistory ( m_history_file.c_str ( ) );
// register readline completion function, pass environment
rl_attempted_completion_function = ReadlinePromptCompletion::readline_completion;
}
 
Prompt::~Prompt ( ) {
......
......@@ -5,8 +5,15 @@
* Author: Tomas Pecka
*/
 
#include <alib/registration>
#include "ReadlinePromptCompletion.h"
 
static ext::Register instance ( [ ] ( ) {
// register readline completion function, pass environment
rl_attempted_completion_function = ReadlinePromptCompletion::readline_completion;
} );
/* ========================================================================= */
 
std::set < std::string > ReadlinePromptCompletion::addPrefix ( const std::set < std::string > & collection, const std::string & prefix ) {
......
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