Skip to content

Commit acb6387

Browse files
committed
This is ConciseView
1 parent ef79331 commit acb6387

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

source/private/TruncateString.ps1

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
filter TruncateString {
2+
[CmdletBinding()]
3+
param(
4+
# The input string will be wrapped to a certain length, with optional padding on the front
5+
[Parameter(ValueFromPipeline)]
6+
[string]$InputObject,
7+
8+
[Parameter(Position = 0)]
9+
[Alias('Length')]
10+
[int]$Width = ($Host.UI.RawUI.BufferSize.Width)
11+
)
12+
# $wrappableChars = [char[]]" ,.?!:;-`n`r`t"
13+
# $maxLength = $width - $IndentPadding.Length -1
14+
$wrapper = [Regex]::new("((?:$AnsiPattern)*[^-=,.?!:;\s\r\n\t\\\/\|]+(?:$AnsiPattern)*)", "Compiled")
15+
16+
if ($InputObject.Length -le $Width) {
17+
return $InputObject
18+
}
19+
20+
($InputObject.Substring(0,$length) -split $wrapper,-2)[0]
21+
}

0 commit comments

Comments
 (0)