Skip to content

Fix length with Add-Border when using ANSI #79

@jdhitsolutions

Description

@jdhitsolutions

When using ANSI escapes in the text, the length of the text is being calculated including the ANSI escapes. Need to subtract that count to get the "real" length.

$s = �[38;5;47mBOVINE320�[0m Up:2.21:40:11 %FreeMem:�[92m52.1�[0m %FreeC:�[93m40.29�[0m %FreeD:�[93m20.86�[0m


[regex]$a="$([char]0x1b)\[\d+[\d;]+m"

[regex]$b="$([char]0x1b)\[0m"

$adjust = 0
$adjust+= ($a.matches($s) | measure length -sum).sum
$adjust+= ($b.matches($s) | measure length -sum).sum

#real length
$s.length - $adjust

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions