LLDB mainline
Editline.cpp
Go to the documentation of this file.
1//===-- Editline.cpp ------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include <climits>
10#include <iomanip>
11#include <optional>
12
14#include "lldb/Host/Editline.h"
16#include "lldb/Host/Host.h"
21#include "lldb/Utility/Status.h"
25#include "llvm/Support/ConvertUTF.h"
26
27#include "llvm/Support/FileSystem.h"
28#include "llvm/Support/Locale.h"
29#include "llvm/Support/Threading.h"
30
31using namespace lldb_private;
32using namespace lldb_private::line_editor;
33
34// Editline uses careful cursor management to achieve the illusion of editing a
35// multi-line block of text with a single line editor. Preserving this
36// illusion requires fairly careful management of cursor state. Read and
37// understand the relationship between DisplayInput(), MoveCursor(),
38// SetCurrentLine(), and SaveEditedLine() before making changes.
39
40/// https://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf
41#define ESCAPE "\x1b"
42#define ANSI_CLEAR_BELOW ESCAPE "[J"
43#define ANSI_CLEAR_RIGHT ESCAPE "[K"
44#define ANSI_SET_COLUMN_N ESCAPE "[%dG"
45#define ANSI_UP_N_ROWS ESCAPE "[%dA"
46#define ANSI_DOWN_N_ROWS ESCAPE "[%dB"
47
48#if LLDB_EDITLINE_USE_WCHAR
49
50#define EditLineConstString(str) L##str
51#define EditLineStringFormatSpec "%ls"
52
53#else
54
55#define EditLineConstString(str) str
56#define EditLineStringFormatSpec "%s"
57
58// use #defines so wide version functions and structs will resolve to old
59// versions for case of libedit not built with wide char support
60#define history_w history
61#define history_winit history_init
62#define history_wend history_end
63#define HistoryW History
64#define HistEventW HistEvent
65#define LineInfoW LineInfo
66
67#define el_wgets el_gets
68#define el_wgetc el_getc
69#define el_wpush el_push
70#define el_wparse el_parse
71#define el_wset el_set
72#define el_wget el_get
73#define el_wline el_line
74#define el_winsertstr el_insertstr
75#define el_wdeletestr el_deletestr
76
77#endif // #if LLDB_EDITLINE_USE_WCHAR
78
79bool IsOnlySpaces(const EditLineStringType &content) {
80 for (wchar_t ch : content) {
81 if (ch != EditLineCharType(' '))
82 return false;
83 }
84 return true;
85}
86
87static size_t ColumnWidth(llvm::StringRef str) {
88 return llvm::sys::locale::columnWidth(str);
89}
90
92 // The naming used by editline for the history operations is counter
93 // intuitive to how it's used in LLDB's editline implementation.
94 //
95 // - The H_LAST returns the oldest entry in the history.
96 //
97 // - The H_PREV operation returns the previous element in the history, which
98 // is newer than the current one.
99 //
100 // - The H_CURR returns the current entry in the history.
101 //
102 // - The H_NEXT operation returns the next element in the history, which is
103 // older than the current one.
104 //
105 // - The H_FIRST returns the most recent entry in the history.
106 //
107 // The naming of the enum entries match the semantic meaning.
108 switch(op) {
109 case HistoryOperation::Oldest:
110 return H_LAST;
111 case HistoryOperation::Older:
112 return H_NEXT;
113 case HistoryOperation::Current:
114 return H_CURR;
115 case HistoryOperation::Newer:
116 return H_PREV;
117 case HistoryOperation::Newest:
118 return H_FIRST;
119 }
120 llvm_unreachable("Fully covered switch!");
121}
122
123
124EditLineStringType CombineLines(const std::vector<EditLineStringType> &lines) {
125 EditLineStringStreamType combined_stream;
126 for (EditLineStringType line : lines) {
127 combined_stream << line.c_str() << "\n";
128 }
129 return combined_stream.str();
130}
131
132std::vector<EditLineStringType> SplitLines(const EditLineStringType &input) {
133 std::vector<EditLineStringType> result;
134 size_t start = 0;
135 while (start < input.length()) {
136 size_t end = input.find('\n', start);
137 if (end == std::string::npos) {
138 result.push_back(input.substr(start));
139 break;
140 }
141 result.push_back(input.substr(start, end - start));
142 start = end + 1;
143 }
144 // Treat an empty history session as a single command of zero-length instead
145 // of returning an empty vector.
146 if (result.empty()) {
147 result.emplace_back();
148 }
149 return result;
150}
151
153 int indent_correction) {
154 if (indent_correction == 0)
155 return line;
156 if (indent_correction < 0)
157 return line.substr(-indent_correction);
158 return EditLineStringType(indent_correction, EditLineCharType(' ')) + line;
159}
160
162 int space_count = 0;
163 for (EditLineCharType ch : line) {
164 if (ch != EditLineCharType(' '))
165 break;
166 ++space_count;
167 }
168 return space_count;
169}
170
171bool IsInputPending(FILE *file) {
172 // FIXME: This will be broken on Windows if we ever re-enable Editline. You
173 // can't use select
174 // on something that isn't a socket. This will have to be re-written to not
175 // use a FILE*, but instead use some kind of yet-to-be-created abstraction
176 // that select-like functionality on non-socket objects.
177 const int fd = fileno(file);
178 SelectHelper select_helper;
179 select_helper.SetTimeout(std::chrono::microseconds(0));
180 select_helper.FDSetRead(fd);
181 return select_helper.Select().Success();
182}
183
184namespace lldb_private {
185namespace line_editor {
186typedef std::weak_ptr<EditlineHistory> EditlineHistoryWP;
187
188// EditlineHistory objects are sometimes shared between multiple Editline
189// instances with the same program name.
190
192private:
193 // Use static GetHistory() function to get a EditlineHistorySP to one of
194 // these objects
195 EditlineHistory(const std::string &prefix, uint32_t size, bool unique_entries)
196 : m_prefix(prefix) {
198 history_w(m_history, &m_event, H_SETSIZE, size);
199 if (unique_entries)
200 history_w(m_history, &m_event, H_SETUNIQUE, 1);
201 }
202
203 const char *GetHistoryFilePath() {
204 // Compute the history path lazily.
205 if (m_path.empty() && m_history && !m_prefix.empty()) {
206 llvm::SmallString<128> lldb_history_file;
207 FileSystem::Instance().GetHomeDirectory(lldb_history_file);
208 llvm::sys::path::append(lldb_history_file, ".lldb");
209
210 // LLDB stores its history in ~/.lldb/. If for some reason this directory
211 // isn't writable or cannot be created, history won't be available.
212 if (!llvm::sys::fs::create_directory(lldb_history_file)) {
213#if LLDB_EDITLINE_USE_WCHAR
214 std::string filename = m_prefix + "-widehistory";
215#else
216 std::string filename = m_prefix + "-history";
217#endif
218 llvm::sys::path::append(lldb_history_file, filename);
219 m_path = std::string(lldb_history_file.str());
220 }
221 }
222
223 if (m_path.empty())
224 return nullptr;
225
226 return m_path.c_str();
227 }
228
229public:
231 Save();
232
233 if (m_history) {
235 m_history = nullptr;
236 }
237 }
238
239 static EditlineHistorySP GetHistory(const std::string &prefix) {
240 typedef std::map<std::string, EditlineHistoryWP> WeakHistoryMap;
241 static std::recursive_mutex g_mutex;
242 static WeakHistoryMap g_weak_map;
243 std::lock_guard<std::recursive_mutex> guard(g_mutex);
244 WeakHistoryMap::const_iterator pos = g_weak_map.find(prefix);
245 EditlineHistorySP history_sp;
246 if (pos != g_weak_map.end()) {
247 history_sp = pos->second.lock();
248 if (history_sp)
249 return history_sp;
250 g_weak_map.erase(pos);
251 }
252 history_sp.reset(new EditlineHistory(prefix, 800, true));
253 g_weak_map[prefix] = history_sp;
254 return history_sp;
255 }
256
257 bool IsValid() const { return m_history != nullptr; }
258
260
261 void Enter(const EditLineCharType *line_cstr) {
262 if (m_history)
263 history_w(m_history, &m_event, H_ENTER, line_cstr);
264 }
265
266 bool Load() {
267 if (m_history) {
268 const char *path = GetHistoryFilePath();
269 if (path) {
270 history_w(m_history, &m_event, H_LOAD, path);
271 return true;
272 }
273 }
274 return false;
275 }
276
277 bool Save() {
278 if (m_history) {
279 const char *path = GetHistoryFilePath();
280 if (path) {
281 history_w(m_history, &m_event, H_SAVE, path);
282 return true;
283 }
284 }
285 return false;
286 }
287
288protected:
289 /// The history object.
290 HistoryW *m_history = nullptr;
291 /// The history event needed to contain all history events.
293 /// The prefix name (usually the editline program name) to use when
294 /// loading/saving history.
295 std::string m_prefix;
296 /// Path to the history file.
297 std::string m_path;
298};
299}
300}
301
302// Editline private methods
303
304void Editline::SetBaseLineNumber(int line_number) {
305 m_base_line_number = line_number;
307 std::max<int>(3, std::to_string(line_number).length() + 1);
308}
309
310std::string Editline::PromptForIndex(int line_index) {
311 bool use_line_numbers = m_multiline_enabled && m_base_line_number > 0;
312 std::string prompt = m_set_prompt;
313 if (use_line_numbers && prompt.length() == 0)
314 prompt = ": ";
315 std::string continuation_prompt = prompt;
316 if (m_set_continuation_prompt.length() > 0) {
317 continuation_prompt = m_set_continuation_prompt;
318 // Ensure that both prompts are the same length through space padding
319 const size_t prompt_width = ColumnWidth(prompt);
320 const size_t cont_prompt_width = ColumnWidth(continuation_prompt);
321 const size_t padded_prompt_width =
322 std::max(prompt_width, cont_prompt_width);
323 if (prompt_width < padded_prompt_width)
324 prompt += std::string(padded_prompt_width - prompt_width, ' ');
325 else if (cont_prompt_width < padded_prompt_width)
326 continuation_prompt +=
327 std::string(padded_prompt_width - cont_prompt_width, ' ');
328 }
329
330 if (use_line_numbers) {
331 StreamString prompt_stream;
332 prompt_stream.Printf(
333 "%*d%s", m_line_number_digits, m_base_line_number + line_index,
334 (line_index == 0) ? prompt.c_str() : continuation_prompt.c_str());
335 return std::string(std::move(prompt_stream.GetString()));
336 }
337 return (line_index == 0) ? prompt : continuation_prompt;
338}
339
340void Editline::SetCurrentLine(int line_index) {
341 m_current_line_index = line_index;
342 m_current_prompt = PromptForIndex(line_index);
343}
344
346
348 const char *editor;
349 el_get(m_editline, EL_EDITOR, &editor);
350 return editor[0] == 'e';
351}
352
354 const LineInfoW *info = el_wline(m_editline);
355 for (const EditLineCharType *character = info->buffer;
356 character < info->lastchar; character++) {
357 if (*character != ' ')
358 return false;
359 }
360 return true;
361}
362
364 int line = 0;
365 if (location == CursorLocation::EditingPrompt ||
366 location == CursorLocation::BlockEnd ||
367 location == CursorLocation::EditingCursor) {
368 for (unsigned index = 0; index < m_current_line_index; index++) {
369 line += CountRowsForLine(m_input_lines[index]);
370 }
371 if (location == CursorLocation::EditingCursor) {
372 line += cursor_row;
373 } else if (location == CursorLocation::BlockEnd) {
374 for (unsigned index = m_current_line_index; index < m_input_lines.size();
375 index++) {
376 line += CountRowsForLine(m_input_lines[index]);
377 }
378 --line;
379 }
380 }
381 return line;
382}
383
385 const LineInfoW *info = el_wline(m_editline);
386 int editline_cursor_position =
387 (int)((info->cursor - info->buffer) + GetPromptWidth());
388 int editline_cursor_row = editline_cursor_position / m_terminal_width;
389
390 // Determine relative starting and ending lines
391 int fromLine = GetLineIndexForLocation(from, editline_cursor_row);
392 int toLine = GetLineIndexForLocation(to, editline_cursor_row);
393 if (toLine != fromLine) {
394 fprintf(m_output_file,
395 (toLine > fromLine) ? ANSI_DOWN_N_ROWS : ANSI_UP_N_ROWS,
396 std::abs(toLine - fromLine));
397 }
398
399 // Determine target column
400 int toColumn = 1;
401 if (to == CursorLocation::EditingCursor) {
402 toColumn =
403 editline_cursor_position - (editline_cursor_row * m_terminal_width) + 1;
404 } else if (to == CursorLocation::BlockEnd && !m_input_lines.empty()) {
405 toColumn =
406 ((m_input_lines[m_input_lines.size() - 1].length() + GetPromptWidth()) %
407 80) +
408 1;
409 }
410 fprintf(m_output_file, ANSI_SET_COLUMN_N, toColumn);
411}
412
413void Editline::DisplayInput(int firstIndex) {
415 int line_count = (int)m_input_lines.size();
416 for (int index = firstIndex; index < line_count; index++) {
417 fprintf(m_output_file,
418 "%s"
419 "%s"
421 m_prompt_ansi_prefix.c_str(), PromptForIndex(index).c_str(),
422 m_prompt_ansi_suffix.c_str(), m_input_lines[index].c_str());
423 if (index < line_count - 1)
424 fprintf(m_output_file, "\n");
425 }
426}
427
429 std::string prompt =
430 PromptForIndex(0); // Prompt width is constant during an edit session
431 int line_length = (int)(content.length() + ColumnWidth(prompt));
432 return (line_length / m_terminal_width) + 1;
433}
434
436 const LineInfoW *info = el_wline(m_editline);
438 EditLineStringType(info->buffer, info->lastchar - info->buffer);
439}
440
442 StringList lines;
443 for (EditLineStringType line : m_input_lines) {
444 if (line_count == 0)
445 break;
446#if LLDB_EDITLINE_USE_WCHAR
447 std::string buffer;
448 llvm::convertWideToUTF8(line, buffer);
449 lines.AppendString(buffer);
450#else
451 lines.AppendString(line);
452#endif
453 --line_count;
454 }
455 return lines;
456}
457
459 assert(op == HistoryOperation::Older || op == HistoryOperation::Newer);
460 if (!m_history_sp || !m_history_sp->IsValid())
461 return CC_ERROR;
462
463 HistoryW *pHistory = m_history_sp->GetHistoryPtr();
464 HistEventW history_event;
465 std::vector<EditLineStringType> new_input_lines;
466
467 // Treat moving from the "live" entry differently
468 if (!m_in_history) {
469 switch (op) {
470 case HistoryOperation::Newer:
471 return CC_ERROR; // Can't go newer than the "live" entry
472 case HistoryOperation::Older: {
473 if (history_w(pHistory, &history_event,
474 GetOperation(HistoryOperation::Newest)) == -1)
475 return CC_ERROR;
476 // Save any edits to the "live" entry in case we return by moving forward
477 // in history (it would be more bash-like to save over any current entry,
478 // but libedit doesn't offer the ability to add entries anywhere except
479 // the end.)
482 m_in_history = true;
483 } break;
484 default:
485 llvm_unreachable("unsupported history direction");
486 }
487 } else {
488 if (history_w(pHistory, &history_event, GetOperation(op)) == -1) {
489 switch (op) {
490 case HistoryOperation::Older:
491 // Can't move earlier than the earliest entry.
492 return CC_ERROR;
493 case HistoryOperation::Newer:
494 // Moving to newer-than-the-newest entry yields the "live" entry.
495 new_input_lines = m_live_history_lines;
496 m_in_history = false;
497 break;
498 default:
499 llvm_unreachable("unsupported history direction");
500 }
501 }
502 }
503
504 // If we're pulling the lines from history, split them apart
505 if (m_in_history)
506 new_input_lines = SplitLines(history_event.str);
507
508 // Erase the current edit session and replace it with a new one
509 MoveCursor(CursorLocation::EditingCursor, CursorLocation::BlockStart);
510 m_input_lines = new_input_lines;
511 DisplayInput();
512
513 // Prepare to edit the last line when moving to previous entry, or the first
514 // line when moving to next entry
515 switch (op) {
516 case HistoryOperation::Older:
517 m_current_line_index = (int)m_input_lines.size() - 1;
518 break;
519 case HistoryOperation::Newer:
521 break;
522 default:
523 llvm_unreachable("unsupported history direction");
524 }
526 MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingPrompt);
527 return CC_NEWLINE;
528}
529
531 const LineInfoW *info = el_wline(m_editline);
532
533 // Paint a ANSI formatted version of the desired prompt over the version
534 // libedit draws. (will only be requested if colors are supported)
536 MoveCursor(CursorLocation::EditingCursor, CursorLocation::EditingPrompt);
537 fprintf(m_output_file,
538 "%s"
539 "%s"
540 "%s",
541 m_prompt_ansi_prefix.c_str(), Prompt(),
542 m_prompt_ansi_suffix.c_str());
543 MoveCursor(CursorLocation::EditingPrompt, CursorLocation::EditingCursor);
545 }
546
548 // Detect when the number of rows used for this input line changes due to
549 // an edit
550 int lineLength = (int)((info->lastchar - info->buffer) + GetPromptWidth());
551 int new_line_rows = (lineLength / m_terminal_width) + 1;
552 if (m_current_line_rows != -1 && new_line_rows != m_current_line_rows) {
553 // Respond by repainting the current state from this line on
554 MoveCursor(CursorLocation::EditingCursor, CursorLocation::EditingPrompt);
557 MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingCursor);
558 }
559 m_current_line_rows = new_line_rows;
560 }
561
562 // Read an actual character
563 while (true) {
565 char ch = 0;
566
569
570 // This mutex is locked by our caller (GetLine). Unlock it while we read a
571 // character (blocking operation), so we do not hold the mutex
572 // indefinitely. This gives a chance for someone to interrupt us. After
573 // Read returns, immediately lock the mutex again and check if we were
574 // interrupted.
575 m_output_mutex.unlock();
576 int read_count =
577 m_input_connection.Read(&ch, 1, std::nullopt, status, nullptr);
578 m_output_mutex.lock();
579 if (m_editor_status == EditorStatus::Interrupted) {
580 while (read_count > 0 && status == lldb::eConnectionStatusSuccess)
581 read_count =
582 m_input_connection.Read(&ch, 1, std::nullopt, status, nullptr);
584 return 0;
585 }
586
587 if (read_count) {
588 if (CompleteCharacter(ch, *c))
589 return 1;
590 } else {
591 switch (status) {
592 case lldb::eConnectionStatusSuccess: // Success
593 break;
594
596 llvm_unreachable("Interrupts should have been handled above.");
597
598 case lldb::eConnectionStatusError: // Check GetError() for details
599 case lldb::eConnectionStatusTimedOut: // Request timed out
600 case lldb::eConnectionStatusEndOfFile: // End-of-file encountered
601 case lldb::eConnectionStatusNoConnection: // No connection
602 case lldb::eConnectionStatusLostConnection: // Lost connection while
603 // connected to a valid
604 // connection
605 m_editor_status = EditorStatus::EndOfInput;
606 return 0;
607 }
608 }
609 }
610}
611
612const char *Editline::Prompt() {
613 if (!m_prompt_ansi_prefix.empty() || !m_prompt_ansi_suffix.empty())
615 return m_current_prompt.c_str();
616}
617
618unsigned char Editline::BreakLineCommand(int ch) {
619 // Preserve any content beyond the cursor, truncate and save the current line
620 const LineInfoW *info = el_wline(m_editline);
621 auto current_line =
622 EditLineStringType(info->buffer, info->cursor - info->buffer);
623 auto new_line_fragment =
624 EditLineStringType(info->cursor, info->lastchar - info->cursor);
625 m_input_lines[m_current_line_index] = current_line;
626
627 // Ignore whitespace-only extra fragments when breaking a line
628 if (::IsOnlySpaces(new_line_fragment))
629 new_line_fragment = EditLineConstString("");
630
631 // Establish the new cursor position at the start of a line when inserting a
632 // line break
634
635 // Don't perform automatic formatting when pasting
637 // Apply smart indentation
640#if LLDB_EDITLINE_USE_WCHAR
641 std::string buffer;
642 llvm::convertWideToUTF8(new_line_fragment, buffer);
643 lines.AppendString(buffer);
644#else
645 lines.AppendString(new_line_fragment);
646#endif
647
648 int indent_correction = m_fix_indentation_callback(this, lines, 0);
649 new_line_fragment = FixIndentation(new_line_fragment, indent_correction);
650 m_revert_cursor_index = GetIndentation(new_line_fragment);
651 }
652 }
653
654 // Insert the new line and repaint everything from the split line on down
656 new_line_fragment);
657 MoveCursor(CursorLocation::EditingCursor, CursorLocation::EditingPrompt);
659
660 // Reposition the cursor to the right line and prepare to edit the new line
662 MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingPrompt);
663 return CC_NEWLINE;
664}
665
666unsigned char Editline::EndOrAddLineCommand(int ch) {
667 // Don't perform end of input detection when pasting, always treat this as a
668 // line break
670 return BreakLineCommand(ch);
671 }
672
673 // Save any edits to this line
675
676 // If this is the end of the last line, consider whether to add a line
677 // instead
678 const LineInfoW *info = el_wline(m_editline);
679 if (m_current_line_index == m_input_lines.size() - 1 &&
680 info->cursor == info->lastchar) {
682 auto lines = GetInputAsStringList();
683 if (!m_is_input_complete_callback(this, lines)) {
684 return BreakLineCommand(ch);
685 }
686
687 // The completion test is allowed to change the input lines when complete
688 m_input_lines.clear();
689 for (unsigned index = 0; index < lines.GetSize(); index++) {
690#if LLDB_EDITLINE_USE_WCHAR
691 std::wstring wbuffer;
692 llvm::ConvertUTF8toWide(lines[index], wbuffer);
693 m_input_lines.insert(m_input_lines.end(), wbuffer);
694#else
695 m_input_lines.insert(m_input_lines.end(), lines[index]);
696#endif
697 }
698 }
699 }
700 MoveCursor(CursorLocation::EditingCursor, CursorLocation::BlockEnd);
701 fprintf(m_output_file, "\n");
702 m_editor_status = EditorStatus::Complete;
703 return CC_NEWLINE;
704}
705
706unsigned char Editline::DeleteNextCharCommand(int ch) {
707 LineInfoW *info = const_cast<LineInfoW *>(el_wline(m_editline));
708
709 // Just delete the next character normally if possible
710 if (info->cursor < info->lastchar) {
711 info->cursor++;
712 el_deletestr(m_editline, 1);
713 return CC_REFRESH;
714 }
715
716 // Fail when at the end of the last line, except when ^D is pressed on the
717 // line is empty, in which case it is treated as EOF
718 if (m_current_line_index == m_input_lines.size() - 1) {
719 if (ch == 4 && info->buffer == info->lastchar) {
720 fprintf(m_output_file, "^D\n");
721 m_editor_status = EditorStatus::EndOfInput;
722 return CC_EOF;
723 }
724 return CC_ERROR;
725 }
726
727 // Prepare to combine this line with the one below
728 MoveCursor(CursorLocation::EditingCursor, CursorLocation::EditingPrompt);
729
730 // Insert the next line of text at the cursor and restore the cursor position
731 const EditLineCharType *cursor = info->cursor;
733 info->cursor = cursor;
735
736 // Delete the extra line
738
739 // Clear and repaint from this line on down
741 MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingCursor);
742 return CC_REFRESH;
743}
744
746 LineInfoW *info = const_cast<LineInfoW *>(el_wline(m_editline));
747
748 // Just delete the previous character normally when not at the start of a
749 // line
750 if (info->cursor > info->buffer) {
751 el_deletestr(m_editline, 1);
752 return CC_REFRESH;
753 }
754
755 // No prior line and no prior character? Let the user know
756 if (m_current_line_index == 0)
757 return CC_ERROR;
758
759 // No prior character, but prior line? Combine with the line above
762 auto priorLine = m_input_lines[m_current_line_index];
766
767 // Repaint from the new line down
769 CountRowsForLine(priorLine), 1);
771
772 // Put the cursor back where libedit expects it to be before returning to
773 // editing by telling libedit about the newly inserted text
774 MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingPrompt);
775 el_winsertstr(m_editline, priorLine.c_str());
776 return CC_REDISPLAY;
777}
778
779unsigned char Editline::PreviousLineCommand(int ch) {
781
782 if (m_current_line_index == 0) {
783 return RecallHistory(HistoryOperation::Older);
784 }
785
786 // Start from a known location
787 MoveCursor(CursorLocation::EditingCursor, CursorLocation::EditingPrompt);
788
789 // Treat moving up from a blank last line as a deletion of that line
790 if (m_current_line_index == m_input_lines.size() - 1 && IsOnlySpaces()) {
793 }
794
798 return CC_NEWLINE;
799}
800
801unsigned char Editline::NextLineCommand(int ch) {
803
804 // Handle attempts to move down from the last line
805 if (m_current_line_index == m_input_lines.size() - 1) {
806 // Don't add an extra line if the existing last line is blank, move through
807 // history instead
808 if (IsOnlySpaces()) {
809 return RecallHistory(HistoryOperation::Newer);
810 }
811
812 // Determine indentation for the new line
813 int indentation = 0;
816 lines.AppendString("");
817 indentation = m_fix_indentation_callback(this, lines, 0);
818 }
819 m_input_lines.insert(
820 m_input_lines.end(),
821 EditLineStringType(indentation, EditLineCharType(' ')));
822 }
823
824 // Move down past the current line using newlines to force scrolling if
825 // needed
827 const LineInfoW *info = el_wline(m_editline);
828 int cursor_position = (int)((info->cursor - info->buffer) + GetPromptWidth());
829 int cursor_row = cursor_position / m_terminal_width;
830 for (int line_count = 0; line_count < m_current_line_rows - cursor_row;
831 line_count++) {
832 fprintf(m_output_file, "\n");
833 }
834 return CC_NEWLINE;
835}
836
837unsigned char Editline::PreviousHistoryCommand(int ch) {
839
840 return RecallHistory(HistoryOperation::Older);
841}
842
843unsigned char Editline::NextHistoryCommand(int ch) {
845
846 return RecallHistory(HistoryOperation::Newer);
847}
848
849unsigned char Editline::FixIndentationCommand(int ch) {
851 return CC_NORM;
852
853 // Insert the character typed before proceeding
854 EditLineCharType inserted[] = {(EditLineCharType)ch, 0};
855 el_winsertstr(m_editline, inserted);
856 LineInfoW *info = const_cast<LineInfoW *>(el_wline(m_editline));
857 int cursor_position = info->cursor - info->buffer;
858
859 // Save the edits and determine the correct indentation level
862 int indent_correction =
863 m_fix_indentation_callback(this, lines, cursor_position);
864
865 // If it is already correct no special work is needed
866 if (indent_correction == 0)
867 return CC_REFRESH;
868
869 // Change the indentation level of the line
870 std::string currentLine = lines.GetStringAtIndex(m_current_line_index);
871 if (indent_correction > 0) {
872 currentLine = currentLine.insert(0, indent_correction, ' ');
873 } else {
874 currentLine = currentLine.erase(0, -indent_correction);
875 }
876#if LLDB_EDITLINE_USE_WCHAR
877 std::wstring wbuffer;
878 llvm::ConvertUTF8toWide(currentLine, wbuffer);
880#else
881 m_input_lines[m_current_line_index] = currentLine;
882#endif
883
884 // Update the display to reflect the change
885 MoveCursor(CursorLocation::EditingCursor, CursorLocation::EditingPrompt);
887
888 // Reposition the cursor back on the original line and prepare to restart
889 // editing with a new cursor position
891 MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingPrompt);
892 m_revert_cursor_index = cursor_position + indent_correction;
893 return CC_NEWLINE;
894}
895
896unsigned char Editline::RevertLineCommand(int ch) {
898 if (m_revert_cursor_index >= 0) {
899 LineInfoW *info = const_cast<LineInfoW *>(el_wline(m_editline));
900 info->cursor = info->buffer + m_revert_cursor_index;
901 if (info->cursor > info->lastchar) {
902 info->cursor = info->lastchar;
903 }
905 }
906 return CC_REFRESH;
907}
908
909unsigned char Editline::BufferStartCommand(int ch) {
911 MoveCursor(CursorLocation::EditingCursor, CursorLocation::BlockStart);
914 return CC_NEWLINE;
915}
916
917unsigned char Editline::BufferEndCommand(int ch) {
919 MoveCursor(CursorLocation::EditingCursor, CursorLocation::BlockEnd);
920 SetCurrentLine((int)m_input_lines.size() - 1);
921 MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingPrompt);
922 return CC_NEWLINE;
923}
924
925/// Prints completions and their descriptions to the given file. Only the
926/// completions in the interval [start, end) are printed.
927static size_t
928PrintCompletion(FILE *output_file,
929 llvm::ArrayRef<CompletionResult::Completion> results,
930 size_t max_completion_length, size_t max_length,
931 std::optional<size_t> max_height = std::nullopt) {
932 constexpr size_t ellipsis_length = 3;
933 constexpr size_t padding_length = 8;
934 constexpr size_t separator_length = 4;
935
936 const size_t description_col =
937 std::min(max_completion_length + padding_length, max_length);
938
939 size_t lines_printed = 0;
940 size_t results_printed = 0;
941 for (const CompletionResult::Completion &c : results) {
942 if (max_height && lines_printed >= *max_height)
943 break;
944
945 results_printed++;
946
947 if (c.GetCompletion().empty())
948 continue;
949
950 // Print the leading padding.
951 fprintf(output_file, " ");
952
953 // Print the completion with trailing padding to the description column if
954 // that fits on the screen. Otherwise print whatever fits on the screen
955 // followed by ellipsis.
956 const size_t completion_length = c.GetCompletion().size();
957 if (padding_length + completion_length < max_length) {
958 fprintf(output_file, "%-*s",
959 static_cast<int>(description_col - padding_length),
960 c.GetCompletion().c_str());
961 } else {
962 // If the completion doesn't fit on the screen, print ellipsis and don't
963 // bother with the description.
964 fprintf(output_file, "%.*s...\n",
965 static_cast<int>(max_length - padding_length - ellipsis_length),
966 c.GetCompletion().c_str());
967 lines_printed++;
968 continue;
969 }
970
971 // If we don't have a description, or we don't have enough space left to
972 // print the separator followed by the ellipsis, we're done.
973 if (c.GetDescription().empty() ||
974 description_col + separator_length + ellipsis_length >= max_length) {
975 fprintf(output_file, "\n");
976 lines_printed++;
977 continue;
978 }
979
980 // Print the separator.
981 fprintf(output_file, " -- ");
982
983 // Descriptions can contain newlines. We want to print them below each
984 // other, aligned after the separator. For example, foo has a
985 // two-line description:
986 //
987 // foo -- Something that fits on the line.
988 // More information below.
989 //
990 // However, as soon as a line exceed the available screen width and
991 // print ellipsis, we don't print the next line. For example, foo has a
992 // three-line description:
993 //
994 // foo -- Something that fits on the line.
995 // Something much longer that doesn't fit...
996 //
997 // Because we had to print ellipsis on line two, we don't print the
998 // third line.
999 bool first = true;
1000 for (llvm::StringRef line : llvm::split(c.GetDescription(), '\n')) {
1001 if (line.empty())
1002 break;
1003 if (max_height && lines_printed >= *max_height)
1004 break;
1005 if (!first)
1006 fprintf(output_file, "%*s",
1007 static_cast<int>(description_col + separator_length), "");
1008
1009 first = false;
1010 const size_t position = description_col + separator_length;
1011 const size_t description_length = line.size();
1012 if (position + description_length < max_length) {
1013 fprintf(output_file, "%.*s\n", static_cast<int>(description_length),
1014 line.data());
1015 lines_printed++;
1016 } else {
1017 fprintf(output_file, "%.*s...\n",
1018 static_cast<int>(max_length - position - ellipsis_length),
1019 line.data());
1020 lines_printed++;
1021 continue;
1022 }
1023 }
1024 }
1025 return results_printed;
1026}
1027
1029 Editline &editline, llvm::ArrayRef<CompletionResult::Completion> results) {
1030 assert(!results.empty());
1031
1032 fprintf(editline.m_output_file,
1033 "\n" ANSI_CLEAR_BELOW "Available completions:\n");
1034
1035 /// Account for the current line, the line showing "Available completions"
1036 /// before and the line saying "More" after.
1037 const size_t page_size = editline.GetTerminalHeight() - 3;
1038
1039 bool all = false;
1040
1041 auto longest =
1042 std::max_element(results.begin(), results.end(), [](auto &c1, auto &c2) {
1043 return c1.GetCompletion().size() < c2.GetCompletion().size();
1044 });
1045
1046 const size_t max_len = longest->GetCompletion().size();
1047
1048 size_t cur_pos = 0;
1049 while (cur_pos < results.size()) {
1050 cur_pos +=
1051 PrintCompletion(editline.m_output_file, results.slice(cur_pos), max_len,
1052 editline.GetTerminalWidth(),
1053 all ? std::nullopt : std::optional<size_t>(page_size));
1054
1055 if (cur_pos >= results.size())
1056 break;
1057
1058 fprintf(editline.m_output_file, "More (Y/n/a): ");
1059 // The type for the output and the type for the parameter are different,
1060 // to allow interoperability with older versions of libedit. The container
1061 // for the reply must be as wide as what our implementation is using,
1062 // but libedit may use a narrower type depending on the build
1063 // configuration.
1064 EditLineGetCharType reply = L'n';
1065 int got_char = el_wgetc(editline.m_editline,
1066 reinterpret_cast<EditLineCharType *>(&reply));
1067 // Check for a ^C or other interruption.
1068 if (editline.m_editor_status == EditorStatus::Interrupted) {
1069 editline.m_editor_status = EditorStatus::Editing;
1070 fprintf(editline.m_output_file, "^C\n");
1071 break;
1072 }
1073
1074 fprintf(editline.m_output_file, "\n");
1075 if (got_char == -1 || reply == 'n')
1076 break;
1077 if (reply == 'a')
1078 all = true;
1079 }
1080}
1081
1082unsigned char Editline::TabCommand(int ch) {
1084 return CC_ERROR;
1085
1086 const LineInfo *line_info = el_line(m_editline);
1087
1088 llvm::StringRef line(line_info->buffer,
1089 line_info->lastchar - line_info->buffer);
1090 unsigned cursor_index = line_info->cursor - line_info->buffer;
1091 CompletionResult result;
1092 CompletionRequest request(line, cursor_index, result);
1093
1094 m_completion_callback(request);
1095
1096 llvm::ArrayRef<CompletionResult::Completion> results = result.GetResults();
1097
1098 StringList completions;
1099 result.GetMatches(completions);
1100
1101 if (results.size() == 0)
1102 return CC_ERROR;
1103
1104 if (results.size() == 1) {
1105 CompletionResult::Completion completion = results.front();
1106 switch (completion.GetMode()) {
1108 std::string to_add = completion.GetCompletion();
1109 // Terminate the current argument with a quote if it started with a quote.
1110 Args &parsedLine = request.GetParsedLine();
1111 if (!parsedLine.empty() && request.GetCursorIndex() < parsedLine.size() &&
1112 request.GetParsedArg().IsQuoted()) {
1113 to_add.push_back(request.GetParsedArg().GetQuoteChar());
1114 }
1115 to_add.push_back(' ');
1116 el_deletestr(m_editline, request.GetCursorArgumentPrefix().size());
1117 el_insertstr(m_editline, to_add.c_str());
1118 // Clear all the autosuggestion parts if the only single space can be completed.
1119 if (to_add == " ")
1120 return CC_REDISPLAY;
1121 return CC_REFRESH;
1122 }
1124 std::string to_add = completion.GetCompletion();
1125 to_add = to_add.substr(request.GetCursorArgumentPrefix().size());
1126 el_insertstr(m_editline, to_add.c_str());
1127 break;
1128 }
1130 el_deletestr(m_editline, line_info->cursor - line_info->buffer);
1131 el_insertstr(m_editline, completion.GetCompletion().c_str());
1132 break;
1133 }
1134 }
1135 return CC_REDISPLAY;
1136 }
1137
1138 // If we get a longer match display that first.
1139 std::string longest_prefix = completions.LongestCommonPrefix();
1140 if (!longest_prefix.empty())
1141 longest_prefix =
1142 longest_prefix.substr(request.GetCursorArgumentPrefix().size());
1143 if (!longest_prefix.empty()) {
1144 el_insertstr(m_editline, longest_prefix.c_str());
1145 return CC_REDISPLAY;
1146 }
1147
1148 DisplayCompletions(*this, results);
1149
1150 DisplayInput();
1151 MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingCursor);
1152 return CC_REDISPLAY;
1153}
1154
1156 if (!m_suggestion_callback) {
1157 return CC_REDISPLAY;
1158 }
1159
1160 const LineInfo *line_info = el_line(m_editline);
1161 llvm::StringRef line(line_info->buffer,
1162 line_info->lastchar - line_info->buffer);
1163
1164 if (std::optional<std::string> to_add = m_suggestion_callback(line))
1165 el_insertstr(m_editline, to_add->c_str());
1166
1167 return CC_REDISPLAY;
1168}
1169
1170unsigned char Editline::TypedCharacter(int ch) {
1171 std::string typed = std::string(1, ch);
1172 el_insertstr(m_editline, typed.c_str());
1173
1174 if (!m_suggestion_callback) {
1175 return CC_REDISPLAY;
1176 }
1177
1178 const LineInfo *line_info = el_line(m_editline);
1179 llvm::StringRef line(line_info->buffer,
1180 line_info->lastchar - line_info->buffer);
1181
1182 if (std::optional<std::string> to_add = m_suggestion_callback(line)) {
1183 std::string to_add_color =
1185 fputs(typed.c_str(), m_output_file);
1186 fputs(to_add_color.c_str(), m_output_file);
1187 size_t new_autosuggestion_size = line.size() + to_add->length();
1188 // Print spaces to hide any remains of a previous longer autosuggestion.
1189 if (new_autosuggestion_size < m_previous_autosuggestion_size) {
1190 size_t spaces_to_print =
1191 m_previous_autosuggestion_size - new_autosuggestion_size;
1192 std::string spaces = std::string(spaces_to_print, ' ');
1193 fputs(spaces.c_str(), m_output_file);
1194 }
1195 m_previous_autosuggestion_size = new_autosuggestion_size;
1196
1197 int editline_cursor_position =
1198 (int)((line_info->cursor - line_info->buffer) + GetPromptWidth());
1199 int editline_cursor_row = editline_cursor_position / m_terminal_width;
1200 int toColumn =
1201 editline_cursor_position - (editline_cursor_row * m_terminal_width);
1202 fprintf(m_output_file, ANSI_SET_COLUMN_N, toColumn);
1203 return CC_REFRESH;
1204 }
1205
1206 return CC_REDISPLAY;
1207}
1208
1210 const EditLineCharType *helptext,
1211 EditlineCommandCallbackType callbackFn) {
1212 el_wset(m_editline, EL_ADDFN, command, helptext, callbackFn);
1213}
1214
1216 EditlinePromptCallbackType callbackFn) {
1217 el_set(m_editline, EL_PROMPT, callbackFn);
1218}
1219
1221 el_wset(m_editline, EL_GETCFN, callbackFn);
1222}
1223
1224void Editline::ConfigureEditor(bool multiline) {
1225 if (m_editline && m_multiline_enabled == multiline)
1226 return;
1227 m_multiline_enabled = multiline;
1228
1229 if (m_editline) {
1230 // Disable edit mode to stop the terminal from flushing all input during
1231 // the call to el_end() since we expect to have multiple editline instances
1232 // in this program.
1233 el_set(m_editline, EL_EDITMODE, 0);
1234 el_end(m_editline);
1235 }
1236
1237 m_editline =
1240
1241 if (m_history_sp && m_history_sp->IsValid()) {
1242 if (!m_history_sp->Load()) {
1243 fputs("Could not load history file\n.", m_output_file);
1244 }
1245 el_wset(m_editline, EL_HIST, history, m_history_sp->GetHistoryPtr());
1246 }
1247 el_set(m_editline, EL_CLIENTDATA, this);
1248 el_set(m_editline, EL_SIGNAL, 0);
1249 el_set(m_editline, EL_EDITOR, "emacs");
1250
1251 SetGetCharacterFunction([](EditLine *editline, EditLineGetCharType *c) {
1252 return Editline::InstanceFor(editline)->GetCharacter(c);
1253 });
1254
1255 SetEditLinePromptCallback([](EditLine *editline) {
1256 return Editline::InstanceFor(editline)->Prompt();
1257 });
1258
1259 // Commands used for multiline support, registered whether or not they're
1260 // used
1262 EditLineConstString("lldb-break-line"),
1263 EditLineConstString("Insert a line break"),
1264 [](EditLine *editline, int ch) {
1265 return Editline::InstanceFor(editline)->BreakLineCommand(ch);
1266 });
1267
1269 EditLineConstString("lldb-end-or-add-line"),
1270 EditLineConstString("End editing or continue when incomplete"),
1271 [](EditLine *editline, int ch) {
1272 return Editline::InstanceFor(editline)->EndOrAddLineCommand(ch);
1273 });
1275 EditLineConstString("lldb-delete-next-char"),
1276 EditLineConstString("Delete next character"),
1277 [](EditLine *editline, int ch) {
1278 return Editline::InstanceFor(editline)->DeleteNextCharCommand(ch);
1279 });
1281 EditLineConstString("lldb-delete-previous-char"),
1282 EditLineConstString("Delete previous character"),
1283 [](EditLine *editline, int ch) {
1285 });
1287 EditLineConstString("lldb-previous-line"),
1288 EditLineConstString("Move to previous line"),
1289 [](EditLine *editline, int ch) {
1290 return Editline::InstanceFor(editline)->PreviousLineCommand(ch);
1291 });
1293 EditLineConstString("lldb-next-line"),
1294 EditLineConstString("Move to next line"), [](EditLine *editline, int ch) {
1295 return Editline::InstanceFor(editline)->NextLineCommand(ch);
1296 });
1298 EditLineConstString("lldb-previous-history"),
1299 EditLineConstString("Move to previous history"),
1300 [](EditLine *editline, int ch) {
1301 return Editline::InstanceFor(editline)->PreviousHistoryCommand(ch);
1302 });
1304 EditLineConstString("lldb-next-history"),
1305 EditLineConstString("Move to next history"),
1306 [](EditLine *editline, int ch) {
1307 return Editline::InstanceFor(editline)->NextHistoryCommand(ch);
1308 });
1310 EditLineConstString("lldb-buffer-start"),
1311 EditLineConstString("Move to start of buffer"),
1312 [](EditLine *editline, int ch) {
1313 return Editline::InstanceFor(editline)->BufferStartCommand(ch);
1314 });
1316 EditLineConstString("lldb-buffer-end"),
1317 EditLineConstString("Move to end of buffer"),
1318 [](EditLine *editline, int ch) {
1319 return Editline::InstanceFor(editline)->BufferEndCommand(ch);
1320 });
1322 EditLineConstString("lldb-fix-indentation"),
1323 EditLineConstString("Fix line indentation"),
1324 [](EditLine *editline, int ch) {
1325 return Editline::InstanceFor(editline)->FixIndentationCommand(ch);
1326 });
1327
1328 // Register the complete callback under two names for compatibility with
1329 // older clients using custom .editrc files (largely because libedit has a
1330 // bad bug where if you have a bind command that tries to bind to a function
1331 // name that doesn't exist, it can corrupt the heap and crash your process
1332 // later.)
1333 EditlineCommandCallbackType complete_callback = [](EditLine *editline,
1334 int ch) {
1335 return Editline::InstanceFor(editline)->TabCommand(ch);
1336 };
1338 EditLineConstString("Invoke completion"),
1339 complete_callback);
1341 EditLineConstString("Invoke completion"),
1342 complete_callback);
1343
1344 // General bindings we don't mind being overridden
1345 if (!multiline) {
1346 el_set(m_editline, EL_BIND, "^r", "em-inc-search-prev",
1347 NULL); // Cycle through backwards search, entering string
1348
1351 EditLineConstString("lldb-apply-complete"),
1352 EditLineConstString("Adopt autocompletion"),
1353 [](EditLine *editline, int ch) {
1354 return Editline::InstanceFor(editline)->ApplyAutosuggestCommand(ch);
1355 });
1356
1357 el_set(m_editline, EL_BIND, "^f", "lldb-apply-complete",
1358 NULL); // Apply a part that is suggested automatically
1359
1361 EditLineConstString("lldb-typed-character"),
1362 EditLineConstString("Typed character"),
1363 [](EditLine *editline, int ch) {
1364 return Editline::InstanceFor(editline)->TypedCharacter(ch);
1365 });
1366
1367 char bind_key[2] = {0, 0};
1368 llvm::StringRef ascii_chars =
1369 "abcdefghijklmnopqrstuvwxzyABCDEFGHIJKLMNOPQRSTUVWXZY1234567890!\"#$%"
1370 "&'()*+,./:;<=>?@[]_`{|}~ ";
1371 for (char c : ascii_chars) {
1372 bind_key[0] = c;
1373 el_set(m_editline, EL_BIND, bind_key, "lldb-typed-character", NULL);
1374 }
1375 el_set(m_editline, EL_BIND, "\\-", "lldb-typed-character", NULL);
1376 el_set(m_editline, EL_BIND, "\\^", "lldb-typed-character", NULL);
1377 el_set(m_editline, EL_BIND, "\\\\", "lldb-typed-character", NULL);
1378 }
1379 }
1380
1381 el_set(m_editline, EL_BIND, "^w", "ed-delete-prev-word",
1382 NULL); // Delete previous word, behave like bash in emacs mode
1383 el_set(m_editline, EL_BIND, "\t", "lldb-complete",
1384 NULL); // Bind TAB to auto complete
1385
1386 // Allow ctrl-left-arrow and ctrl-right-arrow for navigation, behave like
1387 // bash in emacs mode.
1388 el_set(m_editline, EL_BIND, ESCAPE "[1;5C", "em-next-word", NULL);
1389 el_set(m_editline, EL_BIND, ESCAPE "[1;5D", "ed-prev-word", NULL);
1390 el_set(m_editline, EL_BIND, ESCAPE "[5C", "em-next-word", NULL);
1391 el_set(m_editline, EL_BIND, ESCAPE "[5D", "ed-prev-word", NULL);
1392 el_set(m_editline, EL_BIND, ESCAPE ESCAPE "[C", "em-next-word", NULL);
1393 el_set(m_editline, EL_BIND, ESCAPE ESCAPE "[D", "ed-prev-word", NULL);
1394
1395 // Allow user-specific customization prior to registering bindings we
1396 // absolutely require
1397 el_source(m_editline, nullptr);
1398
1399 // Register an internal binding that external developers shouldn't use
1401 EditLineConstString("lldb-revert-line"),
1402 EditLineConstString("Revert line to saved state"),
1403 [](EditLine *editline, int ch) {
1404 return Editline::InstanceFor(editline)->RevertLineCommand(ch);
1405 });
1406
1407 // Register keys that perform auto-indent correction
1409 char bind_key[2] = {0, 0};
1410 const char *indent_chars = m_fix_indentation_callback_chars;
1411 while (*indent_chars) {
1412 bind_key[0] = *indent_chars;
1413 el_set(m_editline, EL_BIND, bind_key, "lldb-fix-indentation", NULL);
1414 ++indent_chars;
1415 }
1416 }
1417
1418 // Multi-line editor bindings
1419 if (multiline) {
1420 el_set(m_editline, EL_BIND, "\n", "lldb-end-or-add-line", NULL);
1421 el_set(m_editline, EL_BIND, "\r", "lldb-end-or-add-line", NULL);
1422 el_set(m_editline, EL_BIND, ESCAPE "\n", "lldb-break-line", NULL);
1423 el_set(m_editline, EL_BIND, ESCAPE "\r", "lldb-break-line", NULL);
1424 el_set(m_editline, EL_BIND, "^p", "lldb-previous-line", NULL);
1425 el_set(m_editline, EL_BIND, "^n", "lldb-next-line", NULL);
1426 el_set(m_editline, EL_BIND, "^?", "lldb-delete-previous-char", NULL);
1427 el_set(m_editline, EL_BIND, "^d", "lldb-delete-next-char", NULL);
1428 el_set(m_editline, EL_BIND, ESCAPE "[3~", "lldb-delete-next-char", NULL);
1429 el_set(m_editline, EL_BIND, ESCAPE "[\\^", "lldb-revert-line", NULL);
1430
1431 // Editor-specific bindings
1432 if (IsEmacs()) {
1433 el_set(m_editline, EL_BIND, ESCAPE "<", "lldb-buffer-start", NULL);
1434 el_set(m_editline, EL_BIND, ESCAPE ">", "lldb-buffer-end", NULL);
1435 el_set(m_editline, EL_BIND, ESCAPE "[A", "lldb-previous-line", NULL);
1436 el_set(m_editline, EL_BIND, ESCAPE "[B", "lldb-next-line", NULL);
1437 el_set(m_editline, EL_BIND, ESCAPE ESCAPE "[A", "lldb-previous-history",
1438 NULL);
1439 el_set(m_editline, EL_BIND, ESCAPE ESCAPE "[B", "lldb-next-history",
1440 NULL);
1441 el_set(m_editline, EL_BIND, ESCAPE "[1;3A", "lldb-previous-history",
1442 NULL);
1443 el_set(m_editline, EL_BIND, ESCAPE "[1;3B", "lldb-next-history", NULL);
1444 } else {
1445 el_set(m_editline, EL_BIND, "^H", "lldb-delete-previous-char", NULL);
1446
1447 el_set(m_editline, EL_BIND, "-a", ESCAPE "[A", "lldb-previous-line",
1448 NULL);
1449 el_set(m_editline, EL_BIND, "-a", ESCAPE "[B", "lldb-next-line", NULL);
1450 el_set(m_editline, EL_BIND, "-a", "x", "lldb-delete-next-char", NULL);
1451 el_set(m_editline, EL_BIND, "-a", "^H", "lldb-delete-previous-char",
1452 NULL);
1453 el_set(m_editline, EL_BIND, "-a", "^?", "lldb-delete-previous-char",
1454 NULL);
1455
1456 // Escape is absorbed exiting edit mode, so re-register important
1457 // sequences without the prefix
1458 el_set(m_editline, EL_BIND, "-a", "[A", "lldb-previous-line", NULL);
1459 el_set(m_editline, EL_BIND, "-a", "[B", "lldb-next-line", NULL);
1460 el_set(m_editline, EL_BIND, "-a", "[\\^", "lldb-revert-line", NULL);
1461 }
1462 }
1463}
1464
1465// Editline public methods
1466
1467Editline *Editline::InstanceFor(EditLine *editline) {
1468 Editline *editor;
1469 el_get(editline, EL_CLIENTDATA, &editor);
1470 return editor;
1471}
1472
1473Editline::Editline(const char *editline_name, FILE *input_file,
1474 FILE *output_file, FILE *error_file,
1475 std::recursive_mutex &output_mutex)
1476 : m_editor_status(EditorStatus::Complete), m_input_file(input_file),
1477 m_output_file(output_file), m_error_file(error_file),
1478 m_input_connection(fileno(input_file), false),
1479 m_output_mutex(output_mutex) {
1480 // Get a shared history instance
1481 m_editor_name = (editline_name == nullptr) ? "lldb-tmp" : editline_name;
1483}
1484
1486 if (m_editline) {
1487 // Disable edit mode to stop the terminal from flushing all input during
1488 // the call to el_end() since we expect to have multiple editline instances
1489 // in this program.
1490 el_set(m_editline, EL_EDITMODE, 0);
1491 el_end(m_editline);
1492 m_editline = nullptr;
1493 }
1494
1495 // EditlineHistory objects are sometimes shared between multiple Editline
1496 // instances with the same program name. So just release our shared pointer
1497 // and if we are the last owner, it will save the history to the history save
1498 // file automatically.
1499 m_history_sp.reset();
1500}
1501
1502void Editline::SetPrompt(const char *prompt) {
1503 m_set_prompt = prompt == nullptr ? "" : prompt;
1504}
1505
1506void Editline::SetContinuationPrompt(const char *continuation_prompt) {
1508 continuation_prompt == nullptr ? "" : continuation_prompt;
1509}
1510
1512
1514 if (!m_editline)
1515 return;
1516
1518 el_resize(m_editline);
1519 int columns;
1520 // This function is documenting as taking (const char *, void *) for the
1521 // vararg part, but in reality in was consuming arguments until the first
1522 // null pointer. This was fixed in libedit in April 2019
1523 // <http://mail-index.netbsd.org/source-changes/2019/04/26/msg105454.html>,
1524 // but we're keeping the workaround until a version with that fix is more
1525 // widely available.
1526 if (el_get(m_editline, EL_GETTC, "co", &columns, nullptr) == 0) {
1527 m_terminal_width = columns;
1528 if (m_current_line_rows != -1) {
1529 const LineInfoW *info = el_wline(m_editline);
1530 int lineLength =
1531 (int)((info->lastchar - info->buffer) + GetPromptWidth());
1532 m_current_line_rows = (lineLength / columns) + 1;
1533 }
1534 } else {
1535 m_terminal_width = INT_MAX;
1537 }
1538
1539 int rows;
1540 if (el_get(m_editline, EL_GETTC, "li", &rows, nullptr) == 0) {
1541 m_terminal_height = rows;
1542 } else {
1543 m_terminal_height = INT_MAX;
1544 }
1545}
1546
1547const char *Editline::GetPrompt() { return m_set_prompt.c_str(); }
1548
1550
1552 bool result = true;
1553 std::lock_guard<std::recursive_mutex> guard(m_output_mutex);
1554 if (m_editor_status == EditorStatus::Editing) {
1555 fprintf(m_output_file, "^C\n");
1557 }
1558 m_editor_status = EditorStatus::Interrupted;
1559 return result;
1560}
1561
1563 bool result = true;
1564 std::lock_guard<std::recursive_mutex> guard(m_output_mutex);
1565 if (m_editor_status == EditorStatus::Editing) {
1566 MoveCursor(CursorLocation::EditingCursor, CursorLocation::BlockStart);
1569 }
1570 m_editor_status = EditorStatus::Interrupted;
1571 return result;
1572}
1573
1574bool Editline::GetLine(std::string &line, bool &interrupted) {
1575 ConfigureEditor(false);
1576 m_input_lines = std::vector<EditLineStringType>();
1577 m_input_lines.insert(m_input_lines.begin(), EditLineConstString(""));
1578
1579 std::lock_guard<std::recursive_mutex> guard(m_output_mutex);
1580
1581 lldbassert(m_editor_status != EditorStatus::Editing);
1582 if (m_editor_status == EditorStatus::Interrupted) {
1583 m_editor_status = EditorStatus::Complete;
1584 interrupted = true;
1585 return true;
1586 }
1587
1588 SetCurrentLine(0);
1589 m_in_history = false;
1590 m_editor_status = EditorStatus::Editing;
1592
1593 int count;
1594 auto input = el_wgets(m_editline, &count);
1595
1596 interrupted = m_editor_status == EditorStatus::Interrupted;
1597 if (!interrupted) {
1598 if (input == nullptr) {
1599 fprintf(m_output_file, "\n");
1600 m_editor_status = EditorStatus::EndOfInput;
1601 } else {
1602 m_history_sp->Enter(input);
1603#if LLDB_EDITLINE_USE_WCHAR
1604 llvm::convertWideToUTF8(SplitLines(input)[0], line);
1605#else
1606 line = SplitLines(input)[0];
1607#endif
1608 m_editor_status = EditorStatus::Complete;
1609 }
1610 }
1611 return m_editor_status != EditorStatus::EndOfInput;
1612}
1613
1614bool Editline::GetLines(int first_line_number, StringList &lines,
1615 bool &interrupted) {
1616 ConfigureEditor(true);
1617
1618 // Print the initial input lines, then move the cursor back up to the start
1619 // of input
1620 SetBaseLineNumber(first_line_number);
1621 m_input_lines = std::vector<EditLineStringType>();
1622 m_input_lines.insert(m_input_lines.begin(), EditLineConstString(""));
1623
1624 std::lock_guard<std::recursive_mutex> guard(m_output_mutex);
1625 // Begin the line editing loop
1626 DisplayInput();
1627 SetCurrentLine(0);
1628 MoveCursor(CursorLocation::BlockEnd, CursorLocation::BlockStart);
1629 m_editor_status = EditorStatus::Editing;
1630 m_in_history = false;
1631
1633 while (m_editor_status == EditorStatus::Editing) {
1634 int count;
1637 "\x1b[^")); // Revert to the existing line content
1638 el_wgets(m_editline, &count);
1639 }
1640
1641 interrupted = m_editor_status == EditorStatus::Interrupted;
1642 if (!interrupted) {
1643 // Save the completed entry in history before returning. Don't save empty
1644 // input as that just clutters the command history.
1645 if (!m_input_lines.empty())
1646 m_history_sp->Enter(CombineLines(m_input_lines).c_str());
1647
1648 lines = GetInputAsStringList();
1649 }
1650 return m_editor_status != EditorStatus::EndOfInput;
1651}
1652
1653void Editline::PrintAsync(Stream *stream, const char *s, size_t len) {
1654 std::lock_guard<std::recursive_mutex> guard(m_output_mutex);
1655 if (m_editor_status == EditorStatus::Editing) {
1657 MoveCursor(CursorLocation::EditingCursor, CursorLocation::BlockStart);
1659 }
1660 stream->Write(s, len);
1661 stream->Flush();
1662 if (m_editor_status == EditorStatus::Editing) {
1663 DisplayInput();
1664 MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingCursor);
1665 }
1666}
1667
1669#if !LLDB_EDITLINE_USE_WCHAR
1670 if (ch == (char)EOF)
1671 return false;
1672
1673 out = (unsigned char)ch;
1674 return true;
1675#else
1676 llvm::SmallString<4> input;
1677 for (;;) {
1678 input.push_back(ch);
1679 auto *cur_ptr = reinterpret_cast<const llvm::UTF8 *>(input.begin());
1680 auto *end_ptr = reinterpret_cast<const llvm::UTF8 *>(input.end());
1681 llvm::UTF32 code_point = 0;
1682 llvm::ConversionResult cr = llvm::convertUTF8Sequence(
1683 &cur_ptr, end_ptr, &code_point, llvm::lenientConversion);
1684 switch (cr) {
1685 case llvm::conversionOK:
1686 out = code_point;
1687 return out != (EditLineGetCharType)WEOF;
1688 case llvm::targetExhausted:
1689 case llvm::sourceIllegal:
1690 return false;
1691 case llvm::sourceExhausted:
1693 size_t read_count = m_input_connection.Read(
1694 &ch, 1, std::chrono::seconds(0), status, nullptr);
1695 if (read_count == 0)
1696 return false;
1697 break;
1698 }
1699 }
1700#endif
1701}
#define el_wgets
Definition: Editline.cpp:67
EditLineStringType CombineLines(const std::vector< EditLineStringType > &lines)
Definition: Editline.cpp:124
#define EditLineConstString(str)
Definition: Editline.cpp:55
#define ANSI_UP_N_ROWS
Definition: Editline.cpp:45
#define el_wline
Definition: Editline.cpp:73
#define EditLineStringFormatSpec
Definition: Editline.cpp:56
static size_t PrintCompletion(FILE *output_file, llvm::ArrayRef< CompletionResult::Completion > results, size_t max_completion_length, size_t max_length, std::optional< size_t > max_height=std::nullopt)
Prints completions and their descriptions to the given file.
Definition: Editline.cpp:928
#define LineInfoW
Definition: Editline.cpp:65
EditLineStringType FixIndentation(const EditLineStringType &line, int indent_correction)
Definition: Editline.cpp:152
#define ANSI_DOWN_N_ROWS
Definition: Editline.cpp:46
#define history_wend
Definition: Editline.cpp:62
#define el_winsertstr
Definition: Editline.cpp:74
#define el_wpush
Definition: Editline.cpp:69
#define HistEventW
Definition: Editline.cpp:64
#define history_winit
Definition: Editline.cpp:61
bool IsInputPending(FILE *file)
Definition: Editline.cpp:171
static size_t ColumnWidth(llvm::StringRef str)
Definition: Editline.cpp:87
#define el_wgetc
Definition: Editline.cpp:68
#define ANSI_CLEAR_BELOW
Definition: Editline.cpp:42
#define el_wset
Definition: Editline.cpp:71
#define ANSI_SET_COLUMN_N
Definition: Editline.cpp:44
std::vector< EditLineStringType > SplitLines(const EditLineStringType &input)
Definition: Editline.cpp:132
#define HistoryW
Definition: Editline.cpp:63
bool IsOnlySpaces(const EditLineStringType &content)
Definition: Editline.cpp:79
#define history_w
Definition: Editline.cpp:60
int GetIndentation(const EditLineStringType &line)
Definition: Editline.cpp:161
static int GetOperation(HistoryOperation op)
Definition: Editline.cpp:91
#define ESCAPE
https://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf
Definition: Editline.cpp:41
#define lldbassert(x)
Definition: LLDBAssert.h:15
lldb_private::Status Select()
void FDSetRead(lldb::socket_t fd)
void SetTimeout(const std::chrono::microseconds &timeout)
A command line argument class.
Definition: Args.h:33
size_t size() const
Definition: Args.h:139
bool empty() const
Definition: Args.h:122
"lldb/Utility/ArgCompletionRequest.h"
const Args & GetParsedLine() const
llvm::StringRef GetCursorArgumentPrefix() const
const Args::ArgEntry & GetParsedArg()
A single completion and all associated data.
const std::string & GetCompletion() const
llvm::ArrayRef< Completion > GetResults() const
void GetMatches(StringList &matches) const
Adds all collected completion matches to the given list.
bool InterruptRead() override
Interrupts an ongoing Read() operation.
size_t Read(void *dst, size_t dst_len, const Timeout< std::micro > &timeout, lldb::ConnectionStatus &status, Status *error_ptr) override
The read function that attempts to read from the connection.
Instances of Editline provide an abstraction over libedit's EditLine facility.
Definition: Editline.h:152
IsInputCompleteCallbackType m_is_input_complete_callback
Definition: Editline.h:395
EditorStatus m_editor_status
Definition: Editline.h:376
unsigned char PreviousLineCommand(int ch)
Line navigation command used when ^P or up arrow are pressed in multi-line mode.
Definition: Editline.cpp:779
unsigned char RecallHistory(HistoryOperation op)
Replaces the current multi-line session with the next entry from history.
Definition: Editline.cpp:458
size_t GetTerminalWidth()
Definition: Editline.h:241
bool IsOnlySpaces()
Returns true if the current EditLine buffer contains nothing but spaces, or is empty.
Definition: Editline.cpp:353
::EditLine * m_editline
Definition: Editline.h:370
void SaveEditedLine()
Save the line currently being edited.
Definition: Editline.cpp:435
void MoveCursor(CursorLocation from, CursorLocation to)
Move the cursor from one well-established location to another using relative line positioning and abs...
Definition: Editline.cpp:384
std::string m_suggestion_ansi_suffix
Definition: Editline.h:406
void SetGetCharacterFunction(EditlineGetCharCallbackType callbackFn)
Definition: Editline.cpp:1220
std::string m_current_prompt
Definition: Editline.h:386
static void DisplayCompletions(Editline &editline, llvm::ArrayRef< CompletionResult::Completion > results)
Definition: Editline.cpp:1028
std::string m_set_continuation_prompt
Definition: Editline.h:385
std::size_t m_previous_autosuggestion_size
Definition: Editline.h:408
ConnectionFileDescriptor m_input_connection
Definition: Editline.h:393
unsigned char BufferStartCommand(int ch)
Buffer start command used when Esc < is typed in multi-line emacs mode.
Definition: Editline.cpp:909
const char * Prompt()
Prompt implementation for EditLine.
Definition: Editline.cpp:612
unsigned char EndOrAddLineCommand(int ch)
Command used when return is pressed in multi-line mode.
Definition: Editline.cpp:666
unsigned char DeletePreviousCharCommand(int ch)
Delete command used when backspace is pressed in multi-line mode.
Definition: Editline.cpp:745
int GetLineIndexForLocation(CursorLocation location, int cursor_row)
Helper method used by MoveCursor to determine relative line position.
Definition: Editline.cpp:363
std::string m_prompt_ansi_prefix
Definition: Editline.h:403
bool IsEmacs()
Returns true if the underlying EditLine session's keybindings are Emacs-based, or false if they are V...
Definition: Editline.cpp:347
CompleteCallbackType m_completion_callback
Definition: Editline.h:400
size_t GetPromptWidth()
Determines the width of the prompt in characters.
Definition: Editline.cpp:345
unsigned char PreviousHistoryCommand(int ch)
History navigation command used when Alt + up arrow is pressed in multi-line mode.
Definition: Editline.cpp:837
const char * m_fix_indentation_callback_chars
Definition: Editline.h:398
std::string m_editor_name
Definition: Editline.h:389
uint32_t GetCurrentLine()
Returns the index of the line currently being edited.
Definition: Editline.cpp:1549
void DisplayInput(int firstIndex=0)
Clear from cursor position to bottom of screen and print input lines including prompts,...
Definition: Editline.cpp:413
int GetCharacter(EditLineGetCharType *c)
Character reading implementation for EditLine that supports our multi-line editing trickery.
Definition: Editline.cpp:530
void TerminalSizeChanged()
Call when the terminal size changes.
Definition: Editline.cpp:1511
volatile std::sig_atomic_t m_terminal_size_has_changed
Definition: Editline.h:388
void SetEditLinePromptCallback(EditlinePromptCallbackType callbackFn)
Definition: Editline.cpp:1215
EditlineHistorySP m_history_sp
Definition: Editline.h:371
static Editline * InstanceFor(::EditLine *editline)
Uses the user data storage of EditLine to retrieve an associated instance of Editline.
Definition: Editline.cpp:1467
bool GetLine(std::string &line, bool &interrupted)
Prompts for and reads a single line of user input.
Definition: Editline.cpp:1574
std::string m_set_prompt
Definition: Editline.h:384
void SetCurrentLine(int line_index)
Sets the current line index between line edits to allow free movement between lines.
Definition: Editline.cpp:340
int CountRowsForLine(const EditLineStringType &content)
Counts the number of rows a given line of content will end up occupying, taking into account both the...
Definition: Editline.cpp:428
void ConfigureEditor(bool multiline)
Ensures that the current EditLine instance is properly configured for single or multi-line editing.
Definition: Editline.cpp:1224
unsigned char NextLineCommand(int ch)
Line navigation command used when ^N or down arrow are pressed in multi-line mode.
Definition: Editline.cpp:801
void PrintAsync(Stream *stream, const char *s, size_t len)
Definition: Editline.cpp:1653
std::vector< EditLineStringType > m_live_history_lines
Definition: Editline.h:373
void AddFunctionToEditLine(const EditLineCharType *command, const EditLineCharType *helptext, EditlineCommandCallbackType callbackFn)
Definition: Editline.cpp:1209
std::vector< EditLineStringType > m_input_lines
Definition: Editline.h:375
bool CompleteCharacter(char ch, EditLineGetCharType &out)
Definition: Editline.cpp:1668
bool Cancel()
Cancel this edit and obliterate all trace of it.
Definition: Editline.cpp:1562
unsigned char DeleteNextCharCommand(int ch)
Delete command used when delete is pressed in multi-line mode.
Definition: Editline.cpp:706
std::string m_suggestion_ansi_prefix
Definition: Editline.h:405
SuggestionCallbackType m_suggestion_callback
Definition: Editline.h:401
unsigned char FixIndentationCommand(int ch)
Respond to normal character insertion by fixing line indentation.
Definition: Editline.cpp:849
unsigned char NextHistoryCommand(int ch)
History navigation command used when Alt + down arrow is pressed in multi-line mode.
Definition: Editline.cpp:843
void SetPrompt(const char *prompt)
Sets a string to be used as a prompt, or combined with a line number to form a prompt.
Definition: Editline.cpp:1502
size_t GetTerminalHeight()
Definition: Editline.h:243
unsigned char BufferEndCommand(int ch)
Buffer end command used when Esc > is typed in multi-line emacs mode.
Definition: Editline.cpp:917
unsigned char TypedCharacter(int ch)
Command used when a character is typed.
Definition: Editline.cpp:1170
unsigned char BreakLineCommand(int ch)
Line break command used when meta+return is pressed in multi-line mode.
Definition: Editline.cpp:618
FixIndentationCallbackType m_fix_indentation_callback
Definition: Editline.h:397
unsigned char ApplyAutosuggestCommand(int ch)
Apply autosuggestion part in gray as editline.
Definition: Editline.cpp:1155
unsigned char TabCommand(int ch)
Context-sensitive tab insertion or code completion command used when the tab key is typed.
Definition: Editline.cpp:1082
Editline(const char *editor_name, FILE *input_file, FILE *output_file, FILE *error_file, std::recursive_mutex &output_mutex)
Definition: Editline.cpp:1473
std::recursive_mutex & m_output_mutex
Definition: Editline.h:409
void SetContinuationPrompt(const char *continuation_prompt)
Sets an alternate string to be used as a prompt for the second line and beyond in multi-line editing ...
Definition: Editline.cpp:1506
unsigned m_current_line_index
Definition: Editline.h:380
StringList GetInputAsStringList(int line_count=UINT32_MAX)
Convert the current input lines into a UTF8 StringList.
Definition: Editline.cpp:441
std::string PromptForIndex(int line_index)
Returns the complete prompt by combining the prompt or continuation prompt with line numbers as appro...
Definition: Editline.cpp:310
unsigned char RevertLineCommand(int ch)
Revert line command used when moving between lines.
Definition: Editline.cpp:896
bool Interrupt()
Interrupt the current edit as if ^C was pressed.
Definition: Editline.cpp:1551
const char * GetPrompt()
Returns the prompt established by SetPrompt.
Definition: Editline.cpp:1547
void SetBaseLineNumber(int line_number)
Sets the lowest line number for multi-line editing sessions.
Definition: Editline.cpp:304
bool GetLines(int first_line_number, StringList &lines, bool &interrupted)
Prompts for and reads a multi-line batch of user input.
Definition: Editline.cpp:1614
std::string m_prompt_ansi_suffix
Definition: Editline.h:404
bool GetHomeDirectory(llvm::SmallVectorImpl< char > &path) const
Get the user home directory.
static FileSystem & Instance()
bool Success() const
Test for success condition.
Definition: Status.cpp:280
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
Definition: Stream.h:112
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
virtual void Flush()=0
Flush the stream.
void AppendString(const std::string &s)
Definition: StringList.cpp:43
const char * GetStringAtIndex(size_t idx) const
Definition: StringList.cpp:86
std::string LongestCommonPrefix()
Definition: StringList.cpp:107
void Enter(const EditLineCharType *line_cstr)
Definition: Editline.cpp:261
std::string m_path
Path to the history file.
Definition: Editline.cpp:297
std::string m_prefix
The prefix name (usually the editline program name) to use when loading/saving history.
Definition: Editline.cpp:295
HistoryW * m_history
The history object.
Definition: Editline.cpp:290
EditlineHistory(const std::string &prefix, uint32_t size, bool unique_entries)
Definition: Editline.cpp:195
static EditlineHistorySP GetHistory(const std::string &prefix)
Definition: Editline.cpp:239
HistEventW m_event
The history event needed to contain all history events.
Definition: Editline.cpp:292
std::stringstream EditLineStringStreamType
Definition: Editline.h:67
std::weak_ptr< EditlineHistory > EditlineHistoryWP
Definition: Editline.cpp:186
unsigned char(*)(::EditLine *editline, int ch) EditlineCommandCallbackType
Definition: Editline.h:86
const char *(*)(::EditLine *editline) EditlinePromptCallbackType
Definition: Editline.h:87
int(*)(::EditLine *editline, EditLineGetCharType *c) EditlineGetCharCallbackType
Definition: Editline.h:84
std::string EditLineStringType
Definition: Editline.h:66
HistoryOperation
Operation for the history.
Definition: Editline.h:139
std::shared_ptr< EditlineHistory > EditlineHistorySP
Definition: Editline.h:91
EditorStatus
Status used to decide when and how to start editing another line in multi-line sessions.
Definition: Editline.h:106
@ Complete
Editing complete, returns the complete set of edited lines.
CursorLocation
Established locations that can be easily moved among with MoveCursor.
Definition: Editline.h:122
A class that represents a running process on the host machine.
@ Partial
The current token has been partially completed.
@ Normal
The current token has been completed.
@ RewriteLine
The full line has been rewritten by the completion.
ConnectionStatus
Connection Status Types.
@ eConnectionStatusError
Check GetError() for details.
@ eConnectionStatusInterrupted
Interrupted read.
@ eConnectionStatusTimedOut
Request timed out.
@ eConnectionStatusEndOfFile
End-of-file encountered.
@ eConnectionStatusSuccess
Success.
@ eConnectionStatusLostConnection
Lost connection while connected to a valid connection.
@ eConnectionStatusNoConnection
No connection.
bool IsQuoted() const
Returns true if this argument was quoted in any way.
Definition: Args.h:54
char GetQuoteChar() const
Definition: Args.h:55