Skip to content
ConsoleMonster
Class

KeyValueList

ConsoleMonster.Widgets

Namespace
ConsoleMonster.Widgets
Assembly
ConsoleMonster
Modifiers
sealed

Aligned key/value pairs: muted keys in a column sized to the longest key, values (markup) wrapping in the rest. Live operation set (Key, Text, optional State) adds or replaces a pair.

Inheritance

Usage

Explore 29 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

Accepted by parameters 14

Constructors

public KeyValueList(string widgetId = "keyvalue") #

Creates a key/value list.

Parameters

widgetId string = "keyvalue" optional
The live name (default keyvalue).

Methods

Add 3 overloads
public KeyValueList Add(string key, string value, StatusKind? status = null) #

Adds or replaces a pair.

Parameters

key string required
The key (plain text).
value string required
The value (markup).
status ConsoleMonster.Styling.StatusKind? = null optional
An optional status shown as a marker before the value.

Returns

KeyValueList This instance.
public KeyValueList Add(KeyValueItem item) #

Adds or replaces a pair made beforehand, keeping its presenter (a key already in the list is replaced in place).

Parameters

item ConsoleMonster.Widgets.KeyValueItem required
The pair.

Returns

KeyValueList This instance.
public KeyValueList Add(string key, double value) #

Adds a pair with a number formatted with thousands separators.

Parameters

key string required
The key.
value double required
The number.

Returns

KeyValueList This instance.
public override void Apply(LiveEvent liveEvent) #

Applies an event to the widget's state.

Parameters

liveEvent ConsoleMonster.Live.LiveEvent required
The event.
public KeyValueHandle Handle(ILiveDispatcher dispatcher) #

Returns a handle that updates this list through a dispatcher (a live session).

Parameters

dispatcher ConsoleMonster.Live.ILiveDispatcher required
The dispatcher.

Returns

KeyValueHandle The handle.
public override Size Measure(Constraints constraints, RenderContext context) #

Returns the size the widget wants within the constraints.

Parameters

constraints ConsoleMonster.Layout.Constraints required
The space offered.
context ConsoleMonster.Canvas.RenderContext required
Profile, theme and glyphs.

Returns

Size The desired size, never larger than the constraints.
public override void Render(Region region, RenderContext context) #

Renders into a region. The region may be smaller or larger than the measured size.

Parameters

region ConsoleMonster.Canvas.Region required
The target region.
context ConsoleMonster.Canvas.RenderContext required
Profile, theme and glyphs.
public KeyValueList Value(string key, object? value, ICellPresenter? presenter = null, IReadOnlyList<RoleRule>? rules = null) #

Adds or replaces a pair whose value is formatted by a presenter (sizes, durations, dates, statuses...).

Parameters

key string required
The key (plain text).
value object? required
The raw value.
presenter ConsoleMonster.Presenters.ICellPresenter? = null optional
The presenter, or null for automatic.
rules System.Collections.Generic.IReadOnlyList<ConsoleMonster.Presenters.RoleRule>? = null optional
Tone rules, or null.

Returns

KeyValueList This instance.

Properties

public IReadOnlyList<KeyValueItem> Items { get; } #

The pairs in order.

public int Gap { get; set; } #

Cells between the key column and the values (default 2).

public int Columns { get; set; } #

Preferred number of pairs per row; narrow layouts reduce the count automatically.

public ThemeToken KeyRole { get; set; } #

Theme colour for keys.

public double MaxKeyFraction { get; set; } #

Preferred key fraction when the natural label and value widths cannot both fit (default 0.4).

public ColumnFormat NumberColumn { get; set; } #

Layout of the leading number of each value (234 / 332, 8.4 rules/s, ~12s): when every value starts with a number, the numbers share a column, right-aligned by default, so they line up under each other. A list that mixes in text (a host name, an OS) keeps every value left-aligned as written, so "3 days" under a name is not pushed right. Set the alignment to HorizontalAlignment.Left to always print values as written.

public PresentationOptions Presentation { get; set; } #

Culture, clock and time zone for values added with KeyValueList.Value.

Extension Methods

public static KeyValueList Columns(KeyValueList keyValueList, int value) #

Sets KeyValueList.Columns: Preferred number of pairs per row; narrow layouts reduce the count automatically.

Parameters

keyValueList ConsoleMonster.Widgets.KeyValueList required
The instance.
value int required
The value.

Returns

KeyValueList The same instance.

Examples

