| 116 | } |
| 117 | |
| 118 | ReplxxLineReader::ReplxxLineReader( |
| 119 | const Suggest & suggest, |
| 120 | const String & history_file_path_, |
| 121 | bool multiline_, |
| 122 | Patterns extenders_, |
| 123 | Patterns delimiters_, |
| 124 | replxx::Replxx::highlighter_callback_t highlighter_) |
| 125 | : LineReader(history_file_path_, multiline_, std::move(extenders_), std::move(delimiters_)), highlighter(std::move(highlighter_)) |
| 126 | { |
| 127 | using namespace std::placeholders; |
| 128 | using Replxx = replxx::Replxx; |
| 129 | |
| 130 | if (!history_file_path.empty()) |
| 131 | { |
| 132 | history_file_fd = open(history_file_path.c_str(), O_RDWR); |
| 133 | if (history_file_fd < 0) |
| 134 | { |
| 135 | rx.print("Open of history file failed: %s\n", errnoToString(errno).c_str()); |
| 136 | } |
| 137 | else |
| 138 | { |
| 139 | convertHistoryFile(history_file_path, rx); |
| 140 | |
| 141 | if (flock(history_file_fd, LOCK_SH)) |
| 142 | { |
| 143 | rx.print("Shared lock of history file failed: %s\n", errnoToString(errno).c_str()); |
| 144 | } |
| 145 | else |
| 146 | { |
| 147 | if (!rx.history_load(history_file_path)) |
| 148 | { |
| 149 | rx.print("Loading history failed: %s\n", errnoToString(errno).c_str()); |
| 150 | } |
| 151 | |
| 152 | if (flock(history_file_fd, LOCK_UN)) |
| 153 | { |
| 154 | rx.print("Unlock of history file failed: %s\n", errnoToString(errno).c_str()); |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | rx.install_window_change_handler(); |
| 161 | |
| 162 | auto callback = [&suggest] (const String & context, size_t context_size) |
| 163 | { |
| 164 | if (auto range = suggest.getCompletions(context, context_size)) |
| 165 | return Replxx::completions_t(range->first, range->second); |
| 166 | return Replxx::completions_t(); |
| 167 | }; |
| 168 | |
| 169 | rx.set_completion_callback(callback); |
| 170 | rx.set_complete_on_empty(false); |
| 171 | rx.set_word_break_characters(word_break_characters); |
| 172 | |
| 173 | if (highlighter) |
| 174 | rx.set_highlighter_callback(highlighter); |
| 175 |
nothing calls this directly
no test coverage detected