Merge pull request #9790 from amosbird/cg

Better cli client
This commit is contained in:
alexey-milovidov 2020-03-21 16:05:20 +03:00 committed by GitHub
commit 5645c202e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 6 deletions

View File

@ -52,10 +52,19 @@ LineReader::Suggest::WordsRange LineReader::Suggest::getCompletions(const String
last_word = std::string_view(prefix).substr(last_word_pos + 1, std::string::npos); last_word = std::string_view(prefix).substr(last_word_pos + 1, std::string::npos);
/// last_word can be empty. /// last_word can be empty.
return std::equal_range(words.begin(), words.end(), last_word, [prefix_length](std::string_view s, std::string_view prefix_searched)
/// Only perform case sensitive completion when the prefix string contains any uppercase characters
if (std::none_of(prefix.begin(), prefix.end(), [&](auto c) { return c >= 'A' && c <= 'Z'; }))
return std::equal_range(
words_no_case.begin(), words_no_case.end(), last_word, [prefix_length](std::string_view s, std::string_view prefix_searched)
{ {
return strncasecmp(s.data(), prefix_searched.data(), prefix_length) < 0; return strncasecmp(s.data(), prefix_searched.data(), prefix_length) < 0;
}); });
else
return std::equal_range(words.begin(), words.end(), last_word, [prefix_length](std::string_view s, std::string_view prefix_searched)
{
return strncmp(s.data(), prefix_searched.data(), prefix_length) < 0;
});
} }
LineReader::LineReader(const String & history_file_path_, char extender_, char delimiter_) LineReader::LineReader(const String & history_file_path_, char extender_, char delimiter_)

View File

@ -14,6 +14,7 @@ public:
using WordsRange = std::pair<Words::const_iterator, Words::const_iterator>; using WordsRange = std::pair<Words::const_iterator, Words::const_iterator>;
Words words; Words words;
Words words_no_case;
std::atomic<bool> ready{false}; std::atomic<bool> ready{false};
/// Get iterators for the matched range of words if any. /// Get iterators for the matched range of words if any.

View File

@ -104,6 +104,8 @@ ReadlineLineReader::ReadlineLineReader(const Suggest & suggest_, const String &
if (signal(SIGINT, clear_prompt_or_exit) == SIG_ERR) if (signal(SIGINT, clear_prompt_or_exit) == SIG_ERR)
throw std::runtime_error(std::string("Cannot set signal handler for readline: ") + strerror(errno)); throw std::runtime_error(std::string("Cannot set signal handler for readline: ") + strerror(errno));
rl_variable_bind("completion-ignore-case", "on");
} }
ReadlineLineReader::~ReadlineLineReader() ReadlineLineReader::~ReadlineLineReader()

2
contrib/replxx vendored

@ -1 +1 @@
Subproject commit 1d7e426202139e872a4e64975a34177061cee4f1 Subproject commit 732015fa4e0a1873402f38a5ca5ec7daec82e75a

View File

@ -50,7 +50,9 @@ void Suggest::load(const ConnectionParameters & connection_parameters, size_t su
/// Note that keyword suggestions are available even if we cannot load data from server. /// Note that keyword suggestions are available even if we cannot load data from server.
std::sort(words.begin(), words.end(), [](const std::string & str1, const std::string & str2) std::sort(words.begin(), words.end());
words_no_case = words;
std::sort(words_no_case.begin(), words_no_case.end(), [](const std::string & str1, const std::string & str2)
{ {
return std::lexicographical_compare(begin(str1), end(str1), begin(str2), end(str2), [](const char char1, const char char2) return std::lexicographical_compare(begin(str1), end(str1), begin(str2), end(str2), [](const char char1, const char char2)
{ {