Skip to content
ConsoleMonster
Class

CodeView

ConsoleMonster.Widgets

Namespace
ConsoleMonster.Widgets
Assembly
ConsoleMonster
Implements
IWidget
Modifiers
sealed
Attributes
Fluent

Source text with syntax highlighting: an optional title (a file name) on a panel, line numbers, highlighted line ranges marked in the gutter, long lines wrapped or truncated with the tier's ellipsis, and a line cap with "+n more lines". The text is literal: markup is not interpreted and control characters are dropped.

Inheritance

  • object
  • CodeView

Usage

Explore 34 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 CodeView(string text, ITextHighlighter? highlighter = null) #

Creates a view.

Parameters

text string required
The text.
highlighter ConsoleMonster.Highlighting.ITextHighlighter? = null optional
The highlighter, or null for plain text.

Methods

public static CodeView For(string text, string? language, string? path = null) #

Creates a view for a language name or file extension ("json", "ps1"): "auto" (or null) detects the language from the path and the content, "text" or "plain" shows plain text.

Parameters

text string required
The text.
language string? required
The language, "auto", "text", or null for auto.
path string? = null optional
The file it came from (for detection), or null.

Returns

CodeView The view.

Exceptions

  • ArgumentException – The language is not registered.
public static CodeView FromLines(string text, int first, int? last = null, string? language = null, string? path = null) #

Creates an excerpt from an inclusive, one-based range of source lines.

Parameters

text string required
The original source.
first int required
First source line.
last int? = null optional
Last source line, or null for the rest of the source.
language string? = null optional
Language or Auto.
path string? = null optional
Source path for language detection.

Returns

CodeView
HighlightLines 2 overloads
public CodeView HighlightLines(int from, int to = 0) #

Marks lines (by their numbers) as highlighted.

Parameters

from int required
The first line.
to int = 0 optional
The last line (default the same).

Returns

CodeView This view.
public CodeView HighlightLines(string range) #

Marks lines given as text: a number ("10") or a range ("10-14", "10..14").

Parameters

range string required
The line or range.

Returns

CodeView This view.

Exceptions

  • ArgumentException – The text is not a line number or a range.
public 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 IReadOnlyList<CodeView> Paginate(int linesPerPage) #

Splits the displayed source into slides, keeping the original line numbers and marked lines.

Parameters

linesPerPage int required
Maximum source lines per page. A wrapped line may occupy several display rows.

Returns

IReadOnlyList<CodeView>
public 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 List<StyledLine> Rows(int width, RenderContext context) #

The display rows at a width: gutter and code, wrapped or truncated.

Parameters

width int required
The width.
context ConsoleMonster.Canvas.RenderContext required
The render context.

Returns

List<StyledLine> The rows.

Properties

public string Text { get; } #

The text.

public ITextHighlighter? Highlighter { get; } #

The highlighter, or null.

public string? Title { get; set; } #

A title (a file name) drawn on a panel around the code, or null for no panel.

public bool LineNumbers { get; set; } #

Shows line numbers.

public int FirstLine { get; set; } #

The number of the first line (default 1), for excerpts.

public bool Wrap { get; set; } #

Wraps long lines instead of truncating them.

public bool IndentationGuides { get; set; } #

Shows scope or indentation guides in the leading whitespace.

public CodeStructure? Structure { get; set; } #

Optional syntax ranges for the original source. Indentation provides a fallback.

public int MaxLines { get; set; } #

The most lines shown (default 2000); the rest are counted.

Extension Methods

public static CodeView FirstLine(CodeView codeView, int value) #

Sets CodeView.FirstLine: The number of the first line (default 1), for excerpts.

Parameters

codeView ConsoleMonster.Widgets.CodeView required
The instance.
value int required
The value.

Returns

CodeView The same instance.

Examples

// C# initializer or property    // C# fluent
codeView.FirstLine = value;      codeView.FirstLine(value);
public static CodeView IndentationGuides(CodeView codeView, bool value = true) #

Sets CodeView.IndentationGuides: Shows scope or indentation guides in the leading whitespace.

Parameters

codeView ConsoleMonster.Widgets.CodeView required
The instance.
value bool = true optional
The value; true when omitted.

Returns

CodeView The same instance.

Examples

// C# initializer or property          // C# fluent
codeView.IndentationGuides = value;    codeView.IndentationGuides(value);
public static CodeView LineNumbers(CodeView codeView, bool value = true) #

Sets CodeView.LineNumbers: Shows line numbers.

Parameters

codeView ConsoleMonster.Widgets.CodeView required
The instance.
value bool = true optional
The value; true when omitted.

Returns

CodeView The same instance.

Examples

// C# initializer or property    // C# fluent
codeView.LineNumbers = value;    codeView.LineNumbers(value);
public static CodeView MaxLines(CodeView codeView, int value) #

Sets CodeView.MaxLines: The most lines shown (default 2000); the rest are counted.

Parameters

codeView ConsoleMonster.Widgets.CodeView required
The instance.
value int required
The value.

Returns

CodeView The same instance.

Examples

// C# initializer or property    // C# fluent
codeView.MaxLines = value;       codeView.MaxLines(value);
public static CodeView Structure(CodeView codeView, CodeStructure? value) #

Sets CodeView.Structure: Optional syntax ranges for the original source. Indentation provides a fallback.

Parameters

codeView ConsoleMonster.Widgets.CodeView required
The instance.
value ConsoleMonster.Widgets.CodeStructure? required
The value.

Returns

CodeView The same instance.

Examples

// C# initializer or property    // C# fluent
codeView.Structure = value;      codeView.Structure(value);
public static CodeView Title(CodeView codeView, string? value) #

Sets CodeView.Title: A title (a file name) drawn on a panel around the code, or null for no panel.

Parameters

codeView ConsoleMonster.Widgets.CodeView required
The instance.
value string? required
The value.

Returns

CodeView The same instance.

Examples

// C# initializer or property    // C# fluent
codeView.Title = value;          codeView.Title(value);
public static CodeView Wrap(CodeView codeView, bool value = true) #

Sets CodeView.Wrap: Wraps long lines instead of truncating them.

Parameters

codeView ConsoleMonster.Widgets.CodeView required
The instance.
value bool = true optional
The value; true when omitted.

Returns

CodeView The same instance.

Examples

// C# initializer or property    // C# fluent
codeView.Wrap = value;           codeView.Wrap(value);