From 2bcb82f9cc1a09733747f5f4bc56165ed4b21b39 Mon Sep 17 00:00:00 2001 From: StartAutomating Date: Sun, 25 Feb 2024 23:32:56 +0000 Subject: [PATCH] feat: Posh.Host.UI.Box.GetBorderLine ( Fixes #373 ) Fixing Overflows --- Posh.types.ps1xml | 92 ++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 36 deletions(-) diff --git a/Posh.types.ps1xml b/Posh.types.ps1xml index 97f3b6a..ffa4d54 100644 --- a/Posh.types.ps1xml +++ b/Posh.types.ps1xml @@ -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 } @@ -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 ''