Skip to content

Commit dcc589d

Browse files
KissakiNotTheDr01ds132ikl
authored
Replace Pipelines "Behind the Scenes" with "Result Display Rendering" (#1635)
* Replace Pipelines "Behind the Scenes" with "Result Display Rendering" The previous "Behind the Scenes" docs has some problems: * The title is not descriptive * Confusing context reference: The "You may have wondered" references `ls` output despite no applicable example in front of it - and is not stable against other docs section changes either way * Confusing false equivalence: Claims "one and the same" and then explains how they are not in fact the same The section is being replaced with a "Result Display Rendering", which * Mentions and explains the existence of a display output hook * Begins with establishing context: The section is about interactive shell pipeline result display output --- I kept the section small as not to duplicate content from the Hooks documentation page. Adding examples for current, different, or simplified displaying may be reasonable here, but would duplicate the hooks "Changing how Output is Displayed" and "Filtering or Diverting Command Output" sections. * Use absolute link for headline anchor Matching link elsewhere in the file * Take over suggested headline Co-authored-by: Douglas <[email protected]> * Add examples of display_output hooks --------- Co-authored-by: Douglas <[email protected]> Co-authored-by: 132ikl <[email protected]>
1 parent ed4ec36 commit dcc589d

File tree

1 file changed

+57
-22
lines changed

1 file changed

+57
-22
lines changed

book/pipelines.md

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -379,35 +379,70 @@ The `sleep` behavior of not supporting an input stream matches Bash `sleep` beha
379379

380380
Many commands do have piped input/output however, and if it's ever unclear, check their `help` documentation as described above.
381381

382-
## Behind the Scenes
382+
## Rendering Display Results
383383

384-
You may have wondered how we see a table if [`ls`](/commands/docs/ls.md) is an input and not an output. Nu adds this output for us automatically using another command called [`table`](/commands/docs/table.md). The [`table`](/commands/docs/table.md) command is appended to any pipeline that doesn't have an output. This allows us to see the result.
384+
In interactive mode, when a pipeline ends, the [`display_output` hook configuration](https://www.nushell.sh/book/hooks.html#changing-how-output-is-displayed) defines how the result will be displayed.
385+
The default configuration uses the [`table` command](/commands/docs/table.md) to render structured data as a visual table.
385386

386-
In effect, the command:
387+
The following example shows how the `display_output` hook can render
387388

388-
```nu
389-
ls
390-
```
391-
392-
And the pipeline:
389+
- an expanded table with `table -e`
390+
- an unexpanded table with `table`
391+
- an empty closure `{||}` and empty string `''` lead to simple output
392+
- `null` can be assigned to clear any customization, reverting back to default behavior
393393

394394
```nu
395-
ls | table
396-
```
397-
398-
Are one and the same.
399-
400-
::: tip Note
401-
The phrase _"are one and the same"_ above only applies to the graphical output in the shell, it does not mean the two data structures are the same:
402-
403-
```nu
404-
(ls) == (ls | table)
405-
# => false
395+
$env.config.hooks.display_output = { table -e }
396+
[1,2,3,[4,5,6]]
397+
# => ╭───┬───────────╮
398+
# => │ 0 │ 1 │
399+
# => │ 1 │ 2 │
400+
# => │ 2 │ 3 │
401+
# => │ 3 │ ╭───┬───╮ │
402+
# => │ │ │ 0 │ 4 │ │
403+
# => │ │ │ 1 │ 5 │ │
404+
# => │ │ │ 2 │ 6 │ │
405+
# => │ │ ╰───┴───╯ │
406+
# => ╰───┴───────────╯
407+
408+
$env.config.hooks.display_output = { table }
409+
[1,2,3,[4,5,6]]
410+
# => ╭───┬────────────────╮
411+
# => │ 0 │ 1 │
412+
# => │ 1 │ 2 │
413+
# => │ 2 │ 3 │
414+
# => │ 3 │ [list 3 items] │
415+
# => ╰───┴────────────────╯
416+
417+
$env.config.hooks.display_output = {||}
418+
[1,2,3,[4,5,6]]
419+
# => 1
420+
# => 2
421+
# => 3
422+
# => [4
423+
# => 5
424+
# => 6]
425+
426+
$env.config.hooks.display_output = ''
427+
[1,2,3,[4,5,6]]
428+
# => 1
429+
# => 2
430+
# => 3
431+
# => [4
432+
# => 5
433+
# => 6]
434+
435+
# clear to default behavior
436+
$env.config.hooks.display_output = null
437+
[1,2,3,[4,5,6]]
438+
# => ╭───┬────────────────╮
439+
# => │ 0 │ 1 │
440+
# => │ 1 │ 2 │
441+
# => │ 2 │ 3 │
442+
# => │ 3 │ [list 3 items] │
443+
# => ╰───┴────────────────╯
406444
```
407445

408-
`ls | table` is not even structured data!
409-
:::
410-
411446
## Output Result to External Commands
412447

413448
Sometimes you want to output Nushell structured data to an external command for further processing. However, Nushell's default formatting options for structured data may not be what you want.

0 commit comments

Comments
 (0)