28#ifndef LLDB_HOST_EDITLINE_H
29#define LLDB_HOST_EDITLINE_H
31#include "lldb/Host/Config.h"
39#if !defined(_WIN32) && !defined(__ANDROID__)
55#include "llvm/ADT/FunctionExtras.h"
58namespace line_editor {
61#if LLDB_EDITLINE_USE_WCHAR
77#if LLDB_EDITLINE_USE_WCHAR || defined(EL_CLIENTDATA) || LLDB_HAVE_EL_RFUNC_T
100 llvm::unique_function<std::optional<std::string>(llvm::StringRef)>;
148using namespace line_editor;
154 Editline(
const char *editor_name, FILE *input_file, FILE *output_file,
155 FILE *error_file, std::recursive_mutex &output_mutex);
165 llvm::ArrayRef<CompletionResult::Completion> results);
209 const char *indent_chars) {
231 bool GetLine(std::string &line,
bool &interrupted);
"lldb/Utility/ArgCompletionRequest.h"
Instances of Editline provide an abstraction over libedit's EditLine facility.
IsInputCompleteCallbackType m_is_input_complete_callback
EditorStatus m_editor_status
void SetSuggestionCallback(SuggestionCallbackType callback)
Register a callback for autosuggestion.
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 SetSuggestionAnsiSuffix(std::string suffix)
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)
void SetIsInputCompleteCallback(IsInputCompleteCallbackType callback)
Register a callback for testing whether multi-line input is complete.
bool m_needs_prompt_repaint
std::string m_current_prompt
static void DisplayCompletions(Editline &editline, llvm::ArrayRef< CompletionResult::Completion > results)
void SetAutoCompleteCallback(CompleteCallbackType callback)
Register a callback for the tab key.
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.
void SetPromptAnsiSuffix(std::string suffix)
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)
void SetPromptAnsiPrefix(std::string prefix)
std::vector< EditLineStringType > m_live_history_lines
void ApplyTerminalSizeChange()
void SetFixIndentationCallback(FixIndentationCallbackType callback, const char *indent_chars)
Register a callback for determining the appropriate indentation for a line when creating a newline.
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.
void SetSuggestionAnsiPrefix(std::string prefix)
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.
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
A stream class that can stream formatted output to a file.
std::stringstream EditLineStringStreamType
llvm::unique_function< void(CompletionRequest &)> CompleteCallbackType
unsigned char(*)(::EditLine *editline, int ch) EditlineCommandCallbackType
const char *(*)(::EditLine *editline) EditlinePromptCallbackType
llvm::unique_function< int(Editline *, StringList &, int)> FixIndentationCallbackType
llvm::unique_function< bool(Editline *, StringList &)> IsInputCompleteCallbackType
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.
@ Interrupted
Editing interrupted.
@ EndOfInput
End of input reported.
@ Complete
Editing complete, returns the complete set of edited lines.
@ Editing
The default state proceeds to edit the current line.
CursorLocation
Established locations that can be easily moved among with MoveCursor.
@ BlockEnd
The location immediately after the last character in a multi-line edit session.
@ BlockStart
The start of the first line in a multi-line edit session.
@ EditingCursor
The location of the cursor on the current line in a multi-line edit session.
@ EditingPrompt
The start of the current line in a multi-line edit session.
llvm::unique_function< std::optional< std::string >(llvm::StringRef)> SuggestionCallbackType
A class that represents a running process on the host machine.