Better code

This commit is contained in:
Amos Bird 2022-01-29 19:44:27 +08:00
parent 62e89a6445
commit bb34435928
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
3 changed files with 11 additions and 7 deletions

View File

@ -125,7 +125,12 @@ void convertHistoryFile(const std::string & path, replxx::Replxx & rx)
}
bool replxx_last_is_delimiter = false;
static bool replxx_last_is_delimiter = false;
void ReplxxLineReader::setLastIsDelimiter(bool flag)
{
replxx_last_is_delimiter = flag;
}
ReplxxLineReader::ReplxxLineReader(
Suggest & suggest,
const String & history_file_path_,

View File

@ -19,6 +19,9 @@ public:
void enableBracketedPaste() override;
/// If highlight is on, we will set a flag to denote whether the last token is a delimiter.
/// This is useful to determine the behavior of <ENTER> key when multiline is enabled.
static void setLastIsDelimiter(bool flag);
private:
InputStatus readOneLine(const String & prompt) override;
void addToHistory(const String & line) override;

View File

@ -6,10 +6,6 @@
#include <Parsers/Lexer.h>
#include <Common/UTF8Helpers.h>
#if USE_REPLXX
extern bool replxx_last_is_delimiter;
#endif
namespace DB
{
@ -156,9 +152,9 @@ void highlight(const String & query, std::vector<replxx::Replxx::Color> & colors
for (Token token = lexer.nextToken(); !token.isEnd(); token = lexer.nextToken())
{
if (token.type == TokenType::Semicolon || token.type == TokenType::VerticalDelimiter)
replxx_last_is_delimiter = true;
ReplxxLineReader::setLastIsDelimiter(true);
else if (token.type != TokenType::Whitespace)
replxx_last_is_delimiter = false;
ReplxxLineReader::setLastIsDelimiter(false);
size_t utf8_len = UTF8::countCodePoints(reinterpret_cast<const UInt8 *>(token.begin), token.size());
for (size_t code_point_index = 0; code_point_index < utf8_len; ++code_point_index)