|
28 | 28 | #define ANSI_TO_START_OF_ROW ESCAPE "[%u;1f" |
29 | 29 | #define ANSI_REVERSE_VIDEO ESCAPE "[7m" |
30 | 30 | #define ANSI_UP_ROWS ESCAPE "[%dA" |
| 31 | +#define ANSI_SET_COLUMN_N ESCAPE "[%uG" |
31 | 32 |
|
32 | 33 | using namespace lldb; |
33 | 34 | using namespace lldb_private; |
@@ -103,19 +104,35 @@ void Statusline::UpdateScrollWindow(ScrollWindowMode mode) { |
103 | 104 | (mode == DisableStatusline) ? m_terminal_height : m_terminal_height - 1; |
104 | 105 |
|
105 | 106 | LockedStreamFile locked_stream = stream_sp->Lock(); |
| 107 | + |
| 108 | + if (mode == EnableStatusline) { |
| 109 | + // Get the cursor position before we potentially change the cursor position. |
| 110 | + CursorPosition cursor_position = m_debugger.GetIOHandlerCursorPosition(); |
| 111 | + |
| 112 | + // Move everything on the screen up to make space for the statusline. This |
| 113 | + // is going to move the cursor to the start of the next line which we need |
| 114 | + // to undo. |
| 115 | + locked_stream << '\n'; |
| 116 | + |
| 117 | + // First move the cursor back up. We can't use ANSI_SAVE/RESTORE_CURSOR |
| 118 | + // here, because the old and new position differ if everything on the screen |
| 119 | + // moved up. |
| 120 | + locked_stream.Printf(ANSI_UP_ROWS, 1); |
| 121 | + |
| 122 | + // Finally move the cursor back to the correct column, if the IOHandler was |
| 123 | + // able to tell us where that was. |
| 124 | + if (cursor_position.cols) |
| 125 | + locked_stream.Printf(ANSI_SET_COLUMN_N, *cursor_position.cols); |
| 126 | + } |
| 127 | + |
| 128 | + // Adjust the scroll window. |
106 | 129 | locked_stream << ANSI_SAVE_CURSOR; |
107 | 130 | locked_stream.Printf(ANSI_SET_SCROLL_ROWS, scroll_height); |
108 | 131 | locked_stream << ANSI_RESTORE_CURSOR; |
109 | | - switch (mode) { |
110 | | - case EnableStatusline: |
111 | | - // Move everything on the screen up. |
112 | | - locked_stream.Printf(ANSI_UP_ROWS, 1); |
113 | | - locked_stream << '\n'; |
114 | | - break; |
115 | | - case DisableStatusline: |
| 132 | + |
| 133 | + if (mode == DisableStatusline) { |
116 | 134 | // Clear the screen below to hide the old statusline. |
117 | 135 | locked_stream << ANSI_CLEAR_BELOW; |
118 | | - break; |
119 | 136 | } |
120 | 137 | } |
121 | 138 |
|
|
0 commit comments