Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions Terminal.Gui/App/ApplicationImpl.Screen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,24 @@ public Rectangle Screen
// Resize the output buffer to match the inline region dimensions.
_screen = value;
(Driver as DriverImpl)?.ResizeOutputBuffer (value.Width, value.Height);

RaiseScreenChangedEvent (value);

return;
}
else

_screen = null;

if (Driver is null)
{
// Fullscreen: sync with Driver.Screen (resizes both terminal tracking and buffer).
_screen = null;
Driver?.SetScreenSize (value.Width, value.Height);
RaiseScreenChangedEvent (Screen);

return;
}

RaiseScreenChangedEvent (Screen);
// Fullscreen: sync with Driver.Screen (resizes both terminal tracking and buffer).
// Driver_SizeChanged will raise ScreenChanged and invalidate layout.
Driver.SetScreenSize (value.Width, value.Height);
}
}

Expand Down
5 changes: 5 additions & 0 deletions Terminal.Gui/App/IApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,11 @@ public interface IApplication : IDisposable
/// If the <see cref="IDriver"/> has not been initialized, this will return a default size of 2048x2048; useful
/// for unit tests.
/// </para>
/// <para>
/// In <see cref="AppModel.FullScreen"/> mode, setting this property delegates to
Comment thread
tig marked this conversation as resolved.
/// <see cref="IDriver.SetScreenSize(int,int)"/>. To simulate a terminal resize in tests, prefer calling
/// <see cref="IDriver.SetScreenSize(int,int)"/> directly.
/// </para>
/// </remarks>
Rectangle Screen { get; set; }

Expand Down
35 changes: 35 additions & 0 deletions Tests/UnitTestsParallelizable/Application/ScreenTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,41 @@ public void Screen_Property_Allows_Setting_With_Zero_Origin ()
Assert.Equal (new (0, 0, 100, 50), app.Screen);
}

// Copilot
[Fact]
public void Screen_Property_Setting_Before_Begin_Raises_ScreenChanged_Once ()
{
// Arrange
using IApplication app = Application.Create ();
app.Init (DriverRegistry.Names.ANSI);

int eventCount = 0;
Rectangle? newScreen = null;

EventHandler<EventArgs<Rectangle>> handler = (_, args) =>
{
eventCount++;
newScreen = args.Value;
};

app.ScreenChanged += handler;

try
{
// Act
app.Screen = new (0, 0, 100, 50);

// Assert
Assert.Equal (1, eventCount);
Assert.Equal (new (0, 0, 100, 50), newScreen);
Assert.Equal (new (0, 0, 100, 50), app.Screen);
}
finally
{
app.ScreenChanged -= handler;
}
}

[Fact]
public void Screen_Property_Setting_Raises_ScreenChanged_Event ()
{
Expand Down
Loading