25#include "llvm/Support/ConvertUTF.h"
27#include "llvm/Support/FileSystem.h"
28#include "llvm/Support/Locale.h"
29#include "llvm/Support/Threading.h"
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"
48#if LLDB_EDITLINE_USE_WCHAR
50#define EditLineConstString(str) L##str
51#define EditLineStringFormatSpec "%ls"
55#define EditLineConstString(str) str
56#define EditLineStringFormatSpec "%s"
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
67#define el_wgets el_gets
68#define el_wgetc el_getc
69#define el_wpush el_push
70#define el_wparse el_parse
73#define el_wline el_line
74#define el_winsertstr el_insertstr
75#define el_wdeletestr el_deletestr
80 for (
wchar_t ch : content) {
88 return llvm::sys::locale::columnWidth(str);
109 case HistoryOperation::Oldest:
111 case HistoryOperation::Older:
113 case HistoryOperation::Current:
115 case HistoryOperation::Newer:
117 case HistoryOperation::Newest:
120 llvm_unreachable(
"Fully covered switch!");
127 combined_stream << line.c_str() <<
"\n";
129 return combined_stream.str();
133 std::vector<EditLineStringType> result;
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));
141 result.push_back(input.substr(start, end - start));
146 if (result.empty()) {
147 result.emplace_back();
153 int indent_correction) {
154 if (indent_correction == 0)
156 if (indent_correction < 0)
157 return line.substr(-indent_correction);
177 const int fd = fileno(file);
179 select_helper.
SetTimeout(std::chrono::microseconds(0));
185namespace line_editor {
206 llvm::SmallString<128> lldb_history_file;
208 llvm::sys::path::append(lldb_history_file,
".lldb");
212 if (!llvm::sys::fs::create_directory(lldb_history_file)) {
213#if LLDB_EDITLINE_USE_WCHAR
214 std::string filename =
m_prefix +
"-widehistory";
216 std::string filename =
m_prefix +
"-history";
218 llvm::sys::path::append(lldb_history_file, filename);
219 m_path = std::string(lldb_history_file.str());
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);
246 if (pos != g_weak_map.end()) {
247 history_sp = pos->second.lock();
250 g_weak_map.erase(pos);
253 g_weak_map[prefix] = history_sp;
307 std::max<int>(3, std::to_string(line_number).length() + 1);
313 if (use_line_numbers && prompt.length() == 0)
315 std::string continuation_prompt = 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,
' ');
330 if (use_line_numbers) {
334 (line_index == 0) ? prompt.c_str() : continuation_prompt.c_str());
335 return std::string(std::move(prompt_stream.
GetString()));
337 return (line_index == 0) ? prompt : continuation_prompt;
350 return editor[0] ==
'e';
356 character < info->lastchar; character++) {
357 if (*character !=
' ')
365 if (location == CursorLocation::EditingPrompt ||
366 location == CursorLocation::BlockEnd ||
367 location == CursorLocation::EditingCursor) {
371 if (location == CursorLocation::EditingCursor) {
373 }
else if (location == CursorLocation::BlockEnd) {
386 int editline_cursor_position =
393 if (toLine != fromLine) {
396 std::abs(toLine - fromLine));
401 if (to == CursorLocation::EditingCursor) {
404 }
else if (to == CursorLocation::BlockEnd && !
m_input_lines.empty()) {
416 for (
int index = firstIndex; index < line_count; index++) {
423 if (index < line_count - 1)
431 int line_length = (int)(content.length() +
ColumnWidth(prompt));
446#if LLDB_EDITLINE_USE_WCHAR
448 llvm::convertWideToUTF8(line, buffer);
459 assert(op == HistoryOperation::Older || op == HistoryOperation::Newer);
465 std::vector<EditLineStringType> new_input_lines;
470 case HistoryOperation::Newer:
472 case HistoryOperation::Older: {
485 llvm_unreachable(
"unsupported history direction");
490 case HistoryOperation::Older:
493 case HistoryOperation::Newer:
499 llvm_unreachable(
"unsupported history direction");
506 new_input_lines =
SplitLines(history_event.str);
509 MoveCursor(CursorLocation::EditingCursor, CursorLocation::BlockStart);
516 case HistoryOperation::Older:
519 case HistoryOperation::Newer:
523 llvm_unreachable(
"unsupported history direction");
526 MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingPrompt);
536 MoveCursor(CursorLocation::EditingCursor, CursorLocation::EditingPrompt);
543 MoveCursor(CursorLocation::EditingPrompt, CursorLocation::EditingCursor);
550 int lineLength = (int)((info->lastchar - info->buffer) +
GetPromptWidth());
554 MoveCursor(CursorLocation::EditingCursor, CursorLocation::EditingPrompt);
557 MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingCursor);
596 llvm_unreachable(
"Interrupts should have been handled above.");
623 auto new_line_fragment =
640#if LLDB_EDITLINE_USE_WCHAR
642 llvm::convertWideToUTF8(new_line_fragment, buffer);
649 new_line_fragment =
FixIndentation(new_line_fragment, indent_correction);
657 MoveCursor(CursorLocation::EditingCursor, CursorLocation::EditingPrompt);
662 MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingPrompt);
680 info->cursor == info->lastchar) {
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);
700 MoveCursor(CursorLocation::EditingCursor, CursorLocation::BlockEnd);
710 if (info->cursor < info->lastchar) {
719 if (ch == 4 && info->buffer == info->lastchar) {
728 MoveCursor(CursorLocation::EditingCursor, CursorLocation::EditingPrompt);
733 info->cursor = cursor;
741 MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingCursor);
750 if (info->cursor > info->buffer) {
774 MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingPrompt);
787 MoveCursor(CursorLocation::EditingCursor, CursorLocation::EditingPrompt);
828 int cursor_position = (int)((info->cursor - info->buffer) +
GetPromptWidth());
857 int cursor_position = info->cursor - info->buffer;
862 int indent_correction =
866 if (indent_correction == 0)
871 if (indent_correction > 0) {
872 currentLine = currentLine.insert(0, indent_correction,
' ');
874 currentLine = currentLine.erase(0, -indent_correction);
876#if LLDB_EDITLINE_USE_WCHAR
877 std::wstring wbuffer;
878 llvm::ConvertUTF8toWide(currentLine, wbuffer);
885 MoveCursor(CursorLocation::EditingCursor, CursorLocation::EditingPrompt);
891 MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingPrompt);
901 if (info->cursor > info->lastchar) {
902 info->cursor = info->lastchar;
911 MoveCursor(CursorLocation::EditingCursor, CursorLocation::BlockStart);
919 MoveCursor(CursorLocation::EditingCursor, CursorLocation::BlockEnd);
921 MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingPrompt);
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;
936 const size_t description_col =
937 std::min(max_completion_length + padding_length, max_length);
939 size_t lines_printed = 0;
940 size_t results_printed = 0;
942 if (max_height && lines_printed >= *max_height)
947 if (c.GetCompletion().empty())
951 fprintf(output_file,
" ");
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());
964 fprintf(output_file,
"%.*s...\n",
965 static_cast<int>(max_length - padding_length - ellipsis_length),
966 c.GetCompletion().c_str());
973 if (c.GetDescription().empty() ||
974 description_col + separator_length + ellipsis_length >= max_length) {
975 fprintf(output_file,
"\n");
981 fprintf(output_file,
" -- ");
1000 for (llvm::StringRef line : llvm::split(c.GetDescription(),
'\n')) {
1003 if (max_height && lines_printed >= *max_height)
1006 fprintf(output_file,
"%*s",
1007 static_cast<int>(description_col + separator_length),
"");
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),
1017 fprintf(output_file,
"%.*s...\n",
1018 static_cast<int>(max_length - position - ellipsis_length),
1025 return results_printed;
1029 Editline &editline, llvm::ArrayRef<CompletionResult::Completion> results) {
1030 assert(!results.empty());
1042 std::max_element(results.begin(), results.end(), [](
auto &c1,
auto &c2) {
1043 return c1.GetCompletion().size() < c2.GetCompletion().size();
1046 const size_t max_len = longest->GetCompletion().size();
1049 while (cur_pos < results.size()) {
1053 all ? std::nullopt : std::optional<size_t>(page_size));
1055 if (cur_pos >= results.size())
1075 if (got_char == -1 || reply ==
'n')
1086 const LineInfo *line_info = el_line(
m_editline);
1088 llvm::StringRef line(line_info->buffer,
1089 line_info->lastchar - line_info->buffer);
1090 unsigned cursor_index = line_info->cursor - line_info->buffer;
1096 llvm::ArrayRef<CompletionResult::Completion> results = result.
GetResults();
1101 if (results.size() == 0)
1104 if (results.size() == 1) {
1106 switch (completion.
GetMode()) {
1115 to_add.push_back(
' ');
1120 return CC_REDISPLAY;
1130 el_deletestr(
m_editline, line_info->cursor - line_info->buffer);
1135 return CC_REDISPLAY;
1140 if (!longest_prefix.empty())
1143 if (!longest_prefix.empty()) {
1144 el_insertstr(
m_editline, longest_prefix.c_str());
1145 return CC_REDISPLAY;
1151 MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingCursor);
1152 return CC_REDISPLAY;
1157 return CC_REDISPLAY;
1160 const LineInfo *line_info = el_line(
m_editline);
1161 llvm::StringRef line(line_info->buffer,
1162 line_info->lastchar - line_info->buffer);
1167 return CC_REDISPLAY;
1171 std::string typed = std::string(1, ch);
1175 return CC_REDISPLAY;
1178 const LineInfo *line_info = el_line(
m_editline);
1179 llvm::StringRef line(line_info->buffer,
1180 line_info->lastchar - line_info->buffer);
1183 std::string to_add_color =
1187 size_t new_autosuggestion_size = line.size() + to_add->length();
1190 size_t spaces_to_print =
1192 std::string spaces = std::string(spaces_to_print,
' ');
1197 int editline_cursor_position =
1198 (int)((line_info->cursor - line_info->buffer) +
GetPromptWidth());
1206 return CC_REDISPLAY;
1264 [](EditLine *editline,
int ch) {
1271 [](EditLine *editline,
int ch) {
1277 [](EditLine *editline,
int ch) {
1283 [](EditLine *editline,
int ch) {
1289 [](EditLine *editline,
int ch) {
1300 [](EditLine *editline,
int ch) {
1306 [](EditLine *editline,
int ch) {
1312 [](EditLine *editline,
int ch) {
1318 [](EditLine *editline,
int ch) {
1324 [](EditLine *editline,
int ch) {
1346 el_set(
m_editline, EL_BIND,
"^r",
"em-inc-search-prev",
1353 [](EditLine *editline,
int ch) {
1357 el_set(
m_editline, EL_BIND,
"^f",
"lldb-apply-complete",
1363 [](EditLine *editline,
int ch) {
1367 char bind_key[2] = {0, 0};
1368 llvm::StringRef ascii_chars =
1369 "abcdefghijklmnopqrstuvwxzyABCDEFGHIJKLMNOPQRSTUVWXZY1234567890!\"#$%"
1370 "&'()*+,./:;<=>?@[]_`{|}~ ";
1371 for (
char c : ascii_chars) {
1373 el_set(
m_editline, EL_BIND, bind_key,
"lldb-typed-character", NULL);
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);
1381 el_set(
m_editline, EL_BIND,
"^w",
"ed-delete-prev-word",
1383 el_set(
m_editline, EL_BIND,
"\t",
"lldb-complete",
1403 [](EditLine *editline,
int ch) {
1409 char bind_key[2] = {0, 0};
1411 while (*indent_chars) {
1412 bind_key[0] = *indent_chars;
1413 el_set(
m_editline, EL_BIND, bind_key,
"lldb-fix-indentation", NULL);
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);
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);
1445 el_set(
m_editline, EL_BIND,
"^H",
"lldb-delete-previous-char", 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",
1453 el_set(
m_editline, EL_BIND,
"-a",
"^?",
"lldb-delete-previous-char",
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);
1469 el_get(editline, EL_CLIENTDATA, &editor);
1474 FILE *output_file, FILE *error_file,
1475 std::recursive_mutex &output_mutex)
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) {
1481 m_editor_name = (editline_name ==
nullptr) ?
"lldb-tmp" : editline_name;
1508 continuation_prompt ==
nullptr ?
"" : continuation_prompt;
1526 if (el_get(
m_editline, EL_GETTC,
"co", &columns,
nullptr) == 0) {
1540 if (el_get(
m_editline, EL_GETTC,
"li", &rows,
nullptr) == 0) {
1566 MoveCursor(CursorLocation::EditingCursor, CursorLocation::BlockStart);
1598 if (input ==
nullptr) {
1603#if LLDB_EDITLINE_USE_WCHAR
1604 llvm::convertWideToUTF8(
SplitLines(input)[0], line);
1615 bool &interrupted) {
1628 MoveCursor(CursorLocation::BlockEnd, CursorLocation::BlockStart);
1657 MoveCursor(CursorLocation::EditingCursor, CursorLocation::BlockStart);
1660 stream->
Write(s, len);
1664 MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingCursor);
1669#if !LLDB_EDITLINE_USE_WCHAR
1670 if (ch == (
char)EOF)
1673 out = (
unsigned char)ch;
1676 llvm::SmallString<4> input;
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);
1685 case llvm::conversionOK:
1688 case llvm::targetExhausted:
1689 case llvm::sourceIllegal:
1691 case llvm::sourceExhausted:
1694 &ch, 1, std::chrono::seconds(0), status,
nullptr);
1695 if (read_count == 0)
EditLineStringType CombineLines(const std::vector< EditLineStringType > &lines)
#define EditLineConstString(str)
#define EditLineStringFormatSpec
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.
EditLineStringType FixIndentation(const EditLineStringType &line, int indent_correction)
bool IsInputPending(FILE *file)
static size_t ColumnWidth(llvm::StringRef str)
#define ANSI_SET_COLUMN_N
std::vector< EditLineStringType > SplitLines(const EditLineStringType &input)
bool IsOnlySpaces(const EditLineStringType &content)
int GetIndentation(const EditLineStringType &line)
static int GetOperation(HistoryOperation op)
#define ESCAPE
https://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf
lldb_private::Status Select()
void FDSetRead(lldb::socket_t fd)
void SetTimeout(const std::chrono::microseconds &timeout)
A command line argument class.
"lldb/Utility/ArgCompletionRequest.h"
const Args & GetParsedLine() const
llvm::StringRef GetCursorArgumentPrefix() const
const Args::ArgEntry & GetParsedArg()
size_t GetCursorIndex() const
A single completion and all associated data.
const std::string & GetCompletion() const
CompletionMode GetMode() 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.
IsInputCompleteCallbackType m_is_input_complete_callback
EditorStatus m_editor_status
unsigned char PreviousLineCommand(int ch)
Line navigation command used when ^P or up arrow are pressed in multi-line mode.
unsigned char RecallHistory(HistoryOperation op)
Replaces the current multi-line session with the next entry from history.
size_t GetTerminalWidth()
bool IsOnlySpaces()
Returns true if the current EditLine buffer contains nothing but spaces, or is empty.
void SaveEditedLine()
Save the line currently being edited.
void MoveCursor(CursorLocation from, CursorLocation to)
Move the cursor from one well-established location to another using relative line positioning and abs...
std::string m_suggestion_ansi_suffix
void SetGetCharacterFunction(EditlineGetCharCallbackType callbackFn)
bool m_needs_prompt_repaint
std::string m_current_prompt
static void DisplayCompletions(Editline &editline, llvm::ArrayRef< CompletionResult::Completion > results)
std::string m_set_continuation_prompt
std::size_t m_previous_autosuggestion_size
ConnectionFileDescriptor m_input_connection
unsigned char BufferStartCommand(int ch)
Buffer start command used when Esc < is typed in multi-line emacs mode.
const char * Prompt()
Prompt implementation for EditLine.
unsigned char EndOrAddLineCommand(int ch)
Command used when return is pressed in multi-line mode.
unsigned char DeletePreviousCharCommand(int ch)
Delete command used when backspace is pressed in multi-line mode.
int GetLineIndexForLocation(CursorLocation location, int cursor_row)
Helper method used by MoveCursor to determine relative line position.
std::string m_prompt_ansi_prefix
bool IsEmacs()
Returns true if the underlying EditLine session's keybindings are Emacs-based, or false if they are V...
CompleteCallbackType m_completion_callback
size_t GetPromptWidth()
Determines the width of the prompt in characters.
unsigned char PreviousHistoryCommand(int ch)
History navigation command used when Alt + up arrow is pressed in multi-line mode.
const char * m_fix_indentation_callback_chars
std::string m_editor_name
uint32_t GetCurrentLine()
Returns the index of the line currently being edited.
void DisplayInput(int firstIndex=0)
Clear from cursor position to bottom of screen and print input lines including prompts,...
int GetCharacter(EditLineGetCharType *c)
Character reading implementation for EditLine that supports our multi-line editing trickery.
int m_revert_cursor_index
void TerminalSizeChanged()
Call when the terminal size changes.
volatile std::sig_atomic_t m_terminal_size_has_changed
void SetEditLinePromptCallback(EditlinePromptCallbackType callbackFn)
EditlineHistorySP m_history_sp
static Editline * InstanceFor(::EditLine *editline)
Uses the user data storage of EditLine to retrieve an associated instance of Editline.
bool GetLine(std::string &line, bool &interrupted)
Prompts for and reads a single line of user input.
void SetCurrentLine(int line_index)
Sets the current line index between line edits to allow free movement between lines.
int CountRowsForLine(const EditLineStringType &content)
Counts the number of rows a given line of content will end up occupying, taking into account both the...
void ConfigureEditor(bool multiline)
Ensures that the current EditLine instance is properly configured for single or multi-line editing.
unsigned char NextLineCommand(int ch)
Line navigation command used when ^N or down arrow are pressed in multi-line mode.
void PrintAsync(Stream *stream, const char *s, size_t len)
std::vector< EditLineStringType > m_live_history_lines
void ApplyTerminalSizeChange()
void AddFunctionToEditLine(const EditLineCharType *command, const EditLineCharType *helptext, EditlineCommandCallbackType callbackFn)
std::vector< EditLineStringType > m_input_lines
bool CompleteCharacter(char ch, EditLineGetCharType &out)
bool Cancel()
Cancel this edit and obliterate all trace of it.
unsigned char DeleteNextCharCommand(int ch)
Delete command used when delete is pressed in multi-line mode.
std::string m_suggestion_ansi_prefix
SuggestionCallbackType m_suggestion_callback
unsigned char FixIndentationCommand(int ch)
Respond to normal character insertion by fixing line indentation.
unsigned char NextHistoryCommand(int ch)
History navigation command used when Alt + down arrow is pressed in multi-line mode.
void SetPrompt(const char *prompt)
Sets a string to be used as a prompt, or combined with a line number to form a prompt.
size_t GetTerminalHeight()
unsigned char BufferEndCommand(int ch)
Buffer end command used when Esc > is typed in multi-line emacs mode.
unsigned char TypedCharacter(int ch)
Command used when a character is typed.
unsigned char BreakLineCommand(int ch)
Line break command used when meta+return is pressed in multi-line mode.
FixIndentationCallbackType m_fix_indentation_callback
unsigned char ApplyAutosuggestCommand(int ch)
Apply autosuggestion part in gray as editline.
unsigned char TabCommand(int ch)
Context-sensitive tab insertion or code completion command used when the tab key is typed.
Editline(const char *editor_name, FILE *input_file, FILE *output_file, FILE *error_file, std::recursive_mutex &output_mutex)
std::recursive_mutex & m_output_mutex
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 ...
unsigned m_current_line_index
StringList GetInputAsStringList(int line_count=UINT32_MAX)
Convert the current input lines into a UTF8 StringList.
std::string PromptForIndex(int line_index)
Returns the complete prompt by combining the prompt or continuation prompt with line numbers as appro...
unsigned char RevertLineCommand(int ch)
Revert line command used when moving between lines.
bool Interrupt()
Interrupt the current edit as if ^C was pressed.
const char * GetPrompt()
Returns the prompt established by SetPrompt.
void SetBaseLineNumber(int line_number)
Sets the lowest line number for multi-line editing sessions.
bool GetLines(int first_line_number, StringList &lines, bool &interrupted)
Prompts for and reads a multi-line batch of user input.
std::string m_prompt_ansi_suffix
bool GetHomeDirectory(llvm::SmallVectorImpl< char > &path) const
Get the user home directory.
static FileSystem & Instance()
bool Success() const
Test for success condition.
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
size_t Write(const void *src, size_t src_len)
Output character bytes to the stream.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
virtual void Flush()=0
Flush the stream.
void AppendString(const std::string &s)
const char * GetStringAtIndex(size_t idx) const
std::string LongestCommonPrefix()
HistoryW * GetHistoryPtr()
void Enter(const EditLineCharType *line_cstr)
const char * GetHistoryFilePath()
std::string m_path
Path to the history file.
std::string m_prefix
The prefix name (usually the editline program name) to use when loading/saving history.
HistoryW * m_history
The history object.
EditlineHistory(const std::string &prefix, uint32_t size, bool unique_entries)
static EditlineHistorySP GetHistory(const std::string &prefix)
HistEventW m_event
The history event needed to contain all history events.
std::stringstream EditLineStringStreamType
std::weak_ptr< EditlineHistory > EditlineHistoryWP
unsigned char(*)(::EditLine *editline, int ch) EditlineCommandCallbackType
const char *(*)(::EditLine *editline) EditlinePromptCallbackType
int(*)(::EditLine *editline, EditLineGetCharType *c) EditlineGetCharCallbackType
std::string EditLineStringType
HistoryOperation
Operation for the history.
std::shared_ptr< EditlineHistory > EditlineHistorySP
EditorStatus
Status used to decide when and how to start editing another line in multi-line sessions.
@ Complete
Editing complete, returns the complete set of edited lines.
CursorLocation
Established locations that can be easily moved among with MoveCursor.
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.
char GetQuoteChar() const