Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lldb/include/lldb/Utility/AnsiTerminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@

#define ANSI_ESC_START_LEN 2

// Cursor Position, set cursor to position [l, c] (default = [1, 1]).
#define ANSI_CSI_CUP(...) ANSI_ESC_START #__VA_ARGS__ "H"
// Reset cursor to position.
#define ANSI_CSI_RESET_CURSOR ANSI_CSI_CUP()
// Erase In Display.
#define ANSI_CSI_ED(opt) ANSI_ESC_START #opt "J"
// Erase complete viewport.
#define ANSI_CSI_ERASE_VIEWPORT ANSI_CSI_ED(2)
// Erase scrollback.
#define ANSI_CSI_ERASE_SCROLLBACK ANSI_CSI_ED(3)
Comment on lines +75 to +84
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll adopt ANSI_CSI_ERASE_VIEWPORT in the statusline which does this too.


// OSC (Operating System Commands)
// https://invisible-island.net/xterm/ctlseqs/ctlseqs.html
#define OSC_ESCAPE_START "\033"
Expand Down
11 changes: 11 additions & 0 deletions lldb/tools/lldb-dap/tool/lldb-dap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "lldb/Host/MainLoopBase.h"
#include "lldb/Host/MemoryMonitor.h"
#include "lldb/Host/Socket.h"
#include "lldb/Utility/AnsiTerminal.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/UriParser.h"
#include "lldb/lldb-forward.h"
Expand Down Expand Up @@ -74,6 +75,7 @@ typedef int socklen_t;
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <termios.h>
#include <unistd.h>
#endif

Expand Down Expand Up @@ -261,6 +263,15 @@ static llvm::Error LaunchRunInTerminalTarget(llvm::opt::Arg &target_arg,
files.push_back(files.back());
if (llvm::Error err = SetupIORedirection(files))
return err;
} else if ((isatty(STDIN_FILENO) != 0) &&
llvm::StringRef(getenv("TERM")).starts_with_insensitive("xterm")) {
// Clear the screen.
llvm::outs() << ANSI_CSI_RESET_CURSOR ANSI_CSI_ERASE_VIEWPORT
ANSI_CSI_ERASE_SCROLLBACK;
// VS Code will reuse the same terminal for the same debug configuration
// between runs. Clear the input buffer prior to starting the new process so
// prior input is not carried forward to the new debug session.
tcflush(STDIN_FILENO, TCIFLUSH);
}

RunInTerminalLauncherCommChannel comm_channel(comm_file);
Expand Down
Loading