nushell/crates
132ikl d69e131450
Rely on display_output hook for formatting values from evaluations (#14361)
# Description

I was reading through the documentation yesterday, when I stumbled upon
[this
section](https://www.nushell.sh/book/pipelines.html#behind-the-scenes)
explaining how command output is formatted using the `table` command. I
was surprised that this section didn't mention the `display_output`
hook, so I took a look in the code and was shocked to discovered that
the documentation was correct, and the `table` command _is_
automatically applied to printed pipelines.

This auto-tabling has two ramifications for the `display_output` hook:

1. The `table` command is called on the output of a pipeline after the
`display_output` has run, even if `display_output` contains the table
command. This means each pipeline output is roughly equivalent to the
following (using `ls` as an example):
    ```nushell
    ls | do $config.hooks.display_output | table
    ```
2. If `display_output` returns structured data, it will _still_ be
formatted through the table command.

This PR removes the auto-table when the `display_output` hook is set.
The auto-table made sense before `display_output` was introduced, but to
me, it now seems like unnecessary "automagic" which can be accomplished
using existing Nushell features.

This means that you can now pull back the curtain a bit, and replace
your `display_output` hook with an empty closure
(`$env.config.hooks.display_output = {||}`, setting it to null retains
the previous behavior) to see the values printed normally without the
table formatting. I think this is a good thing, and makes it easier to
understand Nushell fundamentals.

It is important to note that this PR does not change how `print` and
other commands (well, specifically only `watch`) print out values. They
continue to use `table` with no arguments, so changing your
config/`display_output` hook won't affect what `print`ing a value does.

Rel: [Discord
discussion](https://discord.com/channels/601130461678272522/615329862395101194/1307102690848931904)
(cc @dcarosone)

# User-Facing Changes

Pipelines are no longer automatically formatted using the `table`
command. Instead, the `display_output` hook is used to format pipeline
output. Most users should see no impact, as the default `display_output`
hook already uses the `table` command.

# Tests + Formatting

- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting


Will update mentioned docs page to call out `display_output` hook.
2024-11-19 21:04:29 +08:00
..
nu_plugin_custom_values Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu_plugin_example Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu_plugin_formats Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu_plugin_gstat Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu_plugin_inc Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu_plugin_nu_example Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu_plugin_polars Fix doc and code comment typos (#14366) 2024-11-17 19:17:35 +01:00
nu_plugin_python Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu_plugin_query Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu_plugin_stress_internals Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu-cli Rely on display_output hook for formatting values from evaluations (#14361) 2024-11-19 21:04:29 +08:00
nu-cmd-base Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu-cmd-extra Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu-cmd-lang Remove the NU_DISABLE_IR option (#14293) 2024-11-15 12:09:25 +08:00
nu-cmd-plugin Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu-color-config Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu-command Rely on display_output hook for formatting values from evaluations (#14361) 2024-11-19 21:04:29 +08:00
nu-derive-value Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu-engine Remove the NU_DISABLE_IR option (#14293) 2024-11-15 12:09:25 +08:00
nu-explore Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu-glob skip test_iteration_errors if /root is missing (#14299) 2024-11-14 10:13:04 +01:00
nu-json Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu-lsp Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu-parser make command signature parsing more strict (#14309) 2024-11-18 08:01:52 +08:00
nu-path Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu-plugin Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu-plugin-core Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu-plugin-engine Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu-plugin-protocol Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu-plugin-test-support Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu-pretty-hex Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu-protocol Rely on display_output hook for formatting values from evaluations (#14361) 2024-11-19 21:04:29 +08:00
nu-std add multiple grouper support to group-by (#14337) 2024-11-15 06:40:49 -06:00
nu-system Cut down unnecessary lint allows (#14335) 2024-11-15 19:24:39 +01:00
nu-table Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu-term-grid Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nu-test-support Remove the NU_DISABLE_IR option (#14293) 2024-11-15 12:09:25 +08:00
nu-utils Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
nuon Bump to dev version 0.100.1 (#14328) 2024-11-14 10:04:39 +01:00
README.md Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00

Nushell core libraries and plugins

These sub-crates form both the foundation for Nu and a set of plugins which extend Nu with additional functionality.

Foundational libraries are split into two kinds of crates:

  • Core crates - those crates that work together to build the Nushell language engine
  • Support crates - a set of crates that support the engine with additional features like JSON support, ANSI support, and more.

Plugins are likewise also split into two types:

  • Core plugins - plugins that provide part of the default experience of Nu, including access to the system properties, processes, and web-connectivity features.
  • Extra plugins - these plugins run a wide range of different capabilities like working with different file types, charting, viewing binary data, and more.