We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ef79331 commit acb6387Copy full SHA for acb6387
source/private/TruncateString.ps1
@@ -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