Skip to content

TerminalSelection ​

Namespace: Hex1b

Assembly: Hex1b.dll

Tracks the current text selection state within a terminal buffer.

csharp
public sealed class TerminalSelection

Inheritance ​

Object → TerminalSelection

Constructors ​

TerminalSelection(BufferPosition) ​

Creates a new selection with the cursor at the specified position. No text is selected until is called.

Parameters:

csharp
public TerminalSelection(BufferPosition initialPosition)

Properties ​

Anchor ​

The position where the selection was started.

Returns: BufferPosition

csharp
public BufferPosition Anchor { get; }

Cursor ​

The current cursor position (the moving end of the selection).

Returns: BufferPosition

csharp
public BufferPosition Cursor { get; }

End ​

Gets the end (later) position of the selection.

Returns: BufferPosition

csharp
public BufferPosition End { get; }

IsSelecting ​

Whether a selection range is active (anchor has been set and cursor is moving). When false, only the cursor is positioned but no text is selected.

Returns: Boolean

csharp
public bool IsSelecting { get; }

Mode ​

The selection mode (character, line, or block).

Returns: SelectionMode

csharp
public SelectionMode Mode { get; }

Start ​

Gets the start (earlier) position of the selection.

Returns: BufferPosition

csharp
public BufferPosition Start { get; }

Methods ​

ClearSelection() ​

Clears the selection but keeps the cursor position.

csharp
public void ClearSelection()

ExtractText(Func<int, int, TerminalCell?>, int) ​

Extracts the selected text from a virtual buffer.

Parameters:

Returns: String

The selected text, or null if no selection is active.

csharp
public string? ExtractText(Func<int, int, TerminalCell?> getCell, int bufferWidth)

IsCellSelected(int, int) ​

Determines whether the specified cell position is within the current selection.

Parameters:

  • row (Int32): The virtual row index.
  • column (Int32): The column index.

Returns: Boolean

True if the cell is selected.

csharp
public bool IsCellSelected(int row, int column)

MoveCursor(BufferPosition) ​

Moves the cursor to the specified position. If selecting, extends the selection.

Parameters:

csharp
public void MoveCursor(BufferPosition position)

StartSelection(SelectionMode) ​

Begins a selection at the current cursor position.

Parameters:

csharp
public void StartSelection(SelectionMode mode = SelectionMode.Character)

ToggleMode(SelectionMode) ​

Toggles between selection modes. If the requested mode is already active, switches back to character mode.

Parameters:

csharp
public void ToggleMode(SelectionMode mode)

Remarks ​

The selection operates on a "virtual buffer" that unifies scrollback and screen rows. Scrollback rows are indexed 0..scrollbackCount-1, and screen rows are indexed scrollbackCount..scrollbackCount+screenHeight-1.

Released under the MIT License.