Skip to content

Commit b82b52e

Browse files
committed
fix: reduce flickering in ActiveQueriesPane fullscreen mode
- Remove full screen clear in renderFullscreen for PANE_QUERIES to prevent constant redraws - Clear only header line instead of entire screen - Improve line clearing logic in ActiveQueriesPane to clear only necessary rows - Fix lastDisplayRow calculation to update during loop iteration - Properly handle scroll indicator position in fullscreen mode - Clear remaining rows after last displayed query to remove old content
1 parent af3abb8 commit b82b52e

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

src/cli/ui/Dashboard.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,10 +1470,12 @@ protected function showConfirmation(string $message): bool
14701470
*/
14711471
protected function renderFullscreen(): void
14721472
{
1473-
Terminal::clear();
14741473
[$rows, $cols] = Terminal::getSize();
14751474

14761475
if ($this->fullscreenPane === Layout::PANE_QUERIES) {
1476+
// Don't clear entire screen for queries pane - only clear header and footer
1477+
// Content area is cleared by ActiveQueriesPane::render() to avoid flickering
1478+
14771479
// Calculate scroll offset for fullscreen
14781480
$queries = $this->cachedQueries;
14791481
// Header: row 1, Table header: row 2, Footer: row $rows
@@ -1501,8 +1503,9 @@ protected function renderFullscreen(): void
15011503
// If relativeIndex is in range [0, visibleHeight), keep current scrollOffset
15021504
}
15031505

1504-
// Render header
1506+
// Render header (clear only header line)
15051507
Terminal::moveTo(1, 1);
1508+
Terminal::clearLine();
15061509
if (Terminal::supportsColors()) {
15071510
Terminal::bold();
15081511
Terminal::color(Terminal::COLOR_CYAN);

src/cli/ui/panes/ActiveQueriesPane.php

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)