PRE-MERGE #20059 Show terminal size overlay (COLSxROWS) during resize (#2833)

This commit is contained in:
Carlos Zamora
2026-05-13 14:24:50 -07:00
5 changed files with 73 additions and 0 deletions

View File

@@ -1580,6 +1580,17 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return _terminal->GetViewport().Height();
}
// Function Description:
// - Gets the width of the terminal in columns. This is just the
// width of the viewport.
// Return Value:
// - The width of the terminal in columns
int ControlCore::ViewWidth() const
{
const auto lock = _terminal->LockForReading();
return _terminal->GetViewport().Width();
}
// Function Description:
// - Gets the height of the terminal in lines of text. This includes the
// history AND the viewport.

View File

@@ -172,6 +172,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
int ScrollOffset();
int ViewHeight() const;
int ViewWidth() const;
int BufferHeight() const;
bool HasSelection() const;

View File

@@ -2456,6 +2456,46 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
_automationPeer.UpdateControlBounds();
}
// Show resize overlay with columns x rows
_ShowResizeOverlay();
}
// Method Description:
// - Shows a centered overlay with the current terminal dimensions (columns x rows).
// Used during window resize and font size changes. Skipped for disabled controls
// (e.g. the Settings preview terminal) to avoid visual noise.
void TermControl::_ShowResizeOverlay()
{
// Don't show the overlay in the Settings preview control
if (!IsEnabled())
{
return;
}
const auto coreImpl = winrt::get_self<ControlCore>(_core);
const auto cols = coreImpl->ViewWidth();
const auto rows = coreImpl->ViewHeight();
if (cols > 0 && rows > 0)
{
ResizeOverlayText().Text(fmt::format(FMT_COMPILE(L"{} \u00D7 {}"), cols, rows));
ResizeOverlay().Visibility(Visibility::Visible);
if (!_resizeOverlayTimer)
{
_resizeOverlayTimer.emplace();
_resizeOverlayTimer->Interval(std::chrono::milliseconds(750));
_resizeOverlayTimer->Tick([weakThis = get_weak()](auto&&, auto&&) {
if (auto self = weakThis.get())
{
self->ResizeOverlay().Visibility(Visibility::Collapsed);
self->_resizeOverlayTimer->Stop();
}
});
}
_resizeOverlayTimer->Start();
}
}
// Method Description:

View File

@@ -316,6 +316,9 @@ namespace winrt::Microsoft::Terminal::Control::implementation
winrt::hstring _restorePath;
bool _showMarksInScrollbar{ false };
std::optional<SafeDispatcherTimer> _resizeOverlayTimer;
void _ShowResizeOverlay();
bool _isBackgroundLight{ false };
bool _detached{ false };
til::CoordType _searchScrollOffset = 0;

View File

@@ -1365,6 +1365,24 @@
</Grid>
<!-- Resize overlay: shows columns x rows when terminal is resized -->
<Border x:Name="ResizeOverlay"
Padding="16,8,16,8"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="{ThemeResource SystemControlBackgroundAltHighBrush}"
BorderBrush="{ThemeResource SystemAccentColor}"
BorderThickness="1"
CornerRadius="{ThemeResource OverlayCornerRadius}"
IsHitTestVisible="False"
Visibility="Collapsed">
<TextBlock x:Name="ResizeOverlayText"
FontSize="18"
FontWeight="SemiBold"
Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}"
TextAlignment="Center" />
</Border>
<Grid x:Name="RendererFailedNotice"
HorizontalAlignment="Center"
VerticalAlignment="Center"