Fixes clip copy stripping control characters when de-ansifying (#15428)

Fixes #15414 by changing the method used to de-ansi-fy the input. Control characters will now be kept when using `clip copy`, but ANSI escape codes will be removed (when not using `--ansi (-a)`)
This commit is contained in:
Douglas 2025-03-28 19:15:17 -04:00 committed by GitHub
parent 5fe97b8d59
commit 49d86855ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -11,6 +11,9 @@ export def copy [
--ansi (-a) # Copy ansi formatting --ansi (-a) # Copy ansi formatting
]: any -> nothing { ]: any -> nothing {
let input = $in | collect let input = $in | collect
if not $ansi {
$env.config.use_ansi_coloring = false
}
let text = match ($input | describe -d | get type) { let text = match ($input | describe -d | get type) {
$type if $type in [ table, record, list ] => { $type if $type in [ table, record, list ] => {
$input | table -e $input | table -e
@ -18,18 +21,7 @@ export def copy [
_ => {$input} _ => {$input}
} }
let do_strip_ansi = match $ansi { print -n $'(ansi osc)52;c;($text | encode base64)(ansi st)'
true => {{||}}
false => {{|| ansi strip }}
}
let output = (
$text
| do $do_strip_ansi
| encode base64
)
print -n $'(ansi osc)52;c;($output)(ansi st)'
} }
# Paste contents of system clipboard # Paste contents of system clipboard