23
23
#define ANSI_SAVE_CURSOR ESCAPE " 7"
24
24
#define ANSI_RESTORE_CURSOR ESCAPE " 8"
25
25
#define ANSI_CLEAR_BELOW ESCAPE " [J"
26
- #define ANSI_CLEAR_LINE " \r\x1B [2K"
26
+ #define ANSI_CURSOR_DOWN ESCAPE " [B"
27
+ #define ANSI_CLEAR_LINE ESCAPE " [2K"
27
28
#define ANSI_SET_SCROLL_ROWS ESCAPE " [0;%ur"
28
29
#define ANSI_TO_START_OF_ROW ESCAPE " [%u;0f"
29
30
#define ANSI_UP_ROWS ESCAPE " [%dA"
30
31
31
32
using namespace lldb ;
32
33
using namespace lldb_private ;
33
34
34
- Statusline::Statusline (Debugger &debugger) : m_debugger(debugger) { Enable (); }
35
+ Statusline::Statusline (Debugger &debugger)
36
+ : m_debugger(debugger), m_terminal_width(m_debugger.GetTerminalWidth()),
37
+ m_terminal_height(m_debugger.GetTerminalHeight()) {
38
+ Enable ();
39
+ }
35
40
36
41
Statusline::~Statusline () { Disable (); }
37
42
38
43
void Statusline::TerminalSizeChanged () {
39
- m_terminal_size_has_changed = 1 ;
44
+ UpdateTerminalProperties () ;
40
45
41
46
// This definitely isn't signal safe, but the best we can do, until we
42
47
// have proper signal-catching thread.
43
48
Redraw (/* update=*/ false );
44
49
}
45
50
46
51
void Statusline::Enable () {
47
- UpdateTerminalProperties ();
48
-
49
52
// Reduce the scroll window to make space for the status bar below.
50
- UpdateScrollWindow (ScrollWindowShrink );
53
+ UpdateScrollWindow (EnableStatusline );
51
54
52
55
// Draw the statusline.
53
- Redraw ();
56
+ Redraw (/* update= */ true );
54
57
}
55
58
56
59
void Statusline::Disable () {
57
- UpdateTerminalProperties ();
58
-
59
60
// Extend the scroll window to cover the status bar.
60
- UpdateScrollWindow (ScrollWindowExtend );
61
+ UpdateScrollWindow (DisableStatusline );
61
62
}
62
63
63
64
void Statusline::Draw (std::string str) {
64
65
lldb::LockableStreamFileSP stream_sp = m_debugger.GetOutputStreamSP ();
65
66
if (!stream_sp)
66
67
return ;
67
68
68
- UpdateTerminalProperties ();
69
-
70
69
m_last_str = str;
71
70
72
71
str = ansi::TrimAndPad (str, m_terminal_width);
@@ -80,58 +79,37 @@ void Statusline::Draw(std::string str) {
80
79
locked_stream << ANSI_RESTORE_CURSOR;
81
80
}
82
81
83
- void Statusline::Reset () {
84
- lldb::LockableStreamFileSP stream_sp = m_debugger.GetOutputStreamSP ();
85
- if (!stream_sp)
86
- return ;
87
-
88
- LockedStreamFile locked_stream = stream_sp->Lock ();
89
- locked_stream << ANSI_SAVE_CURSOR;
90
- locked_stream.Printf (ANSI_TO_START_OF_ROW,
91
- static_cast <unsigned >(m_terminal_height));
92
- locked_stream << ANSI_CLEAR_LINE;
93
- locked_stream << ANSI_RESTORE_CURSOR;
94
- }
95
-
96
82
void Statusline::UpdateTerminalProperties () {
97
- if (m_terminal_size_has_changed == 0 )
98
- return ;
99
-
100
- // Clear the previous statusline using the previous dimensions.
101
- Reset ();
102
-
83
+ UpdateScrollWindow (DisableStatusline);
103
84
m_terminal_width = m_debugger.GetTerminalWidth ();
104
85
m_terminal_height = m_debugger.GetTerminalHeight ();
105
-
106
- // Set the scroll window based on the new terminal height.
107
- UpdateScrollWindow (ScrollWindowShrink);
108
-
109
- // Clear the flag.
110
- m_terminal_size_has_changed = 0 ;
86
+ UpdateScrollWindow (EnableStatusline);
111
87
}
112
88
113
89
void Statusline::UpdateScrollWindow (ScrollWindowMode mode) {
90
+ assert (m_terminal_width != 0 && m_terminal_height != 0 );
91
+
114
92
lldb::LockableStreamFileSP stream_sp = m_debugger.GetOutputStreamSP ();
115
93
if (!stream_sp)
116
94
return ;
117
95
118
96
const unsigned scroll_height =
119
- (mode == ScrollWindowExtend ) ? m_terminal_height : m_terminal_height - 1 ;
97
+ (mode == DisableStatusline ) ? m_terminal_height : m_terminal_height - 1 ;
120
98
121
99
LockedStreamFile locked_stream = stream_sp->Lock ();
122
100
locked_stream << ANSI_SAVE_CURSOR;
123
101
locked_stream.Printf (ANSI_SET_SCROLL_ROWS, scroll_height);
124
102
locked_stream << ANSI_RESTORE_CURSOR;
125
103
switch (mode) {
126
- case ScrollWindowExtend:
127
- // Clear the screen below to hide the old statusline.
128
- locked_stream << ANSI_CLEAR_BELOW;
129
- break ;
130
- case ScrollWindowShrink:
104
+ case EnableStatusline:
131
105
// Move everything on the screen up.
132
106
locked_stream.Printf (ANSI_UP_ROWS, 1 );
133
107
locked_stream << ' \n ' ;
134
108
break ;
109
+ case DisableStatusline:
110
+ // Clear the screen below to hide the old statusline.
111
+ locked_stream << ANSI_CLEAR_BELOW;
112
+ break ;
135
113
}
136
114
}
137
115
0 commit comments