diff options
Diffstat (limited to 'lldb/source/Core/IOHandler.cpp')
| -rw-r--r-- | lldb/source/Core/IOHandler.cpp | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/lldb/source/Core/IOHandler.cpp b/lldb/source/Core/IOHandler.cpp index 49f39f2ce492..695c2481e353 100644 --- a/lldb/source/Core/IOHandler.cpp +++ b/lldb/source/Core/IOHandler.cpp @@ -14,9 +14,9 @@ #include <string> #include "lldb/Core/Debugger.h" -#include "lldb/Core/StreamFile.h" #include "lldb/Host/Config.h" #include "lldb/Host/File.h" +#include "lldb/Host/StreamFile.h" #include "lldb/Utility/AnsiTerminal.h" #include "lldb/Utility/Predicate.h" #include "lldb/Utility/Status.h" @@ -226,7 +226,7 @@ IOHandlerEditline::IOHandlerEditline( Debugger &debugger, IOHandler::Type type, const char *editline_name, // Used for saving history files llvm::StringRef prompt, llvm::StringRef continuation_prompt, - bool multi_line, bool color_prompts, uint32_t line_number_start, + bool multi_line, bool color, uint32_t line_number_start, IOHandlerDelegate &delegate) : IOHandlerEditline(debugger, type, FileSP(), // Inherit input from top input reader @@ -234,7 +234,7 @@ IOHandlerEditline::IOHandlerEditline( StreamFileSP(), // Inherit error from top input reader 0, // Flags editline_name, // Used for saving history files - prompt, continuation_prompt, multi_line, color_prompts, + prompt, continuation_prompt, multi_line, color, line_number_start, delegate) {} IOHandlerEditline::IOHandlerEditline( @@ -243,7 +243,7 @@ IOHandlerEditline::IOHandlerEditline( uint32_t flags, const char *editline_name, // Used for saving history files llvm::StringRef prompt, llvm::StringRef continuation_prompt, - bool multi_line, bool color_prompts, uint32_t line_number_start, + bool multi_line, bool color, uint32_t line_number_start, IOHandlerDelegate &delegate) : IOHandler(debugger, type, input_sp, output_sp, error_sp, flags), #if LLDB_ENABLE_LIBEDIT @@ -251,8 +251,8 @@ IOHandlerEditline::IOHandlerEditline( #endif m_delegate(delegate), m_prompt(), m_continuation_prompt(), m_current_lines_ptr(nullptr), m_base_line_number(line_number_start), - m_curr_line_idx(UINT32_MAX), m_multi_line(multi_line), - m_color_prompts(color_prompts), m_interrupt_exits(true) { + m_curr_line_idx(UINT32_MAX), m_multi_line(multi_line), m_color(color), + m_interrupt_exits(true) { SetPrompt(prompt); #if LLDB_ENABLE_LIBEDIT @@ -262,9 +262,9 @@ IOHandlerEditline::IOHandlerEditline( m_input_sp && m_input_sp->GetIsRealTerminal(); if (use_editline) { - m_editline_up = std::make_unique<Editline>( - editline_name, GetInputFILE(), GetOutputFILE(), GetErrorFILE(), - GetOutputMutex(), m_color_prompts); + m_editline_up = std::make_unique<Editline>(editline_name, GetInputFILE(), + GetOutputFILE(), GetErrorFILE(), + GetOutputMutex()); m_editline_up->SetIsInputCompleteCallback( [this](Editline *editline, StringList &lines) { return this->IsInputCompleteCallback(editline, lines); @@ -278,10 +278,12 @@ IOHandlerEditline::IOHandlerEditline( m_editline_up->SetSuggestionCallback([this](llvm::StringRef line) { return this->SuggestionCallback(line); }); - m_editline_up->SetSuggestionAnsiPrefix(ansi::FormatAnsiTerminalCodes( - debugger.GetAutosuggestionAnsiPrefix())); - m_editline_up->SetSuggestionAnsiSuffix(ansi::FormatAnsiTerminalCodes( - debugger.GetAutosuggestionAnsiSuffix())); + if (m_color) { + m_editline_up->SetSuggestionAnsiPrefix(ansi::FormatAnsiTerminalCodes( + debugger.GetAutosuggestionAnsiPrefix())); + m_editline_up->SetSuggestionAnsiSuffix(ansi::FormatAnsiTerminalCodes( + debugger.GetAutosuggestionAnsiSuffix())); + } } // See if the delegate supports fixing indentation const char *indent_chars = delegate.IOHandlerGetFixIndentationCharacters(); @@ -474,8 +476,15 @@ bool IOHandlerEditline::SetPrompt(llvm::StringRef prompt) { m_prompt = std::string(prompt); #if LLDB_ENABLE_LIBEDIT - if (m_editline_up) + if (m_editline_up) { m_editline_up->SetPrompt(m_prompt.empty() ? nullptr : m_prompt.c_str()); + if (m_color) { + m_editline_up->SetPromptAnsiPrefix( + ansi::FormatAnsiTerminalCodes(m_debugger.GetPromptAnsiPrefix())); + m_editline_up->SetPromptAnsiSuffix( + ansi::FormatAnsiTerminalCodes(m_debugger.GetPromptAnsiSuffix())); + } + } #endif return true; } @@ -508,6 +517,21 @@ uint32_t IOHandlerEditline::GetCurrentLineIndex() const { return m_curr_line_idx; } +StringList IOHandlerEditline::GetCurrentLines() const { +#if LLDB_ENABLE_LIBEDIT + if (m_editline_up) + return m_editline_up->GetInputAsStringList(); +#endif + // When libedit is not used, the current lines can be gotten from + // `m_current_lines_ptr`, which is updated whenever a new line is processed. + // This doesn't happen when libedit is used, in which case + // `m_current_lines_ptr` is only updated when the full input is terminated. + + if (m_current_lines_ptr) + return *m_current_lines_ptr; + return StringList(); +} + bool IOHandlerEditline::GetLines(StringList &lines, bool &interrupted) { m_current_lines_ptr = &lines; |
