cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

Pipeline demo uses the sheet command; sizes cut like nushell's

Dami committed 0613ace
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
10 files changed, +43 -32
Mdemos/pipeline.tape18+++++++++++-------
Mdocs/media/notebook.gifbin
Mdocs/media/nu-recipe.gifbin
Mdocs/media/pipeline.gifbin
Mdocs/media/sheet.gifbin
Mdocs/nushell/README.md2+-
Mdocs/nushell/pipelines.md18++++++++++--------
Minternal/numfmt/size.go23++++++++++++-----------
Minternal/numfmt/size_test.go12++++++++----
Minternal/ui/format_test.go2+-
M demos/pipeline.tape +11 -7
M docs/media/notebook.gif +0 -0

Binary file.

M docs/media/nu-recipe.gif +0 -0

Binary file.

M docs/media/pipeline.gif +0 -0

Binary file.

M docs/media/sheet.gif +0 -0

Binary file.

M docs/nushell/README.md +1 -1
M docs/nushell/pipelines.md +10 -8
@@ -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-![In nushell, ls's table goes through 012, three of its rows are selected and sent on, and nu keeps filtering them by size](../media/pipeline.gif)17+![In nushell, ls's table goes through sheet, three of its rows are selected, and quitting sends them on for nu to keep filtering by size](../media/pipeline.gif)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
M internal/numfmt/size.go +12 -11
@@ -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 }
M internal/numfmt/size_test.go +8 -4
M internal/ui/format_test.go +1 -1