Skip to content
ConsoleMonster

API Reference

Class

CodeView

Namespace ConsoleMonster.Widgets
Assembly ConsoleMonster
Implements
Modifiers sealed

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 22 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 10

Constructors

public CodeView(String text, ITextHighlighter? highlighter = null) #

Creates a view.

Parameters

text System.String requiredposition: 0
The text.
highlighter ConsoleMonster.Highlighting.ITextHighlighter? = null optionalposition: 1
The highlighter, or null for plain text.

Methods

public static CodeView For(String text, String? language, String? path = null) #
Returns: CodeView

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 System.String requiredposition: 0
The text.
language System.String? requiredposition: 1
The language, "auto", "text", or null for auto.
path System.String? = null optionalposition: 2
The file it came from (for detection), or null.

Returns

The view.

Exceptions

  • ArgumentException – The language is not registered.
HighlightLines 2 overloads
public CodeView HighlightLines(Int32 from, Int32 to = 0) #
Returns: CodeView

Marks lines (by their numbers) as highlighted.

Parameters

from System.Int32 requiredposition: 0
The first line.
to System.Int32 = 0 optionalposition: 1
The last line (default the same).

Returns

This view.

public CodeView HighlightLines(String range) #
Returns: CodeView

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

Parameters

range System.String requiredposition: 0
The line or range.

Returns

This view.

Exceptions

  • ArgumentException – The text is not a line number or a range.
public Size Measure(Constraints constraints, RenderContext context) #
Returns: Size

Returns the size the widget wants within the constraints.

Parameters

constraints ConsoleMonster.Layout.Constraints requiredposition: 0
The space offered.
context ConsoleMonster.Canvas.RenderContext requiredposition: 1
Profile, theme and glyphs.

Returns

The desired size, never larger than the constraints.

public Void Render(Region region, RenderContext context) #
Returns: Void

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

Parameters

region ConsoleMonster.Canvas.Region requiredposition: 0
The target region.
context ConsoleMonster.Canvas.RenderContext requiredposition: 1
Profile, theme and glyphs.
public List<StyledLine> Rows(Int32 width, RenderContext context) #
Returns: List<StyledLine>

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

Parameters

width System.Int32 requiredposition: 0
The width.
context ConsoleMonster.Canvas.RenderContext requiredposition: 1
The render context.

Returns

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 Boolean LineNumbers { get; set; } #

Shows line numbers.

public Int32 FirstLine { get; set; } #

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

public Boolean Wrap { get; set; } #

Wraps long lines instead of truncating them.

public Int32 MaxLines { get; set; } #

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

Extension Methods

public static CodeView WithFirstLine(CodeView codeView, Int32 value) #
Returns: CodeView

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

Parameters

codeView ConsoleMonster.Widgets.CodeView requiredposition: 0
The instance.
value System.Int32 requiredposition: 1
The value.

Returns

The same instance.

public static CodeView WithLineNumbers(CodeView codeView, Boolean value = true) #
Returns: CodeView

Sets CodeView.LineNumbers: Shows line numbers.

Parameters

codeView ConsoleMonster.Widgets.CodeView requiredposition: 0
The instance.
value System.Boolean = true optionalposition: 1
The value (default true).

Returns

The same instance.

public static CodeView WithMaxLines(CodeView codeView, Int32 value) #
Returns: CodeView

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

Parameters

codeView ConsoleMonster.Widgets.CodeView requiredposition: 0
The instance.
value System.Int32 requiredposition: 1
The value.

Returns

The same instance.

public static CodeView WithTitle(CodeView codeView, String? value) #
Returns: CodeView

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 requiredposition: 0
The instance.
value System.String? requiredposition: 1
The value.

Returns

The same instance.

public static CodeView WithWrap(CodeView codeView, Boolean value = true) #
Returns: CodeView

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

Parameters

codeView ConsoleMonster.Widgets.CodeView requiredposition: 0
The instance.
value System.Boolean = true optionalposition: 1
The value (default true).

Returns

The same instance.