1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-02 07:07:46 +00:00

update script syntax to match the latest nushell (#429)

This commit is contained in:
Darren Schroeder 2023-03-31 07:39:20 -05:00 committed by GitHub
parent a0c1314dd0
commit 4f2263447f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 29 deletions

View file

@ -4,9 +4,9 @@
let height = (term size).rows - 3 # calculate height let height = (term size).rows - 3 # calculate height
let width = (term size).columns - 5 # calculate width let width = (term size).columns - 5 # calculate width
let stamp_start = $width * 1.25 # calculate where to start Nu stamp let stamp_start = $width * 1.25 # calculate where to start Nu stamp
let stamp_end = $width * 1.3125 # calculate where to stop Nu stamp let stamp_end = $width * 1.3 # calculate where to stop Nu stamp
let stamp = 'Nu' let stamp = 'Nu'
seq 0 $height | par-each { # create these in parallel seq 0 $height | par-each {|| # create these in parallel
let row_data = (seq 0 $width | each { |col| let row_data = (seq 0 $width | each { |col|
let fgcolor = 2 + 2 * $col let fgcolor = 2 + 2 * $col
if $fgcolor > $stamp_start and $fgcolor < $stamp_end { if $fgcolor > $stamp_start and $fgcolor < $stamp_end {
@ -15,6 +15,6 @@ seq 0 $height | par-each { # create these in parallel
$"(ansi -e '48;2;0;0;')($fgcolor)m (ansi -e '0m')" $"(ansi -e '48;2;0;0;')($fgcolor)m (ansi -e '0m')"
} }
} | str collect) } | str collect)
$"($row_data)" | table print -n $"($row_data)" | table
$nothing $nothing
} | compact } | compact

View file

@ -4,11 +4,11 @@ def iter_inc [incr mult iter] {
$incr + $mult * $iter $incr + $mult * $iter
} }
let is_release = input "Did you compile in a release mode? y/n " let is_release = (input "Did you compile in a release mode? y/n ")
if ($is_release | str downcase | str trim) == "y" { if ($is_release | str downcase | str trim) == "y" {
$"running test 0 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')" print $"running test 0 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')"
# 0. this has wrong output # 0. this has wrong output
let 0 = (seq 10 | timeit { let 0 = (seq 10 | timeit {
let height = 40 let height = 40
@ -28,7 +28,7 @@ if ($is_release | str downcase | str trim) == "y" {
} | math avg) } | math avg)
$"running test 1 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')" print $"running test 1 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')"
# 1. Fixed newline to fix the output (char cr) # 1. Fixed newline to fix the output (char cr)
let 1 = (seq 10 | timeit { let 1 = (seq 10 | timeit {
let height = 40 let height = 40
@ -47,7 +47,7 @@ if ($is_release | str downcase | str trim) == "y" {
} | str collect } | str collect
} | math avg) } | math avg)
$"running test 2 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')" print $"running test 2 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')"
# 2. Replace (char sp) with just space # 2. Replace (char sp) with just space
let 2 = (seq 10 | timeit { let 2 = (seq 10 | timeit {
let height = 40 let height = 40
@ -66,14 +66,14 @@ if ($is_release | str downcase | str trim) == "y" {
} | str collect } | str collect
} | math avg) } | math avg)
$"running test 3 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')" print $"running test 3 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')"
# 3. Precompute (ansi -e '48;2;0;0;') and (ansi -e '0m') -- seems to be slower # 3. Precompute (ansi -e '48;2;0;0;') and (ansi -e '0m') -- seems to be slower
let 3 = (seq 10 | timeit { let 3 = (seq 10 | timeit {
let height = 40 let height = 40
let width = 160 let width = 160
let stamp = 'Nu' let stamp = 'Nu'
let ansi1 = ansi -e '48;2;0;0;' let ansi1 = (ansi -e '48;2;0;0;')
let ansi2 = ansi -e '0m' let ansi2 = (ansi -e '0m')
seq 0 $height | each { |row| seq 0 $height | each { |row|
let row_data = (seq 0 $width | each { |col| let row_data = (seq 0 $width | each { |col|
let fgcolor = (iter_inc 2 2 $col) let fgcolor = (iter_inc 2 2 $col)
@ -87,7 +87,7 @@ if ($is_release | str downcase | str trim) == "y" {
} | str collect } | str collect
} | math avg) } | math avg)
$"running test 4 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')" print $"running test 4 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')"
# 4. Inline iter_inc call # 4. Inline iter_inc call
let 4 = (seq 10 | timeit { let 4 = (seq 10 | timeit {
let height = 40 let height = 40
@ -106,7 +106,7 @@ if ($is_release | str downcase | str trim) == "y" {
} | str collect } | str collect
} | math avg) } | math avg)
$"running test 5 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')" print $"running test 5 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')"
# 5. Combine (char sp) substitution and iter_inc inlining # 5. Combine (char sp) substitution and iter_inc inlining
let 5 = (seq 10 | timeit { let 5 = (seq 10 | timeit {
let height = 40 let height = 40
@ -125,13 +125,13 @@ if ($is_release | str downcase | str trim) == "y" {
} | str collect } | str collect
} | math avg) } | math avg)
$"running test 6 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')" print $"running test 6 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')"
# 6. The above with par-each outer loop (using par-each anywhere else breaks the output) # 6. The above with par-each outer loop (using par-each anywhere else breaks the output)
let 6 = (seq 10 | timeit { let 6 = (seq 10 | timeit {
let height = 40 let height = 40
let width = 160 let width = 160
let stamp = 'Nu' let stamp = 'Nu'
seq 0 $height | par-each { |row| seq 0 $height | par-each -t 100 { |row|
let row_data = (seq 0 $width | each { |col| let row_data = (seq 0 $width | each { |col|
let fgcolor = 2 + 2 * $col let fgcolor = 2 + 2 * $col
if $fgcolor > 200 and $fgcolor < 210 { if $fgcolor > 200 and $fgcolor < 210 {
@ -144,9 +144,9 @@ if ($is_release | str downcase | str trim) == "y" {
} | str collect } | str collect
} | math avg) } | math avg)
echo 'collating tests' print 'collating tests'
[ $0 $1 $2 $3 $4 $5 $6 ] [ $0 $1 $2 $3 $4 $5 $6 ]
} else { } else {
echo "Compile in a release mode!" print "Compile in a release mode!"
} }

View file

@ -9,7 +9,7 @@ let is_release = "y"
if ($is_release | str downcase | str trim) == "y" { if ($is_release | str downcase | str trim) == "y" {
$"running test 0 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')" print $"running test 0 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')"
# 0. this has wrong output # 0. this has wrong output
let 0 = (seq 10 | timeit { let 0 = (seq 10 | timeit {
let height = 40 let height = 40
@ -29,7 +29,7 @@ if ($is_release | str downcase | str trim) == "y" {
} | math avg) } | math avg)
$"running test 1 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')" print $"running test 1 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')"
# 1. Fixed newline to fix the output (char cr) # 1. Fixed newline to fix the output (char cr)
let 1 = (seq 10 | timeit { let 1 = (seq 10 | timeit {
let height = 40 let height = 40
@ -48,7 +48,7 @@ if ($is_release | str downcase | str trim) == "y" {
} | str collect } | str collect
} | math avg) } | math avg)
$"running test 2 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')" print $"running test 2 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')"
# 2. Replace (char sp) with just space # 2. Replace (char sp) with just space
let 2 = (seq 10 | timeit { let 2 = (seq 10 | timeit {
let height = 40 let height = 40
@ -67,14 +67,14 @@ if ($is_release | str downcase | str trim) == "y" {
} | str collect } | str collect
} | math avg) } | math avg)
$"running test 3 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')" print $"running test 3 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')"
# 3. Precompute (ansi -e '48;2;0;0;') and (ansi -e '0m') -- seems to be slower # 3. Precompute (ansi -e '48;2;0;0;') and (ansi -e '0m') -- seems to be slower
let 3 = (seq 10 | timeit { let 3 = (seq 10 | timeit {
let height = 40 let height = 40
let width = 160 let width = 160
let stamp = 'Nu' let stamp = 'Nu'
let ansi1 = ansi -e '48;2;0;0;' let ansi1 = (ansi -e '48;2;0;0;')
let ansi2 = ansi -e '0m' let ansi2 = (ansi -e '0m')
seq 0 $height | each { |row| seq 0 $height | each { |row|
let row_data = (seq 0 $width | each { |col| let row_data = (seq 0 $width | each { |col|
let fgcolor = (iter_inc 2 2 $col) let fgcolor = (iter_inc 2 2 $col)
@ -88,7 +88,7 @@ if ($is_release | str downcase | str trim) == "y" {
} | str collect } | str collect
} | math avg) } | math avg)
$"running test 4 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')" print $"running test 4 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')"
# 4. Inline iter_inc call # 4. Inline iter_inc call
let 4 = (seq 10 | timeit { let 4 = (seq 10 | timeit {
let height = 40 let height = 40
@ -107,7 +107,7 @@ if ($is_release | str downcase | str trim) == "y" {
} | str collect } | str collect
} | math avg) } | math avg)
$"running test 5 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')" print $"running test 5 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')"
# 5. Combine (char sp) substitution and iter_inc inlining # 5. Combine (char sp) substitution and iter_inc inlining
let 5 = (seq 10 | timeit { let 5 = (seq 10 | timeit {
let height = 40 let height = 40
@ -126,13 +126,13 @@ if ($is_release | str downcase | str trim) == "y" {
} | str collect } | str collect
} | math avg) } | math avg)
$"running test 6 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')" print $"running test 6 at (date now | date format '%Y-%m-%d %H:%M:%S.%3f')"
# 6. The above with par-each outer loop (using par-each anywhere else breaks the output) # 6. The above with par-each outer loop (using par-each anywhere else breaks the output)
let 6 = (seq 10 | timeit { let 6 = (seq 10 | timeit {
let height = 40 let height = 40
let width = 160 let width = 160
let stamp = 'Nu' let stamp = 'Nu'
seq 0 $height | par-each { |row| seq 0 $height | par-each -t 100 { |row|
let row_data = (seq 0 $width | each { |col| let row_data = (seq 0 $width | each { |col|
let fgcolor = 2 + 2 * $col let fgcolor = 2 + 2 * $col
if $fgcolor > 200 and $fgcolor < 210 { if $fgcolor > 200 and $fgcolor < 210 {
@ -145,9 +145,9 @@ if ($is_release | str downcase | str trim) == "y" {
} | str collect } | str collect
} | math avg) } | math avg)
echo 'collating tests' print 'collating tests'
[ $0 $1 $2 $3 $4 $5 $6 ] [ $0 $1 $2 $3 $4 $5 $6 ]
} else { } else {
echo "Compile in a release mode!" print "Compile in a release mode!"
} }

View file

@ -33,3 +33,5 @@ def build-colorstr [
$"($bg)($fg)($slash_str)" $"($bg)($fg)($slash_str)"
# sleep 10ms | ignore # sleep 10ms | ignore
} }
draw

View file

@ -30,7 +30,7 @@ def "nu-complete cargo features" [] {
# `cargo --list` is slow, `open` is faster. # `cargo --list` is slow, `open` is faster.
# TODO: Add caching. # TODO: Add caching.
def "nu-complete cargo subcommands" [] { def "nu-complete cargo subcommands" [] {
^cargo --list | lines | skip 1 | str collect "\n" | from ssv --noheaders | get column1 ^cargo --list | lines | skip 1 | str join "\n" | from ssv --noheaders | get column1
} }
def "nu-complete cargo vcs" [] { def "nu-complete cargo vcs" [] {
[ [