-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
To enable colored output in output formats, I can write a Format.ps1xml file that uses ANSI color codes like so:
<?xml version="1.0" encoding="utf-8"?>
<Configuration>
<ViewDefinitions>
<!-- Resembles the git log output with format=medium (default) -->
<View>
<Name>Medium</Name>
<ViewSelectedBy>
<TypeName>PowerGit.CommitInfo</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<!-- Yellow -->
<Label>[33mSha</Label>
<ScriptBlock>"$($_.Sha)$([char]0x001b)[0m"</ScriptBlock>
</ListItem>
<ListItem>
<Label>Author</Label>
<PropertyName>Author</PropertyName>
</ListItem>
<ListItem>
<Label>Date</Label>
<ScriptBlock>"$($_.Author.When)"</ScriptBlock>
</ListItem>
<ListItem>
<Label>Message</Label>
<PropertyName>Message</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
</ViewDefinitions>
</Configuration>Note the [33m, which is ESC[33m, which is the ANSI code for yellow, and $([char]0x001b)[0m, which is ESC[0m, which is the ANSI reset code.
Together, this will color the whole line yellow:
just like in git log output:
HOWEVER this is actually not valid XML. Every good XML parser will rightfully complain:
See https://en.wikipedia.org/wiki/Valid_characters_in_XML#XML_1.0
Which means these format files cannot be statically checked, generated, codemodded, etc.
It is valid in XML 1.1: https://en.wikipedia.org/wiki/Valid_characters_in_XML#XML_1.1
But if I change the parsing instruction to
<?xml version="1.1" encoding="utf-8"?>PowerShell errors:
Import-Module : Errors occurred while loading the format data file:
/Users/felix/src/github.com/felixfbecker/PowerGit/PowerGit/Formats/PowerGit.CommitInfo.formats.ps1xml, Error in file /Users/felix/src/github.com/felixfbecker/PowerGit/PowerGit/Formats/PowerGit.CommitInfo.formats.ps1xml: Version number '1.1' is invalid. Line 1, position 16.
At /Users/felix/src/github.com/felixfbecker/PowerGit/PowerGit/Import-PowerGit.ps1:32 char:1
+ Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'PowerG ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Import-Module], RuntimeException
+ FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommandIt effectively already parses XML 1.1 fine though, it just complains about the version.


