mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-20 12:14:55 +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 "listdircontent.hpp"
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
#include <cassert>
|
||||
#include <ciso646>
|
||||
|
||||
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) {
|
||||
|
|
|
@ -21,12 +21,17 @@
|
|||
#include <string>
|
||||
|
||||
namespace din {
|
||||
class ListDirContent;
|
||||
|
||||
class LineReader {
|
||||
public:
|
||||
LineReader ( void );
|
||||
explicit LineReader ( const ListDirContent* parLS );
|
||||
~LineReader ( void ) noexcept = default;
|
||||
|
||||
std::string read ( const std::string& parMessage );
|
||||
|
||||
private:
|
||||
const ListDirContent* m_ls;
|
||||
};
|
||||
} //namespace din
|
||||
|
||||
|
|
|
@ -83,13 +83,13 @@ namespace {
|
|||
|
||||
void do_navigation (din::DBSource& parDB) {
|
||||
const std::string prompt;
|
||||
din::LineReader lines;
|
||||
din::ListDirContent ls(&parDB);
|
||||
din::LineReader lines(&ls);
|
||||
|
||||
bool running = true;
|
||||
std::string curr_line;
|
||||
din::CommandProcessor proc;
|
||||
din::GenericPath dir_man;
|
||||
din::ListDirContent ls(&parDB);
|
||||
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("disconnect", std::function<void()>(std::bind(&din::DBSource::disconnect, &parDB)), 0);
|
||||
|
|
Loading…
Add table
Reference in a new issue