Skip to content

Commit c7a51c9

Browse files
sagarbhure-msftSagar Bhure
authored andcommitted
Show terminal size overlay (COLSxROWS) during resize (#2833)
Display a centered overlay showing columns x rows when the terminal control is resized. The overlay auto-hides after 750ms of inactivity. - Add ResizeOverlay Border element to TermControl.xaml - Add ViewWidth() to ControlCore (matches existing ViewHeight()) - Show overlay in _SwapChainSizeChanged using SafeDispatcherTimer - Use fmt::format for string formatting Closes #2833
1 parent c334f91 commit c7a51c9

File tree

5 files changed

+52
-0
lines changed

5 files changed

+52
-0
lines changed

src/cascadia/TerminalControl/ControlCore.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,17 @@ namespace winrt::Microsoft::Terminal::Control::implementation
15801580
return _terminal->GetViewport().Height();
15811581
}
15821582

1583+
// Function Description:
1584+
// - Gets the width of the terminal in columns. This is just the
1585+
// width of the viewport.
1586+
// Return Value:
1587+
// - The width of the terminal in columns
1588+
int ControlCore::ViewWidth() const
1589+
{
1590+
const auto lock = _terminal->LockForReading();
1591+
return _terminal->GetViewport().Width();
1592+
}
1593+
15831594
// Function Description:
15841595
// - Gets the height of the terminal in lines of text. This includes the
15851596
// history AND the viewport.

src/cascadia/TerminalControl/ControlCore.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
172172

173173
int ScrollOffset();
174174
int ViewHeight() const;
175+
int ViewWidth() const;
175176
int BufferHeight() const;
176177

177178
bool HasSelection() const;

src/cascadia/TerminalControl/TermControl.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,6 +2458,26 @@ namespace winrt::Microsoft::Terminal::Control::implementation
24582458
{
24592459
_automationPeer.UpdateControlBounds();
24602460
}
2461+
2462+
// Show resize overlay with COLSxROWS
2463+
const auto coreImpl = winrt::get_self<ControlCore>(_core);
2464+
const auto cols = coreImpl->ViewWidth();
2465+
const auto rows = coreImpl->ViewHeight();
2466+
if (cols > 0 && rows > 0)
2467+
{
2468+
ResizeOverlayText().Text(fmt::format(FMT_COMPILE(L"{} \u00D7 {}"), cols, rows));
2469+
ResizeOverlay().Visibility(Visibility::Visible);
2470+
2471+
_resizeOverlayTimer.Interval(std::chrono::milliseconds(750));
2472+
_resizeOverlayTimer.Tick([weakThis = get_weak()](auto&&, auto&&) {
2473+
if (auto self = weakThis.get())
2474+
{
2475+
self->ResizeOverlay().Visibility(Visibility::Collapsed);
2476+
self->_resizeOverlayTimer.Stop();
2477+
}
2478+
});
2479+
_resizeOverlayTimer.Start();
2480+
}
24612481
}
24622482

24632483
// Method Description:

src/cascadia/TerminalControl/TermControl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
316316
winrt::hstring _restorePath;
317317
bool _showMarksInScrollbar{ false };
318318

319+
SafeDispatcherTimer _resizeOverlayTimer;
320+
319321
bool _isBackgroundLight{ false };
320322
bool _detached{ false };
321323
til::CoordType _searchScrollOffset = 0;

src/cascadia/TerminalControl/TermControl.xaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,24 @@
13651365

13661366
</Grid>
13671367

1368+
<!-- Resize overlay: shows COLSxROWS when terminal is resized -->
1369+
<Border x:Name="ResizeOverlay"
1370+
HorizontalAlignment="Center"
1371+
VerticalAlignment="Center"
1372+
Padding="16,8,16,8"
1373+
Background="{ThemeResource SystemControlBackgroundAltHighBrush}"
1374+
BorderBrush="{ThemeResource SystemAccentColor}"
1375+
BorderThickness="1"
1376+
CornerRadius="{ThemeResource OverlayCornerRadius}"
1377+
IsHitTestVisible="False"
1378+
Visibility="Collapsed">
1379+
<TextBlock x:Name="ResizeOverlayText"
1380+
FontSize="18"
1381+
FontWeight="SemiBold"
1382+
Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}"
1383+
TextAlignment="Center" />
1384+
</Border>
1385+
13681386
<Grid x:Name="RendererFailedNotice"
13691387
HorizontalAlignment="Center"
13701388
VerticalAlignment="Center"

0 commit comments

Comments
 (0)