Table of Contents

Class LogViewerControl

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

Displays log entries from an ILogService as a live, virtualized, filterable table. Composes a GridControl (table today; toolbar / detail in later tasks) internally; the table is fed by a SharpConsoleUI.Controls.LogTableDataSource so only visible rows are rendered. Auto-scroll (tail-follow) sticks to the newest row unless the user scrolls up. Thread-safe: log events may arrive from any thread (they are marshalled onto the UI thread by the data source).

public class LogViewerControl : BaseControl, IDOMPaintable, INotifyPropertyChanged, IInteractiveControl, IFocusableControl, IMouseAwareControl, IWindowControl, IDisposable, IContainer
Inheritance
LogViewerControl
Implements
Inherited Members
Extension Methods

Remarks

This control has no single themed colour surface (rows colour themselves by severity), so it does not implement IColorRoleableControl. The inner grid is wired into the layout DOM tree via LayoutNodeFactory, so the table's rows measure/arrange/paint through the real engine (not a hand-painted copy) — this is what fixes the previously-empty Log Stream window.

Constructors

LogViewerControl(ILogService)

Creates a new LogViewerControl bound to the specified log service.

public LogViewerControl(ILogService logService)

Parameters

logService ILogService

The log service to display entries from.

Properties

AutoScroll

Gets or sets whether to keep the newest log entry visible (tail-follow).

public bool AutoScroll { get; set; }

Property Value

bool

Remarks

This is sticky USER INTENT and is not changed by scrolling. It writes DOWN to the inner table's AutoScroll, which tracks the transient "currently pinned to the bottom" state and detaches itself when the user scrolls up. The table never writes back up, so this property always reads back what the caller set.

BackgroundColor

Gets or sets the background color for the container and its child controls.

public Color BackgroundColor { get; set; }

Property Value

Color

CanFocusWithMouse

Whether this control can receive focus via mouse clicks

public bool CanFocusWithMouse { get; }

Property Value

bool

CanReceiveFocus

Whether this control can receive focus

public bool CanReceiveFocus { get; }

Property Value

bool

Container

Gets or sets the parent container that hosts this control.

public override IContainer? Container { get; set; }

Property Value

IContainer

Remarks

This control is a tree-participating container: the inner grid's IContainer is set to this (mirrors NavigationView), so _grid.Container.GetConsoleWindowSystem resolves through this control's own Container. Setting it here (rather than in SharpConsoleUI.Controls.LogViewerControl.EnsureAttached()) keeps the wiring correct the moment this control is attached to its parent.

ContentWidth

Gets the minimum width needed to display the control's content, including margins. Returns null if width cannot be determined. This is calculated based on content (text length, child controls, etc.) and represents the natural/intrinsic size.

public override int? ContentWidth { get; }

Property Value

int?

Remarks

The grid resolves its own width against available space, so this returns null to let the layout engine decide (mirrors ContentWidth).

FilterCategory

Gets or sets the category the view filter restricts to; null shows all.

public string? FilterCategory { get; set; }

Property Value

string

FilterLevel

Gets or sets the minimum log level shown by the VIEW filter (does not discard entries).

public LogLevel FilterLevel { get; set; }

Property Value

LogLevel

ForegroundColor

Gets or sets the foreground (text) color for the container and its child controls.

public Color ForegroundColor { get; set; }

Property Value

Color

GetConsoleWindowSystem

Gets the console window system instance, or null if not attached to a window system.

public ConsoleWindowSystem? GetConsoleWindowSystem { get; }

Property Value

ConsoleWindowSystem

HasFocus

public bool HasFocus { get; }

Property Value

bool

IsEnabled

Gets or sets whether this control is enabled and can receive input.

public bool IsEnabled { get; set; }

Property Value

bool

IsPaused

Gets or sets whether tail-follow is frozen. Paused entries still buffer.

public bool IsPaused { get; set; }

Property Value

bool

ShowDetailPane

Gets or sets whether the detail pane is shown when a row is selected.

public bool ShowDetailPane { get; set; }

Property Value

bool

ShowToolbar

Gets or sets whether the toolbar is shown.

public bool ShowToolbar { get; set; }

Property Value

bool

Title

Gets or sets a title shown above the log table.

public string? Title { get; set; }

Property Value

string

WantsMouseEvents

Whether this control wants to receive mouse events

public bool WantsMouseEvents { get; }

Property Value

bool

