The pipeline tape and the Pipelines page lead with 'ls | sheet --send selection | where ...', and explain sheet as the to nuon | ^012 --pipe | from nuon it stands for. The Size format cuts digits past its decimals as nushell does (2998 bytes is 2.9 kB, where it showed 3.0 kB), so a table reads the same in 012 and in nu.
- commit
- 0613aceb706bc9634c1081e65dbfc46998a8c71b
- parent
- 0f539e254fd5a385804c43de764f4232f6e3c3cc
- author
- Dami <dami.etoile@gmail.com>
- kind
- feat risk score 2.0 of 3, Jev's estimate
| M | demos/ | 18 | +++++++++++------- |
| M | docs/ | bin | |
| M | docs/ | bin | |
| M | docs/ | bin | |
| M | docs/ | bin | |
| M | docs/ | 2 | +- |
| M | docs/ | 18 | ++++++++++-------- |
| M | internal/ | 23 | ++++++++++++----------- |
| M | internal/ | 12 | ++++++++---- |
| M | internal/ | 2 | +- |
@@ -1,10 +1,16 @@
1-# Pipelines: in a nushell session, a table goes through 012 and on.2-# ls's table goes in as NUON, 012 shows its sizes in the Size format, a3-# selection is sent back, and nu carries on with sizes that are still4-# file sizes. Needs nu on the PATH.1+# Pipelines: in a nushell session, a table goes through 012 and on with2+# the sheet command. ls's table shows its sizes in the Size format, a3+# selection is sent back when 012 quits (--send selection, so it doesn't4+# ask), and nu carries on with sizes that are still file sizes. Needs nu5+# on the PATH.56 Output out/pipeline.gif67 Source lib/setup.tape78 Source lib/nu.tape9+Hide10+Type "^012 nu --install-module ../bin/012.nu" Enter11+Sleep 1s12+Type "use ../bin/012.nu *; clear" Enter13+Sleep 1s814 915 Show1016 Sleep 600ms@@ -12,7 +18,7 @@ Type "ls data | select name size"
1218 Sleep 400ms1319 Enter1420 Sleep 2.2s15-Type "ls data | select name size | to nuon | ^012 --pipe | from nuon | where size > 400b"21+Type "ls data | select name size | sheet --send selection | where size > 400b"1622 Sleep 600ms1723 Enter1824 Sleep 2s@@ -21,8 +27,6 @@ Ctrl+G
2127 Type "A1:B4" Enter2228 Sleep 1s2329 Ctrl+Q24-Sleep 1.6s25-Enter2630 Sleep 2.5s2731 Screenshot out/stills/pipeline-result.png2832 Sleep 1sBinary file.
Binary file.
Binary file.
Binary file.
@@ -12,7 +12,7 @@ of their own type. 012 is a spreadsheet for those tables. A table can go
1212 through 012 in the middle of a pipeline, and nushell can run inside 0121313 in a notebook, its cells' outputs live parts of the sheets.1414 15-15+1616 1717 ## Three ways to use them together1818 @@ -5,23 +5,25 @@ sidebar_position: 2
55 66 # Pipelines77 8-012 can be a stage in a pipeline: a table comes in on standard input,9-you look at it or edit it in the terminal, and with `--pipe` the result10-goes out on standard output for the next command.8+012 can be a stage in a pipeline: a table comes in, you look at it or9+edit it in the terminal, and what you send back goes on to the next10+command. With the [`sheet` command](#the-sheet-command) installed11+(`012 nu --install-module`), that stage is one word:1112 1213 ```nu13-ls | select name size | to nuon | ^012 --pipe | from nuon | where size > 1kb14+ls | select name size | sheet --send selection | where size > 1kb1415 ```1516 16-17+1718 19+`sheet` is shorthand for20+`to nuon | ^012 --pipe | from nuon`:1821 [`to nuon`](https://www.nushell.sh/commands/docs/to_nuon.html) writes1922 the table in NUON, nushell's own notation, so file sizes, durations and2023 dates arrive as themselves, and2124 [`from nuon`](https://www.nushell.sh/commands/docs/from_nuon.html) reads22-what 012 sends back with the same types ([Types](types.md)). With the23-[`sheet` command](#the-sheet-command) installed, the same stage is24-`ls | select name size | sheet | where size > 1kb`.25+what 012 sends back with the same types ([Types](types.md)). Without the26+module, write it out.2527 2628 The screen is the terminal's own (`/dev/tty`, or the console on2729 Windows), not standard input or output, so the pipeline's data never@@ -13,8 +13,10 @@ var sizeUnits = []string{"B", "kB", "MB", "GB", "TB", "PB", "EB"}
1313 1414 // Size shows v bytes as nushell shows a file size: whole bytes below1515 // 1000 ("512 B"), and above that dec decimals of the largest unit, a16-// thousand times apart, that keeps the number under 1000 once rounded17-// ("1.6 kB", "1.0 MB"). Negative sizes show a minus sign.16+// thousand times apart, that keeps the number under 1000. Like nushell,17+// it cuts the digits past dec rather than rounding them, so 2998 bytes18+// is "2.9 kB", never a unit it hasn't reached. Negative sizes show a19+// minus sign.1820 func Size(v float64, dec int) string { return SizeIn(v, dec, locale.Canonical) }1921 2022 // SizeIn is Size as shown in loc: 1,6 kB in de-DE.@@ -27,23 +29,22 @@ func SizeIn(v float64, dec int, loc *locale.Locale) string {
2729 return sign + "∞ B"2830 }2931 unit := 030- for unit < len(sizeUnits)-1 && roundTo(v, 0) >= 1000 {31- v /= 100032- unit++33- }34- if unit > 0 && roundTo(v, dec) >= 1000 && unit < len(sizeUnits)-1 {32+ for unit < len(sizeUnits)-1 && v >= 1000 {3533 v /= 10003634 unit++3735 }3836 pat := "0"3937 if unit > 0 && dec > 0 {4038 pat += "." + strings.Repeat("0", dec)39+ } else {40+ dec = 04141 }42- return sign + FormatIn(v, pat, loc) + " " + sizeUnits[unit]42+ return sign + FormatIn(truncTo(v, dec), pat, loc) + " " + sizeUnits[unit]4343 }4444 45-// roundTo rounds v to dec decimals, halves away from zero.46-func roundTo(v float64, dec int) float64 {45+// truncTo cuts v to dec decimals. The nudge keeps a value that is46+// exactly on a digit, such as 1.6 held as 1.5999999, from losing it.47+func truncTo(v float64, dec int) float64 {4748 p := math.Pow10(dec)48- return math.Round(v*p) / p49+ return math.Trunc(v*p*(1+1e-12)) / p4950 }@@ -15,12 +15,16 @@ func TestSize(t *testing.T) {
1515 {0, 1, "0 B"},1616 {512, 1, "512 B"},1717 {999, 1, "999 B"},18- {999.6, 1, "1.0 kB"},18+ {999.6, 1, "999 B"},1919 {1000, 1, "1.0 kB"},2020 {1646, 1, "1.6 kB"},21- {1646, 0, "2 kB"},22- {1646, 2, "1.65 kB"},23- {999_999, 1, "1.0 MB"},21+ {1646, 0, "1 kB"},22+ {1646, 2, "1.64 kB"},23+ {999_999, 1, "999.9 kB"},24+ {2998, 1, "2.9 kB"},25+ {1650, 1, "1.6 kB"},26+ {1_999_999, 1, "1.9 MB"},27+ {-2998, 1, "-2.9 kB"},2428 {2_000_000, 1, "2.0 MB"},2529 {1.5e9, 1, "1.5 GB"},2630 {1.2e12, 1, "1.2 TB"},@@ -75,7 +75,7 @@ func TestFormatCommandsCoverSheetsMenu(t *testing.T) {
7575 {"format.financial", " (1,450.00) "},7676 {"format.currency_rounded", " -$1,450 "},7777 {"format.duration", "-34800:00:00"}, // uses the padding: nothing to its right78- {"format.size", " -1.5 kB "},78+ {"format.size", " -1.4 kB "}, // cut, not rounded, as nushell shows it7979 {"format.plain_text", " -1450 "},8080 {"format.automatic", " -1450 "},8181 }