1010#include " lldb/Core/Debugger.h"
1111#include " lldb/Core/FormatEntity.h"
1212#include " lldb/Host/StreamFile.h"
13- #include " lldb/Host/ThreadLauncher.h"
1413#include " lldb/Interpreter/CommandInterpreter.h"
1514#include " lldb/Symbol/SymbolContext.h"
1615#include " lldb/Target/StackFrame.h"
1716#include " lldb/Utility/AnsiTerminal.h"
18- #include " lldb/Utility/LLDBLog.h"
19- #include " lldb/Utility/Log.h"
2017#include " lldb/Utility/StreamString.h"
2118#include " llvm/ADT/StringRef.h"
2219#include " llvm/Support/Locale.h"
23- #include < algorithm>
24- #include < cstdint>
2520
2621#define ESCAPE " \x1b "
2722#define ANSI_NORMAL ESCAPE " [0m"
3227#define ANSI_SET_SCROLL_ROWS ESCAPE " [0;%ur"
3328#define ANSI_TO_START_OF_ROW ESCAPE " [%u;0f"
3429#define ANSI_UP_ROWS ESCAPE " [%dA"
35- #define ANSI_DOWN_ROWS ESCAPE " [%dB"
36- #define ANSI_FORWARD_COLS ESCAPE " \033 [%dC"
37- #define ANSI_BACKWARD_COLS ESCAPE " \033 [%dD"
3830
3931using namespace lldb ;
4032using namespace lldb_private ;
4133
42- static size_t ColumnWidth (llvm::StringRef str) {
43- std::string stripped = ansi::StripAnsiTerminalCodes (str);
44- return llvm::sys::locale::columnWidth (stripped);
45- }
46-
4734Statusline::Statusline (Debugger &debugger) : m_debugger(debugger) { Enable (); }
4835
4936Statusline::~Statusline () { Disable (); }
@@ -73,41 +60,6 @@ void Statusline::Disable() {
7360 UpdateScrollWindow (ScrollWindowExtend);
7461}
7562
76- std::string Statusline::TrimAndPad (std::string str, size_t max_width) {
77- size_t column_width = ColumnWidth (str);
78-
79- // Trim the string.
80- if (column_width > max_width) {
81- size_t min_width_idx = max_width;
82- size_t min_width = column_width;
83-
84- // Use a StringRef for more efficient slicing in the loop below.
85- llvm::StringRef str_ref = str;
86-
87- // Keep extending the string to find the minimum column width to make sure
88- // we include as many ANSI escape characters or Unicode code units as
89- // possible. This is far from the most efficient way to do this, but it's
90- // means our stripping code doesn't need to be ANSI and Unicode aware and
91- // should be relatively cold code path.
92- for (size_t i = column_width; i < str.length (); ++i) {
93- size_t stripped_width = ColumnWidth (str_ref.take_front (i));
94- if (stripped_width <= column_width) {
95- min_width = stripped_width;
96- min_width_idx = i;
97- }
98- }
99-
100- str = str.substr (0 , min_width_idx);
101- column_width = min_width;
102- }
103-
104- // Pad the string.
105- if (column_width < max_width)
106- str.append (max_width - column_width, ' ' );
107-
108- return str;
109- }
110-
11163void Statusline::Draw (std::string str) {
11264 lldb::LockableStreamFileSP stream_sp = m_debugger.GetOutputStreamSP ();
11365 if (!stream_sp)
@@ -117,7 +69,7 @@ void Statusline::Draw(std::string str) {
11769
11870 m_last_str = str;
11971
120- str = TrimAndPad (str, m_terminal_width);
72+ str = ansi:: TrimAndPad (str, m_terminal_width);
12173
12274 LockedStreamFile locked_stream = stream_sp->Lock ();
12375 locked_stream << ANSI_SAVE_CURSOR;
0 commit comments