From 49d86855ce6c5c0df785dc5f4b786707d650a83c Mon Sep 17 00:00:00 2001 From: Douglas <32344964+NotTheDr01ds@users.noreply.github.com> Date: Fri, 28 Mar 2025 19:15:17 -0400 Subject: [PATCH] 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)`) --- crates/nu-std/std-rfc/clip/mod.nu | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/crates/nu-std/std-rfc/clip/mod.nu b/crates/nu-std/std-rfc/clip/mod.nu index 60e8d0fefe..44cc4cbaa1 100644 --- a/crates/nu-std/std-rfc/clip/mod.nu +++ b/crates/nu-std/std-rfc/clip/mod.nu @@ -11,6 +11,9 @@ export def copy [ --ansi (-a) # Copy ansi formatting ]: any -> nothing { let input = $in | collect + if not $ansi { + $env.config.use_ansi_coloring = false + } let text = match ($input | describe -d | get type) { $type if $type in [ table, record, list ] => { $input | table -e @@ -18,18 +21,7 @@ export def copy [ _ => {$input} } - let do_strip_ansi = match $ansi { - true => {{||}} - false => {{|| ansi strip }} - } - - let output = ( - $text - | do $do_strip_ansi - | encode base64 - ) - - print -n $'(ansi osc)52;c;($output)(ansi st)' + print -n $'(ansi osc)52;c;($text | encode base64)(ansi st)' } # Paste contents of system clipboard