-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Posh.Host.UI.Box.MiddleWall ( Fixes #371 )
- Loading branch information
James Brundage
committed
Feb 25, 2024
1 parent
bed1863
commit aa1b1b0
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<# | ||
.SYNOPSIS | ||
Gets a box's middle wall character | ||
.DESCRIPTION | ||
Gets the middle wall in a box. | ||
.NOTES | ||
If the box only has one line, and it is less than 5 characters, the second character will be considered the top wall. | ||
If it only has one character, it will be considered the middle wall. | ||
Otherwise, the character directly left of the middle will be considered the middle wall. | ||
#> | ||
$theseLines = @($this -split '[\r\n]+' -ne '') | ||
|
||
if (-not $theseLines) { return } | ||
$theLine = $theseLines[[Math]::Floor($theseLines.Length / 2)] | ||
if ($theLine.Length -lt 5) { | ||
# If there is only one line, it is between two and five characters | ||
if ($theLine.Length -ge 2) { | ||
# pick the second character as the top wall | ||
$theLine.Substring(1,1) | ||
} else { | ||
# (if there was only one character, it's the top wall) | ||
$theLine.Substring(0,1) | ||
} | ||
} else { | ||
# Otherwise, pick one left of the middle in the line | ||
$theLine.Substring(([Math]::Floor($theLine.Length / 2) - 1), 1) | ||
} |