Skip to content

Commit

Permalink
feat: Posh.Host.UI.Box.GetBorderLine ( Fixes #373 )
Browse files Browse the repository at this point in the history
Fixing Overflows
  • Loading branch information
StartAutomating authored and StartAutomating committed Feb 25, 2024
1 parent 41ca674 commit 2bcb82f
Showing 1 changed file with 56 additions and 36 deletions.
92 changes: 56 additions & 36 deletions Posh.types.ps1xml
Original file line number Diff line number Diff line change
Expand Up @@ -1612,19 +1612,22 @@ if (-not $Width) {
$width = $host.UI.RawUI.BufferSize.Width
}

$left,
$right,
$middle,
$wall =
$this."${lineType}Left",
$this."${lineType}Right",
($this.("${lineType}Middle" -replace "MiddleMiddle", "Middle")),
$this."${lineType}Wall"

if (-not $wall) { $wall = ' '}
if (-not $left) { $left = $this.LeftWall }
if (-not $middle) { $middle = $this.MiddleWall }
if (-not $right) { $right = $this.RightWall }
if ($lineType -eq 'Row') {
$wall = ' '
$left = $this.LeftWall
$middle = $this.MiddleVerticalWall
$right = $this.RightWall
} else {
$left,
$right,
$middle,
$wall =
$this."${lineType}Left",
$this."${lineType}Right",
($this.("${lineType}Middle" -replace "MiddleMiddle", "Middle")),
$this."${lineType}Wall"
}

if (-not $ColumnWidth) {
return $(switch ($width) {
1 { $left }
Expand All @@ -1635,33 +1638,50 @@ if (-not $ColumnWidth) {
}
}
})
} else {
$currentTotalWidth = 0
$columnWidths = @(foreach ($eachColumnWidth in $ColumnWidth) {
$columnsWide =
if ($eachColumnWidth -le 1) {
([int][Math]::Floor($width * $eachColumnWidth) - 1)
} else {
$eachColumnWidth -as [int]
}
if ($width -ge ($columnsWide + $currentTotalWidth)) {
$currentTotalWidth+=$columnsWide
$columnsWide
}
$currentTotalWidth = 0
$columnWidths = @(foreach ($eachColumnWidth in $ColumnWidth) {
$columnsWide =
if ($eachColumnWidth -le 1) {
([int][Math]::Floor($width * $eachColumnWidth) - 1)
} else {
$eachColumnWidth -as [int]
}
})
if ($width -ge ($columnsWide + $currentTotalWidth)) {
$currentTotalWidth+=$columnsWide
$columnsWide
}
})

@(
$left
for ($columnNumber = 0; $columnNumber -lt $columnWidths.Length; $columnNumber++) {
if ($columnNumber) {
$Middle

@(
$left
$totalWidth = 1
for ($columnNumber = 0; $columnNumber -lt $columnWidths.Length; $columnNumber++) {
if ($columnNumber) {
$Middle
}
$thisColumnWidth = $columnWidths[$columnNumber]

$wallSection = $Wall * $thisColumnWidth
$totalWidth += $wallSection.Length
Write-Debug "Total Width: $totalWidth"
if (($totalWidth + 2) -ge $Width) {
if ($totalWidth -ge $width) {
$n = ($totalWidth - $width) + 1
$wallSection -replace ".{$n}$"
} else {
$wallSection.Substring(0, $wallSection.Length - 1)
}
$Wall * $columnWidths[$columnNumber]

break
} else {
$wallSection
}
$Right
) -join ''

}
}
$totalWidth++
$Right
) -join ''
</Script>
</ScriptMethod>
<ScriptProperty>
Expand Down

0 comments on commit 2bcb82f

Please sign in to comment.