Skip to content

Commit 28467ce

Browse files
committed
Moving new ansi CSI helpers into AnsiTerminal.h
1 parent a2248f1 commit 28467ce

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

lldb/include/lldb/Utility/AnsiTerminal.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@
7272

7373
#define ANSI_ESC_START_LEN 2
7474

75+
// Cursor Position, set cursor to position [l, c] (default = [1, 1]).
76+
#define ANSI_CSI_CUP(...) ANSI_ESC_START #__VA_ARGS__ "H"
77+
// Reset cursor to position.
78+
#define ANSI_CSI_RESET_CURSOR ANSI_CSI_CUP()
79+
// Erase In Display.
80+
#define ANSI_CSI_ED(opt) ANSI_ESC_START #opt "J"
81+
// Erase complete viewport.
82+
#define ANSI_CSI_ERASE_VIEWPORT ANSI_CSI_ED(2)
83+
// Erase scrollback.
84+
#define ANSI_CSI_ERASE_SCROLLBACK ANSI_CSI_ED(3)
85+
7586
// OSC (Operating System Commands)
7687
// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
7788
#define OSC_ESCAPE_START "\033"

lldb/tools/lldb-dap/tool/lldb-dap.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "lldb/Host/MainLoopBase.h"
2222
#include "lldb/Host/MemoryMonitor.h"
2323
#include "lldb/Host/Socket.h"
24+
#include "lldb/Utility/AnsiTerminal.h"
2425
#include "lldb/Utility/Status.h"
2526
#include "lldb/Utility/UriParser.h"
2627
#include "lldb/lldb-forward.h"
@@ -122,15 +123,6 @@ class LLDBDAPOptTable : public llvm::opt::GenericOptTable {
122123
};
123124
} // anonymous namespace
124125

125-
#define ESCAPE "\x1b"
126-
#define CSI ESCAPE "["
127-
// Move the cursor to 0,0
128-
#define ANSI_CURSOR_HOME CSI "H"
129-
// Clear the screen buffer
130-
#define ANSI_ERASE_SCREEN CSI "2J"
131-
// Clear the scroll back buffer
132-
#define ANSI_ERASE_SCROLLBACK CSI "3J"
133-
134126
static void PrintHelp(LLDBDAPOptTable &table, llvm::StringRef tool_name) {
135127
std::string usage_str = tool_name.str() + " options";
136128
table.printHelp(llvm::outs(), usage_str.c_str(), "LLDB DAP", false);
@@ -274,7 +266,8 @@ static llvm::Error LaunchRunInTerminalTarget(llvm::opt::Arg &target_arg,
274266
} else if ((isatty(STDIN_FILENO) != 0) &&
275267
llvm::StringRef(getenv("TERM")).starts_with_insensitive("xterm")) {
276268
// Clear the screen.
277-
llvm::outs() << ANSI_CURSOR_HOME ANSI_ERASE_SCREEN ANSI_ERASE_SCROLLBACK;
269+
llvm::outs() << ANSI_CSI_RESET_CURSOR ANSI_CSI_ERASE_VIEWPORT
270+
ANSI_CSI_ERASE_SCROLLBACK;
278271
// VSCode will reuse the same terminal for the same debug configuration
279272
// between runs. Clear the input buffer prior to starting the new process so
280273
// prior input is not carried forward to the new debug session.

0 commit comments

Comments
 (0)