Skip to content

Commit

Permalink
new example: obsession get error ansi output
Browse files Browse the repository at this point in the history
  • Loading branch information
ninmonkey committed Jan 22, 2024
1 parent 634eef8 commit 9aab247
Show file tree
Hide file tree
Showing 2 changed files with 217 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
$error.clear()
# & {
# # generate fresh sample error }
# [CmdletBinding()]
# param()
'ssdf'.EnumerateRunes().value | Join-string -f '{x}' -sep ' '
[ErrorRecord]$serr = $error[0]
# } -ea 'silentlycontinue' -ev 'serr'

function Hrr {
param( [int]$PadLines = 1 )
$pad = "`n" * $PadLines -join ''
('-' * [console]::WindowWidth) -join '' |Join-String -op $Pad -os $Pad }

function HShowEscape {
# Replaces escape characters with their saffe-to-print runes
[CmdletBinding()]
param( [Parameter(ValueFromPipeline)][string]$InputText )
process {
if( $Null -eq $InputText ) { return }
$InputText.EnumerateRunes() | %{
( $_.Value -ge 0 -and $_.value -le 0x1f) ?
[Text.Rune]::New( $_.Value + 0x2400 ) :
$_
} | Join-String
}
}
function ShowEmojiRepeats {
# Replaces escape characters
process {
$_ -replace
[Regex]::Escape('␛[32;1m'), '🐈' -replace
[Regex]::Escape('␛[0m'), '🦎'
}
}

[string[]]$outStr_lines = (($serr | Get-Error | out-string) -split '\r?\n').where({$_}, 'first', 6)
$outStr_lines | Set-Clipboard
[string[]]$roundTClippy_lines = Get-Clipboard


(($serr | Get-Error | out-string) -split '\r?\n').where({$_}, 'first', 6) | Join-String -sep (Hrr) -p { $_ | fcc }
| ShowEmojiRepeats


$outStr_lines| HShowEscape
<#
prints
$outStr_lines| HShowEscape
␛[32;1mException : ␛[0m
␛[32;1m␛[0m ␛[32;1mType : ␛[0mSystem.FormatException␛[0m
␛[32;1m␛[0m␛[32;1m␛[0m ␛[32;1mTargetSite : ␛[0m
␛[32;1m␛[0m␛[32;1m␛[0m␛[32;1m␛[0m ␛[32;1mName : ␛[0mThrowFormatInvalidString␛[0m
␛[32;1m␛[0m␛[32;1m␛[0m␛[32;1m␛[0m␛[32;1m␛[0m ␛[32;1mDeclaringType : ␛[0mSystem.ThrowHelper, System.Private.CoreLib
␛[32;1m␛[0m␛[32;1m␛[0m␛[32;1m␛[0m␛[32;1m␛[0m␛[32;1m␛[0m ␛[32;1mMemberType : ␛[0mMethod␛[0m
#>

(($serr | Get-Error | out-string) -split '\r?\n').where({$_}, 'first', 6) | Join-String -sep (Hrr) -p { $_ | HShowEscape } | ShowEmojiRepeats


return

'ssdf'.EnumerateRunes().value | Join-string -f '{x}' -sep ' '
(($serr | Get-Error | out-string) -split '\r?\n').where({$_}, 'first', 6) | Join-String -sep (Hrr) -p { $_ | fcc }


return

(($serr | Get-Error | out-string) -split '\r?\n').where({$_}, 'first', 6) | Join-String -sep (Hrr) -p { $_ | fcc }
Loading

0 comments on commit 9aab247

Please sign in to comment.