Class CommandPalette
- Namespace
- MiniTui
- Assembly
- MiniTui.dll
A searchable list of things to run (1.x spec §13). Typing filters the items with Match(string, string); ↑ ↓ PgUp PgDn Ctrl+Home Ctrl+End move the selection; Enter or a click runs the selected item; Esc or a click outside closes it. Show it with ShowPalette(CommandRegistry?), or with Show(Overlay) for items of your own.
public sealed class CommandPalette : Overlay
- Inheritance
-
CommandPalette
- Inherited Members
Constructors
CommandPalette(IReadOnlyList<PaletteItem>)
Create a palette over items. Show it with Show(Overlay).
public CommandPalette(IReadOnlyList<PaletteItem> items)
Parameters
itemsIReadOnlyList<PaletteItem>
Exceptions
- ArgumentException
itemscontains null.
Properties
CapturesText
True for text inputs: while this component is the innermost focused one, its ancestors' and the app's
single-character bindings (without Ctrl or Alt) are skipped, so typing q doesn't quit.
public override bool CapturesText { get; }
Property Value
CloseOnClickOutside
Whether a press of any mouse button outside the overlay closes it (1.x spec §7.6). The press goes nowhere else. False by default.
public override bool CloseOnClickOutside { get; }
Property Value
Framed
Whether the app draws the themed block around the overlay. When false, the app only clears the Placement(Rect) rect, and Render(Buffer, Rect, RenderContext) gets all of it to draw, border included. True by default.
public override bool Framed { get; }
Property Value
MaxRows
At most this many item rows are shown; more scroll. Default 12.
public int MaxRows { get; init; }
Property Value
Placeholder
Shown muted in the empty filter line. Default "Type to search".
public string Placeholder { get; init; }
Property Value
Result
The chosen item's index in the items, or null when the palette closed without a choice.
public Task<int?> Result { get; }
Property Value
Title
The title in the overlay's border.
public override string? Title { get; }
Property Value
Methods
HandleKey(ConsoleKeyInfo)
Handle a key before Keys. Return true if handled.
public override bool HandleKey(ConsoleKeyInfo key)
Parameters
keyConsoleKeyInfo
Returns
HandleMouse(MouseEvent)
Handle a mouse event inside this component's Area (1.x spec §4.7). Return true if handled; otherwise the event goes on to the component's parent, and is dropped if nothing handles it. A press has already focused the component when this runs.
public override bool HandleMouse(MouseEvent mouse)
Parameters
mouseMouseEvent
Returns
HandlePaste(string)
Handle pasted text, such as with Paste(string). Return true if handled; otherwise the paste goes on to the component's parent, and is dropped if nothing handles it.
public override bool HandlePaste(string text)
Parameters
textstring
Returns
ItemsFor(App, CommandRegistry?)
The items for the app's current state (1.x spec §13.4, §15.6): the key bindings in scope, innermost first, as
the help overlay lists them (not the binding whose handler is running, which is the one opening the palette),
then the menu bar's items with a Run, with their paths, then each command of commands and its subcommands, in add order. A command with a usage
opens a CommandLineOverlay with its name typed; one without runs at once.
public static IReadOnlyList<PaletteItem> ItemsFor(App app, CommandRegistry? commands = null)
Parameters
appAppcommandsCommandRegistry
Returns
OnMount()
Called when the component is mounted, before its children.
protected override void OnMount()
OnUnmount()
Called when the component unmounts, after its children and after Lifetime is cancelled.
protected override void OnUnmount()
Placement(Rect)
Centered, near the top, max(40, 60%) of the width, and as tall as the filter line, a divider and the
matches (up to MaxRows).
public override Rect Placement(Rect screen)
Parameters
screenRect
Returns
Render(Buffer, Rect, RenderContext)
Draw the component. Called every frame its parent renders it.
public override void Render(Buffer buf, Rect area, RenderContext ctx)
Parameters
bufBufferareaRectctxRenderContext