CodeView
ConsoleMonster.Widgets
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.
Returned or exposed by 20
- Method Ui.Code
- Method ConsoleView.BuildCode
- Extension method CodeView.FirstLine
- Extension method CodeView.IndentationGuides
- Extension method CodeView.LineNumbers
- Extension method CodeView.MaxLines
- Extension method CodeView.Structure
- Extension method CodeView.Title
- Extension method CodeView.Wrap
- Method CodeView.For
- Method CodeView.FromLines
- Method CodeView.HighlightLines
- Method CodeView.Paginate
- Method CodeViewFluent.FirstLine
- Method CodeViewFluent.IndentationGuides
- Method CodeViewFluent.LineNumbers
- Method CodeViewFluent.MaxLines
- Method CodeViewFluent.Structure
- Method CodeViewFluent.Title
- Method CodeViewFluent.Wrap
Accepted by parameters 14
- Extension method CodeView.FirstLine
- Extension method CodeView.IndentationGuides
- Extension method CodeView.LineNumbers
- Extension method CodeView.MaxLines
- Extension method CodeView.Structure
- Extension method CodeView.Title
- Extension method CodeView.Wrap
- Method CodeViewFluent.FirstLine
- Method CodeViewFluent.IndentationGuides
- Method CodeViewFluent.LineNumbers
- Method CodeViewFluent.MaxLines
- Method CodeViewFluent.Structure
- Method CodeViewFluent.Title
- Method CodeViewFluent.Wrap
Constructors
public CodeView(string text, ITextHighlighter? highlighter = null) #Creates a view.
Parameters
- text string
- The text.
- highlighter ConsoleMonster.Highlighting.ITextHighlighter? = null
- 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
- The text.
- language string?
- The language, "auto", "text", or null for auto.
- path string? = null
- The file it came from (for detection), or null.
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
- The original source.
- first int
- First source line.
- last int? = null
- Last source line, or null for the rest of the source.
- language string? = null
- Language or Auto.
- path string? = null
- Source path for language detection.
Returns
CodeViewpublic CodeView HighlightLines(int from, int to = 0) #Marks lines (by their numbers) as highlighted.
Parameters
- from int
- The first line.
- to int = 0
- The last line (default the same).
public CodeView HighlightLines(string range) #Marks lines given as text: a number ("10") or a range ("10-14", "10..14").
Parameters
- range string
- The line or range.
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
- The space offered.
- context ConsoleMonster.Canvas.RenderContext
- Profile, theme and glyphs.
public IReadOnlyList<CodeView> Paginate(int linesPerPage) #Splits the displayed source into slides, keeping the original line numbers and marked lines.
Parameters
- linesPerPage int
- 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
- The target region.
- context ConsoleMonster.Canvas.RenderContext
- 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
- The width.
- context ConsoleMonster.Canvas.RenderContext
- The render context.
Inherited Methods
Properties
public string? Title { get; set; } #A title (a file name) drawn on a panel around the code, or null for no panel.
public int FirstLine { get; set; } #The number of the first line (default 1), for excerpts.
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
- The instance.
- value int
- The value.
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
- The instance.
- value bool = true
- The value; true when omitted.
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
- The instance.
- value bool = true
- The value; true when omitted.
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
- The instance.
- value int
- The value.
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
- The instance.
- value ConsoleMonster.Widgets.CodeStructure?
- The value.
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
- The instance.
- value string?
- The value.
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
- The instance.
- value bool = true
- The value; true when omitted.
Examples
// C# initializer or property // C# fluent
codeView.Wrap = value; codeView.Wrap(value);