Methods

GetLogicalContentSize()

Gets the logical size of the control's content without rendering.

public override Size GetLogicalContentSize()

Returns

Size

The size representing the content's natural dimensions.

GetVisibleHeightForControl(IWindowControl)

Gets the actual visible height for a control within the container viewport. Returns null if the control is not found or visibility cannot be determined.

public int? GetVisibleHeightForControl(IWindowControl control)

Parameters

control IWindowControl

The control to check

Returns

int?

The number of visible lines, or null if unknown

Invalidate(Invalidation, IWindowControl?)

Marks this container as needing the specified work on the next frame. The request propagates up the container chain and folds into the owning window's frame-intent accumulator.

public void Invalidate(Invalidation work, IWindowControl? callerControl = null)

Parameters

work Invalidation

The kind of work requested: Repaint (appearance-only, Measure skipped) or Relayout (full layout).

callerControl IWindowControl

The control that triggered the invalidation, if any (cycle guard).

MeasureDOM(LayoutConstraints)

Measures the control's desired size given the available constraints.

public override LayoutSize MeasureDOM(LayoutConstraints constraints)

Parameters

constraints LayoutConstraints

The layout constraints (min/max width/height).

Returns

LayoutSize

The desired size of the control.

Remarks

This control is a tree-participating container (see LayoutNodeFactory): the inner grid is built as its Fill child, so the engine drives measurement of the grid/table subtree via VerticalStackLayout. This node's own MeasureDOM is only reached when the tree has no children (defensive), so it just measures the grid directly.

OnDisposing()

Called during Dispose() before Container is set to null. Override to perform control-specific cleanup (null events, close portals, clear data, etc.).

protected override void OnDisposing()

PaintDOM(CharacterBuffer, LayoutRect, LayoutRect, Color, Color)

Paints the control's content directly to a CharacterBuffer.

public override void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutRect clipRect, Color defaultFg, Color defaultBg)

Parameters

buffer CharacterBuffer

The buffer to paint to.

bounds LayoutRect

The absolute bounds where the control should paint.

clipRect LayoutRect

The clipping rectangle (visible area).

defaultFg Color
defaultBg Color

Remarks

Records this control's bounds and ensures the data source is attached. The grid and table paint themselves through their own layout nodes (built by LayoutNodeFactory), so this paints nothing of the table itself.

ProcessKey(ConsoleKeyInfo)

Processes a keyboard input event.

public bool ProcessKey(ConsoleKeyInfo keyInfo)

Parameters

keyInfo ConsoleKeyInfo

Returns

bool

True if the key was handled by this control; otherwise, false.

ProcessMouseEvent(MouseEventArgs)

Processes a mouse event for this control

public bool ProcessMouseEvent(MouseEventArgs args)

Parameters

args MouseEventArgs

Mouse event arguments with control-relative coordinates

Returns

bool

True if the event was handled and should not propagate further

SelectEntry(int)

Programmatically selects a display row (shows its detail).

public void SelectEntry(int rowIndex)

Parameters

rowIndex int

The zero-based display-row index to select.

SetCaptureLevel(LogLevel)

Sets the log service capture level (what the app records going forward). This is the dropdown's action: it changes MinimumLevel, not just the view filter.

public void SetCaptureLevel(LogLevel level)

Parameters

level LogLevel

The minimum level the log service should record from now on.

Events

MouseClick

Occurs when the control is clicked.

public event EventHandler<MouseEventArgs>? MouseClick

Event Type

EventHandler<MouseEventArgs>

MouseDoubleClick

Occurs when the control is double-clicked.

public event EventHandler<MouseEventArgs>? MouseDoubleClick

Event Type

EventHandler<MouseEventArgs>

MouseEnter

Occurs when the mouse enters the control area.

public event EventHandler<MouseEventArgs>? MouseEnter

Event Type

EventHandler<MouseEventArgs>

MouseLeave

Occurs when the mouse leaves the control area.

public event EventHandler<MouseEventArgs>? MouseLeave

Event Type

EventHandler<MouseEventArgs>

MouseMove

Occurs when the mouse moves over the control.

public event EventHandler<MouseEventArgs>? MouseMove

Event Type

EventHandler<MouseEventArgs>

MouseRightClick

Occurs when the control is right-clicked.

public event EventHandler<MouseEventArgs>? MouseRightClick

Event Type

EventHandler<MouseEventArgs>