nushell/crates
Andrés N. Robalino 7a77910720
Table content rolling. (#3097)
There are many use cases. Here we introduce the following:

- The rows can be rolled `... | roll` (up) or `... | roll down`
- Columns can be rolled too (the default is on the `left`, you can pass `... | roll column --opposite` to roll in the other direction)
- You can `roll` the cells of a table and keeping the header names in the same order (`... | roll column --cells-only`)
- Above examples can also be passed (Ex. `... | roll down 3`) a number to tell how many places to roll.

Basic working example with rolling columns:

```
> echo '00000100'
| split chars
| each { str to-int }
| rotate counter-clockwise _
| reject _
| rename bit1 bit2 bit3 bit4 bit5 bit6 bit7 bit8

───┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────
 # │ bit1 │ bit2 │ bit3 │ bit4 │ bit5 │ bit6 │ bit7 │ bit8
───┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────
 0 │    0 │    0 │    0 │    0 │    0 │    1 │    0 │    0
───┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────
```

We want to "shift" three bits to the left of the bitstring (four in decimal), let's try it:

```
> echo '00000100'
| split chars
| each { str to-int }
| rotate counter-clockwise _
| reject _
| rename bit1 bit2 bit3 bit4 bit5 bit6 bit7 bit8
| roll column 3

───┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────
 # │ bit4 │ bit5 │ bit6 │ bit7 │ bit8 │ bit1 │ bit2 │ bit3
───┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────
 0 │    0 │    0 │    1 │    0 │    0 │    0 │    0 │    0
───┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────
```

The tables was rolled correctly (32 in decimal, for above bitstring). However, the *last three header names* look confusing.
We can roll the cell contents only to fix it.

```
> echo '00000100'
| split chars
| each { str to-int }
| rotate counter-clockwise _
| reject _
| rename bit1 bit2 bit3 bit4 bit5 bit6 bit7 bit8
| roll column 3 --cells-only

───┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────
 # │ bit1 │ bit2 │ bit3 │ bit4 │ bit5 │ bit6 │ bit7 │ bit8
───┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────
 0 │    0 │    0 │    1 │    0 │    0 │    0 │    0 │    0
───┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────
```

There we go. Let's compute it's decimal value now (should be 32)

```
> echo '00000100'
| split chars
| each { str to-int }
| rotate counter-clockwise _
| reject _
| roll column 3 --cells-only
| pivot bit --ignore-titles
| get bit
| reverse
| each --numbered { = $it.item * (2 ** $it.index) }
| math sum

32
```
2021-02-23 13:29:07 -05:00
..
nu-ansi-term add nu-ansi-term (#3089) 2021-02-22 12:33:34 -06:00
nu-cli add nu-ansi-term (#3089) 2021-02-22 12:33:34 -06:00
nu-command Table content rolling. (#3097) 2021-02-23 13:29:07 -05:00
nu-data Remove parking_lot crate reference from nu-data (#3091) 2021-02-23 22:21:31 +13:00
nu-engine Make sure CurDir is filtered out in absolutize. (#3084) 2021-02-23 22:22:17 +13:00
nu-errors add nu-ansi-term (#3089) 2021-02-22 12:33:34 -06:00
nu-json Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu-parser Remove parking_lot crate reference from nu-data (#3091) 2021-02-23 22:21:31 +13:00
nu-plugin Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu-protocol Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu-source Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu-stream Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu-table return string from draw_table instead of printing directly (#3088) 2021-02-23 22:25:49 +13:00
nu-test-support Extract .nu-env tests and more granularity (#3078) 2021-02-18 20:24:27 -05:00
nu-value-ext Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu_plugin_binaryview add nu-ansi-term (#3089) 2021-02-22 12:33:34 -06:00
nu_plugin_chart Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu_plugin_fetch Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu_plugin_from_bson Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu_plugin_from_sqlite Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu_plugin_inc Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu_plugin_match Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu_plugin_post Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu_plugin_ps Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu_plugin_s3 Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu_plugin_selector Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu_plugin_start Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu_plugin_sys Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu_plugin_textview add nu-ansi-term (#3089) 2021-02-22 12:33:34 -06:00
nu_plugin_to_bson Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu_plugin_to_sqlite Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu_plugin_tree Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00
nu_plugin_xpath Bump to 0.27.1 (#3073) 2021-02-18 18:54:48 +13:00