// C# initializer or property                                           // C# fluent
new global::ConsoleMonster.Widgets.KeyValueList { Columns = value };    Ui.KeyValue().Columns(value);
public static KeyValueList Gap(KeyValueList keyValueList, int value) #

Sets KeyValueList.Gap: Cells between the key column and the values (default 2).

Parameters

keyValueList ConsoleMonster.Widgets.KeyValueList required
The instance.
value int required
The value.

Returns

KeyValueList The same instance.

Examples

// C# initializer or property                                       // C# fluent
new global::ConsoleMonster.Widgets.KeyValueList { Gap = value };    Ui.KeyValue().Gap(value);
public static KeyValueList KeyRole(KeyValueList keyValueList, ThemeToken value) #

Sets KeyValueList.KeyRole: Theme colour for keys.

Parameters

keyValueList ConsoleMonster.Widgets.KeyValueList required
The instance.
value ConsoleMonster.Styling.ThemeToken required
The value.

Returns

KeyValueList The same instance.

Examples

// C# initializer or property                                           // C# fluent
new global::ConsoleMonster.Widgets.KeyValueList { KeyRole = value };    Ui.KeyValue().KeyRole(value);
public static KeyValueList MaxKeyFraction(KeyValueList keyValueList, double value) #

Sets KeyValueList.MaxKeyFraction: Preferred key fraction when the natural label and value widths cannot both fit (default 0.4).

Parameters

keyValueList ConsoleMonster.Widgets.KeyValueList required
The instance.
value double required
The value.

Returns

KeyValueList The same instance.

Examples

// C# initializer or property                                                  // C# fluent
new global::ConsoleMonster.Widgets.KeyValueList { MaxKeyFraction = value };    Ui.KeyValue().MaxKeyFraction(value);
NumberColumn 2 overloads
public static KeyValueList NumberColumn(KeyValueList keyValueList, ColumnFormat value) #

Sets KeyValueList.NumberColumn: Layout of the leading number of each value (234 / 332, 8.4 rules/s, ~12s): when every value starts with a number, the numbers share a column, right-aligned by default, so they line up under each other. A list that mixes in text (a host name, an OS) keeps every value left-aligned as written, so "3 days" under a name is not pushed right. Set the alignment to HorizontalAlignment.Left to always print values as written.

Parameters

keyValueList ConsoleMonster.Widgets.KeyValueList required
The instance.
value ConsoleMonster.Layout.ColumnFormat required
The value.

Returns

KeyValueList The same instance.

Examples

// C# initializer or property                                                // C# fluent
new global::ConsoleMonster.Widgets.KeyValueList { NumberColumn = value };    Ui.KeyValue().NumberColumn(value);
public static KeyValueList NumberColumn(KeyValueList keyValueList, Action<ColumnFormat> configure) #

Configures KeyValueList.NumberColumn in place: Layout of the leading number of each value (234 / 332, 8.4 rules/s, ~12s): when every value starts with a number, the numbers share a column, right-aligned by default, so they line up under each other. A list that mixes in text (a host name, an OS) keeps every value left-aligned as written, so "3 days" under a name is not pushed right. Set the alignment to HorizontalAlignment.Left to always print values as written.

Parameters

keyValueList ConsoleMonster.Widgets.KeyValueList required
The instance.
configure System.Action<ConsoleMonster.Layout.ColumnFormat> required
Configures the value.

Returns

KeyValueList The same instance.
Presentation 2 overloads
public static KeyValueList Presentation(KeyValueList keyValueList, PresentationOptions value) #

Sets KeyValueList.Presentation: Culture, clock and time zone for values added with KeyValueList.Value.

Parameters

keyValueList ConsoleMonster.Widgets.KeyValueList required
The instance.
value ConsoleMonster.Presenters.PresentationOptions required
The value.

Returns

KeyValueList The same instance.

Examples

// C# initializer or property                                                // C# fluent
new global::ConsoleMonster.Widgets.KeyValueList { Presentation = value };    Ui.KeyValue().Presentation(value);
public static KeyValueList Presentation(KeyValueList keyValueList, Action<PresentationOptions> configure) #

Configures KeyValueList.Presentation in place (creating it when not set): Culture, clock and time zone for values added with KeyValueList.Value.

Parameters

keyValueList ConsoleMonster.Widgets.KeyValueList required
The instance.
configure System.Action<ConsoleMonster.Presenters.PresentationOptions> required
Configures the value.

Returns

KeyValueList The same instance.