Skip to content

Commit 47cf7aa

Browse files
author
James Brundage
committed
Adding formatter for sentences (re #242)
1 parent 50a781d commit 47cf7aa

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Write-FormatView -TypeName PipeScript.Sentence -Action {
2+
3+
Write-FormatViewExpression -ForegroundColor Verbose -Property Keyword -If { $_.Command }
4+
Write-FormatViewExpression -ForegroundColor Success -ScriptBlock { " <# $($_.Command) #> " } -If { $_.Command }
5+
6+
Write-FormatViewExpression -ScriptBlock { ' ' }
7+
Write-FormatViewExpression -ScriptBlock {
8+
@(foreach ($clause in $_.Clauses) {
9+
$wordNumber = -1
10+
foreach ($word in $clause.Words) {
11+
$wordNumber++
12+
if (-not $wordNumber) {
13+
Format-RichText -ForegroundColor Warning -InputObject "$word"
14+
} else {
15+
Format-RichText -InputObject "$word"
16+
}
17+
}
18+
}) -join ' '
19+
}
20+
21+
Write-FormatViewExpression -ForegroundColor Magenta -If { $_.Arguments -and -not $_.Clauses } -ScriptBlock {
22+
$_.Arguments -join ' '
23+
}
24+
}

0 commit comments

Comments
 (0)