2016-03-15 08:42:01 +01:00
|
|
|
/* Copyright 2015, 2016, Michele Santullo
|
|
|
|
* This file is part of "dindexer".
|
|
|
|
*
|
|
|
|
* "dindexer" 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.
|
|
|
|
*
|
|
|
|
* "dindexer" 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 "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "linereader.hpp"
|
2016-04-15 15:07:22 +02:00
|
|
|
#include "listdircontent.hpp"
|
2016-04-28 00:05:22 +02:00
|
|
|
#include "dindexer-common/readline_wrapper.hpp"
|
|
|
|
#include "genericpath.hpp"
|
2016-03-15 08:42:01 +01:00
|
|
|
#include <cassert>
|
2016-04-15 15:07:22 +02:00
|
|
|
#include <ciso646>
|
2016-04-28 00:05:22 +02:00
|
|
|
#include <vector>
|
|
|
|
#include <functional>
|
2016-03-15 08:42:01 +01:00
|
|
|
|
|
|
|
namespace din {
|
2016-04-15 15:07:22 +02:00
|
|
|
namespace {
|
2016-04-28 00:05:22 +02:00
|
|
|
std::vector<std::string> list_matches (const ListDirContent& parLS, const std::string& parCurrPath, const std::string& parPrefix) {
|
|
|
|
GenericPath full_prefix;
|
|
|
|
if (not parCurrPath.empty()) {
|
|
|
|
full_prefix.push_piece(parCurrPath);
|
|
|
|
}
|
|
|
|
if (not parPrefix.empty()) {
|
|
|
|
return parLS.ls(full_prefix, parPrefix);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return parLS.ls(full_prefix);
|
2016-04-15 15:07:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} //unnamed namespace
|
|
|
|
|
|
|
|
LineReader::LineReader (const ListDirContent* parLS) :
|
|
|
|
m_ls(parLS)
|
|
|
|
{
|
|
|
|
assert(m_ls);
|
2016-03-15 08:42:01 +01:00
|
|
|
}
|
|
|
|
|
2016-04-28 00:05:22 +02:00
|
|
|
std::string LineReader::read (const std::string& parMessage, const std::string& parCurrPath) {
|
|
|
|
dinlib::ReadlineWrapper rl(std::bind(&list_matches, std::cref(*m_ls), std::cref(parCurrPath), std::placeholders::_1));
|
2016-03-15 08:42:01 +01:00
|
|
|
|
2016-04-28 00:05:22 +02:00
|
|
|
return rl.read(parMessage);
|
2016-03-15 08:42:01 +01:00
|
|
|
}
|
|
|
|
} //namespace din
|