Promote clip from std-rfc to std (#15877)

# Description
Promotes the clip module from `std-rfc` to `std`. Whether we want to
promote other modules as well (probably?) is up for discussion but I
thought I would get the ball rolling with this one.

# User-Facing Changes
* The `clip` module has been promoted from `std-rfc` to `std`. Using the
`std-rfc` version of clip modules will give a deprecation warning
instructing you to switch to the `std` version.

# Tests + Formatting
N/A

# After Submitting
N/A
This commit is contained in:
132ikl
2025-06-12 19:26:48 -04:00
committed by GitHub
parent f8b0af70ff
commit ebcb26f9d5
4 changed files with 88 additions and 33 deletions

View File

@ -1,48 +1,38 @@
# The clip module has been added to std. This std-rfc module is deprecated and will be removed.
#
# Commands for interacting with the system clipboard
#
# > These commands require your terminal to support OSC 52
# > Terminal multiplexers such as screen, tmux, zellij etc may interfere with this command
module std-clip {
export use std/clip *
}
use std-clip
# Copy input to system clipboard
@deprecated "The clip module has been moved to std. Please use the std version instead of the std-rfc version." --since 0.105.0 --remove 0.107.0
@example "Copy a string to the clipboard" {
"Hello" | clip copy
}
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
}
_ => {$input}
}
print -n $'(ansi osc)52;c;($text | encode base64)(ansi st)'
std-clip copy --ansi=$ansi
}
# Paste contents of system clipboard
@deprecated "The clip module has been moved to std. Please use the std version instead of the std-rfc version." --since 0.105.0 --remove 0.107.0
@example "Paste a string from the clipboard" {
clip paste
} --result "Hello"
export def paste []: [nothing -> string] {
try {
term query $'(ansi osc)52;c;?(ansi st)' -p $'(ansi osc)52;c;' -t (ansi st)
} catch {
error make -u {
msg: "Terminal did not responds to OSC 52 paste request."
help: $"Check if your terminal supports OSC 52."
}
}
| decode
| decode base64
| decode
std-clip paste
}
# Add a prefix to each line of the content to be copied
@deprecated "The clip module has been moved to std. Please use the std version instead of the std-rfc version." --since 0.105.0 --remove 0.107.0
@example "Format output for Nushell doc" {
[1 2 3] | clip prefix '# => '
} --result "# => ╭───┬───╮
@ -55,12 +45,5 @@ export def paste []: [nothing -> string] {
ls | clip prefix '# => ' | clip copy
}
export def prefix [prefix: string]: any -> string {
let input = $in | collect
match ($input | describe -d | get type) {
$type if $type in [ table, record, list ] => {
$input | table -e
}
_ => {$input}
}
| str replace -r --all '(?m)(.*)' $'($prefix)$1'
std-clip prefix $prefix
}