From 2a3b47cdf6ca8634c49a6fd64952bd0c0ee465a6 Mon Sep 17 00:00:00 2001 From: tehishik Date: Wed, 1 May 2019 23:16:33 +0900 Subject: [PATCH 1/2] add highlighting when using Select-string --- src/MatchInfo.ps1 | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/MatchInfo.ps1 b/src/MatchInfo.ps1 index a3f1571..43040b3 100644 --- a/src/MatchInfo.ps1 +++ b/src/MatchInfo.ps1 @@ -29,6 +29,12 @@ function MatchInfo { Write-host ':' -foregroundcolor $global:PSColor.Match.Default.Color -noNewLine Write-host $match.LineNumber -foregroundcolor $global:PSColor.Match.LineNumber.Color -noNewLine Write-host ':' -foregroundcolor $global:PSColor.Match.Default.Color -noNewLine - Write-host $match.Line -foregroundcolor $global:PSColor.Match.Line.Color + $ParsedText = $match.Line -split $match.pattern + Write-host $ParsedText[0] -foregroundcolor $global:PSColor.Match.Line.Color -noNewLine + for ($i = 1; $i -lt $ParsedText.length; $i += 1) { + Write-host $match.matches[0].value -foregroundcolor $global:PSColor.Match.MatchedText.Color -noNewLine -BackgroundColor $global:PSColor.Match.Background.Color + Write-host $ParsedText[$i] -foregroundcolor $global:PSColor.Match.Line.Color -noNewLine + } + Write-Host if ($match.Context) {PrintContext $match.Context.DisplayPostContext $match.RelativePath($pwd) ($match.LineNumber + 1)} } \ No newline at end of file From f0421b8ec5e2d7a810823c18e055b2bf4b6d837f Mon Sep 17 00:00:00 2001 From: tehishik Date: Wed, 1 May 2019 23:22:06 +0900 Subject: [PATCH 2/2] add color definitions to highlight matched text --- src/PSColor.psm1 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/PSColor.psm1 b/src/PSColor.psm1 index aa7595c..38bcebd 100644 --- a/src/PSColor.psm1 +++ b/src/PSColor.psm1 @@ -25,10 +25,14 @@ $global:PSColor = @{ Stopped = @{ Color = 'DarkRed' } } Match = @{ - Default = @{ Color = 'White' } - Path = @{ Color = 'Cyan'} - LineNumber = @{ Color = 'Yellow' } - Line = @{ Color = 'White' } + Default = @{ Color = 'White' } + Path = @{ Color = 'Cyan'} + LineNumber = @{ Color = 'Yellow' } + Line = @{ Color = 'White' } + MatchedText = @{ Color = 'Cyan' } + BackGround = @{ Color = 'DarkRed' } + } + } NoMatch = @{ Default = @{ Color = 'White' }