aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Client/ReplxxLineReader.h
blob: 9cc2853f77a8c1862197c4aef2a78c9b09a8b376 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once

#include "LineReader.h"
#include <replxx.hxx>

namespace DB
{

class ReplxxLineReader : public LineReader
{
public:
    ReplxxLineReader(
        Suggest & suggest,
        const String & history_file_path,
        bool multiline,
        Patterns extenders_,
        Patterns delimiters_,
        const char word_break_characters_[],
        replxx::Replxx::highlighter_callback_t highlighter_);
    ~ReplxxLineReader() override;

    void enableBracketedPaste() override;
    void disableBracketedPaste() 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;
    int executeEditor(const std::string & path);
    void openEditor();

    replxx::Replxx rx;
    replxx::Replxx::highlighter_callback_t highlighter;

    const char * word_break_characters;

    // used to call flock() to synchronize multiple clients using same history file
    int history_file_fd = -1;
    bool bracketed_paste_enabled = false;

    std::string editor;
};

}