@@ -48,20 +48,21 @@ public static function render(PdoDb $db, Layout $layout, int $paneIndex, bool $a
4848 $ queries = MonitorManager::getActiveQueries ($ db );
4949 }
5050
51- // Clear content area first (before border to avoid clearing border)
52- for ($ i = 0 ; $ i < $ content ['height ' ]; $ i ++) {
53- Terminal::moveTo ($ content ['row ' ] + $ i , $ content ['col ' ]);
54- Terminal::clearLine ();
55- }
56-
57- // Render border after clearing content
51+ // Render border first (before clearing content to avoid clearing border)
5852 if (!$ fullscreen ) {
5953 $ layout ->renderBorder ($ paneIndex , 'Active Queries ' , $ active );
6054 }
6155
6256 if (empty ($ queries )) {
57+ // Clear only first line and show message
6358 Terminal::moveTo ($ content ['row ' ], $ content ['col ' ]);
59+ Terminal::clearLine ();
6460 echo 'No active queries ' ;
61+ // Clear remaining lines
62+ for ($ i = 1 ; $ i < $ content ['height ' ]; $ i ++) {
63+ Terminal::moveTo ($ content ['row ' ] + $ i , $ content ['col ' ]);
64+ Terminal::clearLine ();
65+ }
6566 return ;
6667 }
6768
@@ -92,6 +93,7 @@ public static function render(PdoDb $db, Layout $layout, int $paneIndex, bool $a
9293 // Display queries (with scrolling)
9394 $ startIdx = $ scrollOffset ;
9495 $ endIdx = min ($ startIdx + $ visibleHeight , count ($ queries ));
96+ $ lastDisplayRow = $ content ['row ' ]; // Track last row that was actually displayed
9597
9698 for ($ i = $ startIdx ; $ i < $ endIdx ; $ i ++) {
9799 $ query = $ queries [$ i ];
@@ -112,6 +114,7 @@ public static function render(PdoDb $db, Layout $layout, int $paneIndex, bool $a
112114 }
113115
114116 Terminal::moveTo ($ displayRow , $ content ['col ' ]);
117+ Terminal::clearLine (); // Clear line before rendering to avoid artifacts
115118
116119 $ isSelected = $ active && $ selectedIndex === $ i ;
117120 if ($ isSelected && Terminal::supportsColors ()) {
@@ -141,11 +144,38 @@ public static function render(PdoDb $db, Layout $layout, int $paneIndex, bool $a
141144 }
142145 echo $ rowText ;
143146 Terminal::reset ();
147+
148+ $ lastDisplayRow = $ displayRow ; // Update last displayed row
149+ }
150+
151+ // Clear remaining rows after last displayed query (to remove old content)
152+ // In fullscreen, footer is at $rows, so clear up to $rows - 1
153+ // In normal mode, clear up to scroll indicator row
154+ if ($ fullscreen ) {
155+ [$ totalRows ] = Terminal::getSize ();
156+ $ maxRow = $ totalRows - 1 ; // Footer is at $totalRows
157+ } else {
158+ $ maxRow = $ content ['row ' ] + $ content ['height ' ] - 1 ; // Scroll indicator row
159+ }
160+
161+ for ($ row = $ lastDisplayRow + 1 ; $ row < $ maxRow ; $ row ++) {
162+ Terminal::moveTo ($ row , $ content ['col ' ]);
163+ Terminal::clearLine ();
144164 }
145165
146166 // Show scroll indicator
167+ // In fullscreen, footer is at $rows, so scroll indicator is at $rows - 1
168+ // In normal mode, scroll indicator is at content['row'] + content['height'] - 1
169+ if ($ fullscreen ) {
170+ [$ totalRows ] = Terminal::getSize ();
171+ $ scrollIndicatorRow = $ totalRows - 1 ;
172+ } else {
173+ $ scrollIndicatorRow = $ content ['row ' ] + $ content ['height ' ] - 1 ;
174+ }
175+
147176 if ($ scrollOffset > 0 || $ endIdx < count ($ queries )) {
148- Terminal::moveTo ($ content ['row ' ] + $ content ['height ' ] - 1 , $ content ['col ' ]);
177+ Terminal::moveTo ($ scrollIndicatorRow , $ content ['col ' ]);
178+ Terminal::clearLine (); // Clear before rendering indicator
149179 if (Terminal::supportsColors ()) {
150180 Terminal::color (Terminal::COLOR_YELLOW );
151181 }
@@ -161,6 +191,10 @@ public static function render(PdoDb $db, Layout $layout, int $paneIndex, bool $a
161191 }
162192 echo $ info ;
163193 Terminal::reset ();
194+ } else {
195+ // Clear scroll indicator row if no scrolling needed
196+ Terminal::moveTo ($ scrollIndicatorRow , $ content ['col ' ]);
197+ Terminal::clearLine ();
164198 }
165199 }
166200
0 commit comments