Skip to content

Commit

Permalink
feat: Posh.Host.UI.Box.TopWall ( Fixes #369 )
Browse files Browse the repository at this point in the history
  • Loading branch information
StartAutomating authored and StartAutomating committed Feb 25, 2024
1 parent 53e2fe7 commit 6203c2d
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions Posh.types.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,47 @@ if (-not $theseLines) { return }
$theseLines[0].Substring($theseLines[0].Length - 1)


</GetScriptBlock>
</ScriptProperty>
<ScriptProperty>
<Name>TopWall</Name>
<GetScriptBlock>
&lt;#
.SYNOPSIS
Gets a box's top wall character
.DESCRIPTION
Gets the top 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 top wall.

Otherwise, the character directly left of the middle will be considered the top wall.
#&gt;
$theseLines = @($this -split '[\r\n]+' -ne '')

if (-not $theseLines) { return }
$theLine = $theseLines[0]
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,2)
} 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[[Math]::Floor($theLine.Length / 2) - 1]
}






</GetScriptBlock>
</ScriptProperty>
</Members>
Expand Down

0 comments on commit 6203c2d

Please sign in to comment.