Skip to content
Draft
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
42 changes: 42 additions & 0 deletions Examples/UICatalog/UICatalogRunnable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,48 @@ View [] CreateLoggingMenuItems ()
Enabled = false, CommandView = navTraceCheckBox, HelpText = "Toggle Focus & TabBehavior tracing", Key = Key.K.WithCtrl
});

CheckBox configTraceCheckBox = new ()
{
Text = "Con_figuration",
Value = Trace.EnabledCategories.HasFlag (TraceCategory.Configuration) ? CheckState.Checked : CheckState.UnChecked,
CanFocus = false
};

configTraceCheckBox.ValueChanging += (_, e) =>
{
if (e.NewValue == CheckState.Checked)
{
Trace.EnabledCategories |= TraceCategory.Configuration;
}
else
{
Trace.EnabledCategories &= ~TraceCategory.Configuration;
}
};

menuItems.Add (new MenuItem { CommandView = configTraceCheckBox, HelpText = "Toggle Configuration management tracing" });

CheckBox drawTraceCheckBox = new ()
{
Text = "_Draw",
Value = Trace.EnabledCategories.HasFlag (TraceCategory.Draw) ? CheckState.Checked : CheckState.UnChecked,
CanFocus = false
};

drawTraceCheckBox.ValueChanging += (_, e) =>
{
if (e.NewValue == CheckState.Checked)
{
Trace.EnabledCategories |= TraceCategory.Draw;
}
else
{
Trace.EnabledCategories &= ~TraceCategory.Draw;
}
};

menuItems.Add (new MenuItem { CommandView = drawTraceCheckBox, HelpText = "Toggle Draw operation tracing" });

// add a separator
menuItems.Add (new Line ());

Expand Down
6 changes: 6 additions & 0 deletions Terminal.Gui/App/ApplicationImpl.Screen.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace Terminal.Gui.App;

using Trace = Terminal.Gui.Tracing.Trace;

internal partial class ApplicationImpl
{
/// <inheritdoc/>
Expand Down Expand Up @@ -48,6 +50,8 @@ private void RaiseScreenChangedEvent (Rectangle screen)
/// <inheritdoc/>
public void LayoutAndDraw (bool forceRedraw = false)
{
Trace.Draw ("ApplicationImpl", "Start", $"forceRedraw={forceRedraw}");

if (ClearScreenNextIteration)
{
forceRedraw = true;
Expand Down Expand Up @@ -94,5 +98,7 @@ public void LayoutAndDraw (bool forceRedraw = false)
// Cause the driver to flush any pending updates to the terminal
Driver?.Refresh ();
}

Trace.Draw ("ApplicationImpl", "End", $"neededLayout={neededLayout}, needsDraw={needsDraw}");
}
}
22 changes: 22 additions & 0 deletions Terminal.Gui/App/Tracing/Trace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,28 @@

#endregion

#region Draw Tracing

/// <summary>
/// Traces a draw operation.
/// </summary>
/// <param name="id">An identifying string for the trace (e.g., <see cref="View.ToIdentifyingString"/>).</param>

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Integration Tests (ubuntu-latest)

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Integration Tests (ubuntu-latest)

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Integration Tests (macos-latest)

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Integration Tests (macos-latest)

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Non-Parallel Unit Tests (ubuntu-latest)

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Non-Parallel Unit Tests (ubuntu-latest)

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Build All Configurations

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Build All Configurations

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Non-Parallel Unit Tests (macos-latest)

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Non-Parallel Unit Tests (macos-latest)

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Integration Tests (windows-latest)

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Integration Tests (windows-latest)

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Non-Parallel Unit Tests (windows-latest)

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Non-Parallel Unit Tests (windows-latest)

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Parallel Unit Tests (ubuntu-latest)

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Parallel Unit Tests (ubuntu-latest)

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Parallel Unit Tests (windows-latest)

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Parallel Unit Tests (windows-latest)

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Parallel Unit Tests (macos-latest)

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved

Check warning on line 294 in Terminal.Gui/App/Tracing/Trace.cs

View workflow job for this annotation

GitHub Actions / Parallel Unit Tests (macos-latest)

XML comment has cref attribute 'ToIdentifyingString' that could not be resolved
/// <param name="phase">The phase of the draw operation (e.g., "Start", "End", "Adornments", "SubViews", "Text", "Content").</param>
/// <param name="message">Optional additional context.</param>
/// <param name="method">Automatically captured caller method name.</param>
[Conditional ("DEBUG")]
public static void Draw (string? id, string phase, string? message = null, [CallerMemberName] string method = "")
{
if (!EnabledCategories.HasFlag (TraceCategory.Draw))
{
return;
}

Backend.Log (new TraceEntry (TraceCategory.Draw, id ?? string.Empty, phase, method, message, DateTime.UtcNow, null));
}

