mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-21 12:34:56 +00:00
Try to use linereader autocomplete
This commit is contained in:
parent
69590a0267
commit
7515705c05
3 changed files with 48 additions and 4 deletions
|
@ -16,14 +16,53 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "linereader.hpp"
|
#include "linereader.hpp"
|
||||||
|
#include "listdircontent.hpp"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <readline/readline.h>
|
#include <readline/readline.h>
|
||||||
#include <readline/history.h>
|
#include <readline/history.h>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <ciso646>
|
||||||
|
|
||||||
namespace din {
|
namespace din {
|
||||||
LineReader::LineReader() {
|
namespace {
|
||||||
|
char* custom_generator (const char* parText, int parState) {
|
||||||
|
static int list_index, len;
|
||||||
|
|
||||||
|
if (not parState) {
|
||||||
|
list_index = 0;
|
||||||
|
len = std::strlen(parText);
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
//char* custom_generator (const char* parText, int parState) {
|
||||||
|
//}
|
||||||
|
|
||||||
|
//char** custom_completion (const char* parText, int parStart, int parEnd) {
|
||||||
|
// char** matches = nullptr;
|
||||||
|
|
||||||
|
// if (0 == parStart) {
|
||||||
|
// matches = rl_completion_matches(const_cast<char*>(parText), &custom_generator);
|
||||||
|
// }
|
||||||
|
// else {
|
||||||
|
// //See the hack described here:
|
||||||
|
// //http://cc.byexamples.com/2008/06/16/gnu-readline-implement-custom-auto-complete/
|
||||||
|
// rl_bind_key('\t', &rl_abort);
|
||||||
|
// }
|
||||||
|
// return matches;
|
||||||
|
//}
|
||||||
|
} //unnamed namespace
|
||||||
|
|
||||||
|
LineReader::LineReader (const ListDirContent* parLS) :
|
||||||
|
m_ls(parLS)
|
||||||
|
{
|
||||||
|
assert(m_ls);
|
||||||
|
|
||||||
|
//rl_attempted_completion_function = &custom_completion;
|
||||||
|
rl_completion_entry_function = &custom_generator;
|
||||||
|
rl_bind_key('\t', &rl_complete);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string LineReader::read (const std::string& parMessage) {
|
std::string LineReader::read (const std::string& parMessage) {
|
||||||
|
|
|
@ -21,12 +21,17 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace din {
|
namespace din {
|
||||||
|
class ListDirContent;
|
||||||
|
|
||||||
class LineReader {
|
class LineReader {
|
||||||
public:
|
public:
|
||||||
LineReader ( void );
|
explicit LineReader ( const ListDirContent* parLS );
|
||||||
~LineReader ( void ) noexcept = default;
|
~LineReader ( void ) noexcept = default;
|
||||||
|
|
||||||
std::string read ( const std::string& parMessage );
|
std::string read ( const std::string& parMessage );
|
||||||
|
|
||||||
|
private:
|
||||||
|
const ListDirContent* m_ls;
|
||||||
};
|
};
|
||||||
} //namespace din
|
} //namespace din
|
||||||
|
|
||||||
|
|
|
@ -83,13 +83,13 @@ namespace {
|
||||||
|
|
||||||
void do_navigation (din::DBSource& parDB) {
|
void do_navigation (din::DBSource& parDB) {
|
||||||
const std::string prompt;
|
const std::string prompt;
|
||||||
din::LineReader lines;
|
din::ListDirContent ls(&parDB);
|
||||||
|
din::LineReader lines(&ls);
|
||||||
|
|
||||||
bool running = true;
|
bool running = true;
|
||||||
std::string curr_line;
|
std::string curr_line;
|
||||||
din::CommandProcessor proc;
|
din::CommandProcessor proc;
|
||||||
din::GenericPath dir_man;
|
din::GenericPath dir_man;
|
||||||
din::ListDirContent ls(&parDB);
|
|
||||||
proc.add_command("exit", &on_exit, 0);
|
proc.add_command("exit", &on_exit, 0);
|
||||||
proc.add_command("cd", std::function<void(const std::string&)>(std::bind(&din::GenericPath::push_piece, &dir_man, std::placeholders::_1)), 1);
|
proc.add_command("cd", std::function<void(const std::string&)>(std::bind(&din::GenericPath::push_piece, &dir_man, std::placeholders::_1)), 1);
|
||||||
proc.add_command("disconnect", std::function<void()>(std::bind(&din::DBSource::disconnect, &parDB)), 0);
|
proc.add_command("disconnect", std::function<void()>(std::bind(&din::DBSource::disconnect, &parDB)), 0);
|
||||||
|
|
Loading…
Add table
Reference in a new issue