Skip to content

Commit 8f151f0

Browse files
committed
[lldb] Unify window resizing logic in command line driver
Unify the logic for window resizing in the command line driver. This was prompted by the Windows bot not knowing about the ws_col field.
1 parent f9c8c01 commit 8f151f0

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

lldb/tools/driver/Driver.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,8 @@ int Driver::MainLoop() {
446446
m_debugger.SetUseExternalEditor(m_option_data.m_use_external_editor);
447447
m_debugger.SetShowInlineDiagnostics(true);
448448

449-
struct winsize window_size;
450-
if ((isatty(STDIN_FILENO) != 0) &&
451-
::ioctl(STDIN_FILENO, TIOCGWINSZ, &window_size) == 0) {
452-
if (window_size.ws_col > 0)
453-
m_debugger.SetTerminalWidth(window_size.ws_col);
454-
if (window_size.ws_row > 0)
455-
m_debugger.SetTerminalHeight(window_size.ws_row);
456-
}
449+
// Set the terminal dimensions.
450+
UpdateWindowSize();
457451

458452
SBCommandInterpreter sb_interpreter = m_debugger.GetCommandInterpreter();
459453

@@ -629,21 +623,24 @@ int Driver::MainLoop() {
629623
return sb_interpreter.GetQuitStatus();
630624
}
631625

632-
void Driver::ResizeWindow(unsigned short col, unsigned short row) {
633-
GetDebugger().SetTerminalWidth(col);
634-
GetDebugger().SetTerminalHeight(row);
635-
}
636-
637-
void sigwinch_handler(int signo) {
626+
void Driver::UpdateWindowSize() {
638627
struct winsize window_size;
639628
if ((isatty(STDIN_FILENO) != 0) &&
640629
::ioctl(STDIN_FILENO, TIOCGWINSZ, &window_size) == 0) {
641-
if ((window_size.ws_col > 0) && g_driver != nullptr) {
642-
g_driver->ResizeWindow(window_size.ws_col, window_size.ws_row);
643-
}
630+
if (window_size.ws_col > 0)
631+
m_debugger.SetTerminalWidth(window_size.ws_col);
632+
#ifndef _WIN32
633+
if (window_size.ws_row > 0)
634+
m_debugger.SetTerminalHeight(window_size.ws_row);
635+
#endif
644636
}
645637
}
646638

639+
void sigwinch_handler(int signo) {
640+
if (g_driver != nullptr)
641+
g_driver->UpdateWindowSize();
642+
}
643+
647644
void sigint_handler(int signo) {
648645
#ifdef _WIN32 // Restore handler as it is not persistent on Windows
649646
signal(SIGINT, sigint_handler);

lldb/tools/driver/Driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class Driver : public lldb::SBBroadcaster {
9292

9393
lldb::SBDebugger &GetDebugger() { return m_debugger; }
9494

95-
void ResizeWindow(unsigned short col, unsigned short row);
95+
void UpdateWindowSize();
9696

9797
private:
9898
lldb::SBDebugger m_debugger;

0 commit comments

Comments
 (0)