Skip to content
ConsoleMonster
Cmdlet

Format-ConsoleCode

Module ConsoleMonster
Inputs
System.Object
Outputs
ConsoleMonster.Layout.IWidget

Shows source text with syntax highlighting, line numbers and highlighted lines.

Syntax

Format-ConsoleCode [-AsWidget] [-FirstLine <Int32>] [-Highlight <String[]>] [[-InputObject] <Object>] [-Language <String>] [-LineNumbers] [-MaxLines <Int32>] [-NoTitle] [-Title <String>] [-Width <Int32>] [-Wrap] [<CommonParameters>]
#
Parameter set: Text
Format-ConsoleCode [-AsWidget] [-FirstLine <Int32>] [-Highlight <String[]>] [-Language <String>] [-LineNumbers] [-MaxLines <Int32>] [-NoTitle] -Path <String> [-Title <String>] [-Width <Int32>] [-Wrap] [<CommonParameters>]
#
Parameter set: Path

Description

Shows source text with syntax highlighting, line numbers and highlighted lines.

Highlights JSON, XML/HTML, YAML, PowerShell, C#, SQL, INI/TOML, CSV/TSV, diffs, log lines and Markdown, or plain text with -Language Smart (numbers, booleans, GUIDs, IP addresses, URLs, paths, dates, DNs, quoted strings). -Language Auto (the default) picks the language from the file extension, then from the content, and falls back to plain text. Text comes from -Path or from pipeline strings (joined as lines). The text is always literal: markup is not read and control characters are dropped. -LineNumbers adds a gutter, -Highlight marks lines (10, '10-14'), long lines are truncated with an ellipsis or wrapped with -Wrap, and output stops after -MaxLines lines with "+n more lines". A file is shown on a panel titled with its name (-Title changes it, -NoTitle leaves the panel out). Redirected output is plain text.

Examples

Authored help example

EXAMPLE 1

Format-ConsoleCode -AsWidget

EXAMPLE 2

Format-ConsoleCode -Path 'C:\Path'

Parameters

-AsWidget SwitchParameter optional
Returns the view instead of writing it.
-FirstLine Int32 optional
The number of the first line (default 1), for excerpts.
-Highlight String[] optional
Lines to mark: numbers or ranges such as 10, '10-14'.
-InputObject Object optionalposition: 0pipeline: True (ByValue)sets: Text
Text to show (pipeline strings are joined as lines).
-Language String optional
The language: Auto (default), Json, Xml, Yaml, PowerShell, CSharp, Sql, Ini, Csv, Diff, Log, Markdown, Smart, Text, or a language registered from C#.
-LineNumbers SwitchParameter optional
Shows line numbers.
-MaxLines Int32 optional
The most lines shown (default 2000).
-NoTitle SwitchParameter optional
Leaves the panel out.
-Title String optional
The panel title (default the file name with -Path; none for pipeline text).
-Width Int32 optional
Lays the output out for this width instead of the terminal's.
-Wrap SwitchParameter optional
Wraps long lines instead of truncating them.
-Path String requiredaliases: FullNamesets: Path
A file to show.

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.