Skip to content

Commit cfe9430

Browse files
committed
Add examples of display_output hooks
1 parent 22e5e0d commit cfe9430

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

book/pipelines.md

+59
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,65 @@ Many commands do have piped input/output however, and if it's ever unclear, chec
384384
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.
385385
The default configuration uses the [`table` command](/commands/docs/table.md) to render structured data as a visual table.
386386

387+
The following example shows how the `display_output` hook can render
388+
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
393+
394+
```nu
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+
# => ╰───┴────────────────╯
444+
```
445+
387446
## Output Result to External Commands
388447

389448
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)