mirror of
https://github.com/nushell/nushell.git
synced 2025-06-20 09:58:15 +02:00
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:
parent
f8b0af70ff
commit
ebcb26f9d5
@ -64,6 +64,7 @@ pub fn load_standard_library(
|
|||||||
"std/testing",
|
"std/testing",
|
||||||
include_str!("../std/testing/mod.nu"),
|
include_str!("../std/testing/mod.nu"),
|
||||||
),
|
),
|
||||||
|
("mod.nu", "std/clip", include_str!("../std/clip/mod.nu")),
|
||||||
];
|
];
|
||||||
|
|
||||||
for (filename, std_subdir_name, content) in std_submodules.drain(..) {
|
for (filename, std_subdir_name, content) in std_submodules.drain(..) {
|
||||||
|
@ -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
|
# Commands for interacting with the system clipboard
|
||||||
#
|
#
|
||||||
# > These commands require your terminal to support OSC 52
|
# > These commands require your terminal to support OSC 52
|
||||||
# > Terminal multiplexers such as screen, tmux, zellij etc may interfere with this command
|
# > 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
|
# 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" {
|
@example "Copy a string to the clipboard" {
|
||||||
"Hello" | clip copy
|
"Hello" | clip copy
|
||||||
}
|
}
|
||||||
export def copy [
|
export def copy [
|
||||||
--ansi (-a) # Copy ansi formatting
|
--ansi (-a) # Copy ansi formatting
|
||||||
]: any -> nothing {
|
]: any -> nothing {
|
||||||
let input = $in | collect
|
std-clip copy --ansi=$ansi
|
||||||
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)'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Paste contents of system clipboard
|
# 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" {
|
@example "Paste a string from the clipboard" {
|
||||||
clip paste
|
clip paste
|
||||||
} --result "Hello"
|
} --result "Hello"
|
||||||
export def paste []: [nothing -> string] {
|
export def paste []: [nothing -> string] {
|
||||||
try {
|
std-clip paste
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add a prefix to each line of the content to be copied
|
# 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" {
|
@example "Format output for Nushell doc" {
|
||||||
[1 2 3] | clip prefix '# => '
|
[1 2 3] | clip prefix '# => '
|
||||||
} --result "# => ╭───┬───╮
|
} --result "# => ╭───┬───╮
|
||||||
@ -55,12 +45,5 @@ export def paste []: [nothing -> string] {
|
|||||||
ls | clip prefix '# => ' | clip copy
|
ls | clip prefix '# => ' | clip copy
|
||||||
}
|
}
|
||||||
export def prefix [prefix: string]: any -> string {
|
export def prefix [prefix: string]: any -> string {
|
||||||
let input = $in | collect
|
std-clip prefix $prefix
|
||||||
match ($input | describe -d | get type) {
|
|
||||||
$type if $type in [ table, record, list ] => {
|
|
||||||
$input | table -e
|
|
||||||
}
|
|
||||||
_ => {$input}
|
|
||||||
}
|
|
||||||
| str replace -r --all '(?m)(.*)' $'($prefix)$1'
|
|
||||||
}
|
}
|
||||||
|
66
crates/nu-std/std/clip/mod.nu
Normal file
66
crates/nu-std/std/clip/mod.nu
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
# Copy input to system clipboard
|
||||||
|
@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)'
|
||||||
|
}
|
||||||
|
|
||||||
|
# Paste contents of system clipboard
|
||||||
|
@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
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add a prefix to each line of the content to be copied
|
||||||
|
@example "Format output for Nushell doc" {
|
||||||
|
[1 2 3] | clip prefix '# => '
|
||||||
|
} --result "# => ╭───┬───╮
|
||||||
|
# => │ 0 │ 1 │
|
||||||
|
# => │ 1 │ 2 │
|
||||||
|
# => │ 2 │ 3 │
|
||||||
|
# => ╰───┴───╯
|
||||||
|
# => "
|
||||||
|
@example "Format output for Nushell doc and copy it" {
|
||||||
|
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'
|
||||||
|
}
|
@ -37,11 +37,16 @@ def get-annotated [
|
|||||||
source `($file)`
|
source `($file)`
|
||||||
scope commands
|
scope commands
|
||||||
| select name attributes
|
| select name attributes
|
||||||
| where attributes != []
|
|
||||||
| to nuon
|
| to nuon
|
||||||
'
|
'
|
||||||
| from nuon
|
| from nuon
|
||||||
| update attributes { get name | each {|x| $valid_annotations | get -i $x } | first }
|
| each {|e|
|
||||||
|
# filter commands with test attributes, and map attributes to annotation name
|
||||||
|
let test_attributes = $e.attributes.name | each {|x| $valid_annotations | get -i $x }
|
||||||
|
if ($test_attributes | is-not-empty) {
|
||||||
|
$e | update attributes $test_attributes.0
|
||||||
|
}
|
||||||
|
}
|
||||||
| rename function_name annotation
|
| rename function_name annotation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user