#endregion

#region Keyboard Tracing

/// <summary>
Expand Down
5 changes: 4 additions & 1 deletion Terminal.Gui/App/Tracing/TraceCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public enum TraceCategory
/// <summary>Configuration management traces (property discovery, source loading, property assignment).</summary>
Configuration = 32,

/// <summary>Draw operation traces (layout-and-draw, view draw phases, adornments, subviews).</summary>
Draw = 64,

/// <summary>All trace categories enabled.</summary>
All = Lifecycle | Command | Mouse | Keyboard | Navigation | Configuration
All = Lifecycle | Command | Mouse | Keyboard | Navigation | Configuration | Draw
}
11 changes: 11 additions & 0 deletions Terminal.Gui/ViewBase/View.Drawing.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using Terminal.Gui.Tracing;

namespace Terminal.Gui.ViewBase;

Expand Down Expand Up @@ -27,6 +28,7 @@ internal static void Draw (IEnumerable<View> views, bool force)
view.SetNeedsDraw ();
}

Trace.Draw (view.ToIdentifyingString (), "Draw", $"force={force}");
view.Draw (context);
}

Expand Down Expand Up @@ -83,6 +85,8 @@ public void Draw (DrawContext? context = null)
return;
}

Trace.Draw (this.ToIdentifyingString (), "Start", $"NeedsDraw={NeedsDraw}, SubViewNeedsDraw={SubViewNeedsDraw}");

Region? originalClip = GetClip ();

// TODO: This can be further optimized by checking NeedsDraw below and only
Expand All @@ -93,6 +97,7 @@ public void Draw (DrawContext? context = null)
// Draw the Border and Padding Adornments.
// Note: Margin with a Shadow is special-cased and drawn in a separate pass to support
// transparent shadows.
Trace.Draw (this.ToIdentifyingString (), "Adornments");
DoDrawAdornments (originalClip);
SetClip (originalClip);

Expand All @@ -114,16 +119,19 @@ public void Draw (DrawContext? context = null)
// Draw the SubViews first (order matters: SubViews, Text, Content)
if (SubViewNeedsDraw)
{
Trace.Draw (this.ToIdentifyingString (), "SubViews");
DoDrawSubViews (context);
}

// ------------------------------------
// Draw the text
Trace.Draw (this.ToIdentifyingString (), "Text");
SetAttributeForRole (Enabled ? VisualRole.Normal : VisualRole.Disabled);
DoDrawText (context);

// ------------------------------------
// Draw the content
Trace.Draw (this.ToIdentifyingString (), "Content");
DoDrawContent (context);

// ------------------------------------
Expand All @@ -132,6 +140,7 @@ public void Draw (DrawContext? context = null)
// because they may draw outside the viewport.
SetClip (originalClip);
originalClip = AddFrameToClip ();
Trace.Draw (this.ToIdentifyingString (), "LineCanvas");
DoRenderLineCanvas (context);

// ------------------------------------
Expand Down Expand Up @@ -179,6 +188,8 @@ public void Draw (DrawContext? context = null)
// But the context contains the region that was drawn by this view
DoDrawComplete (context);

Trace.Draw (this.ToIdentifyingString (), "End");

// When DoDrawComplete returns, Driver.Clip has been updated to exclude this view's area.
// The next view drawn (earlier in Z-order, typically a peer view or the SuperView) will see
// a clip with "holes" where this view (and any SubViews drawn before it) are located.
Expand Down
37 changes: 37 additions & 0 deletions Tests/UnitTestsParallelizable/Tracing/TraceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,43 @@ public void LoggingBackend_FormatsConfigurationCorrectly ()

#endregion

#region Draw Category Tests

// Copilot
[Fact]
public void TraceCategory_Draw_HasExpectedValue ()
{
Assert.Equal (64, (int)TraceCategory.Draw);
}

// Copilot
[Fact]
public void TraceCategory_All_IncludesDraw ()
{
Assert.True (TraceCategory.All.HasFlag (TraceCategory.Draw));
}

// Copilot
[Fact]
public void Draw_Category_CanBeEnabled ()
{
Trace.EnabledCategories = TraceCategory.None;

try
{
Trace.EnabledCategories = TraceCategory.Draw;

Assert.True (Trace.EnabledCategories.HasFlag (TraceCategory.Draw));
}
finally
{
Trace.EnabledCategories = TraceCategory.None;
Trace.Backend = new NullBackend ();
}
}

#endregion

#region Scenario Tests (merged from IssueScenarioTraceTests)

/// <summary>
Expand Down
Loading