Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 7 additions & 0 deletions Terminal.Gui/App/IApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,13 @@ 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)"/> when the Driver has been initialized. If the Driver
/// is <see langword="null"/> (before <see cref="IApplication.Init(string?)"/> or after disposal),
/// the setter raises <see cref="ScreenChanged"/> with the current getter value but does not call the Driver.
/// To simulate a terminal resize in tests, prefer calling <see cref="IDriver.SetScreenSize(int,int)"/> directly.
/// </para>
/// </remarks>
Rectangle Screen { get; set; }

Expand Down
73 changes: 73 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 Expand Up @@ -479,6 +514,44 @@ public void Screen_Property_Thread_Safe_Access ()

#endregion Screen Property Tests

// Copilot
[Fact]
public void Screen_Setter_Before_Driver_Init_Fires_ScreenChanged_Without_Delegating_To_Driver ()
{
// Arrange — Create app but do NOT call Init, so Driver remains null.
using IApplication app = Application.Create ();

// Verify precondition: Driver is null before Init.
Assert.Null (app.Driver);

var eventCount = 0;
Rectangle? reported = null;

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

app.ScreenChanged += handler;

try
{
// Act — setting Screen with no Driver should still raise ScreenChanged.
app.Screen = new (0, 0, 120, 40);

// Assert — event fired exactly once with the default getter value (2048x2048)
// because _screen is reset to null in fullscreen mode and Driver is null.
Assert.Equal (1, eventCount);
Assert.NotNull (reported);
Assert.Equal (new (0, 0, 2048, 2048), reported.Value);
}
finally
{
app.ScreenChanged -= handler;
}
}

#region Inline Mode Screen Tests

// Copilot
Expand Down
Loading