|
3 | 3 | Nushell's line-editor [Reedline](https://github.com/nushell/reedline) is |
4 | 4 | cross-platform and designed to be modular and flexible. The line-editor is |
5 | 5 | in charge of controlling the command history, validations, completions, hints, |
6 | | -screen paint, and more. |
| 6 | +the status line, screen paint, and more. |
7 | 7 |
|
8 | 8 | [[toc]] |
9 | 9 |
|
@@ -460,6 +460,81 @@ $env.config.hinter.closure = {|ctx| |
460 | 460 |
|
461 | 461 | Set `$env.config.hinter.closure = null` to go back to the built-in history hints. |
462 | 462 |
|
| 463 | +## Status Line |
| 464 | + |
| 465 | +Below the line you're editing, Nushell draws a status line, one row that tells you what the parser |
| 466 | +makes of the line so far. Nushell already parses the line on every keystroke to highlight it, and |
| 467 | +the status line reuses that parse. Running the line erases the status line, and it stays hidden |
| 468 | +while you search the history. |
| 469 | + |
| 470 | +```text |
| 471 | +~> "a,b" | split row "," |
| 472 | + split row {flags} <separator> → list<string> = [a, b] |
| 473 | +``` |
| 474 | + |
| 475 | +The status line has up to three parts, left to right: |
| 476 | + |
| 477 | +- **Signature.** The signature of the command under the cursor, with the parameter you're typing |
| 478 | + in bold and underlined. Required parameters are in `<angle brackets>`, optional ones in |
| 479 | + `(parentheses)`, and a rest parameter starts with `...`. `{flags}` stands for all of the |
| 480 | + command's flags, and it's the part underlined while the cursor is on a flag or its value. |
| 481 | +- **Type.** `→` and the type that the pipeline at the cursor outputs, as far as the parser can |
| 482 | + tell. Inside a closure, block or subexpression, it's the type of the pipeline inside it. The |
| 483 | + status line leaves out `any` and `nothing`. |
| 484 | +- **Preview.** `=` and the value of the line, when every command in it is a |
| 485 | + [const command](./how_nushell_code_gets_run.md#parse-time-constant-evaluation). A line such as |
| 486 | + `ls | length` gets no preview, because `ls` can't run at parse time. If a preview takes longer |
| 487 | + than 25 milliseconds, Nushell stops computing it and leaves it out. |
| 488 | + |
| 489 | +| Line, with the cursor at the end | Status line | |
| 490 | +| -------------------------------------------- | ------------------------------------------------ | |
| 491 | +| `"hello" \| str length` | `str length {flags} ...(rest) → int = 5` | |
| 492 | +| `[1 2 3] \| math sum` | `math sum {flags} ...(columns) → number = 6` | |
| 493 | +| `ls \| update name {\|r\| [1 2] \| math sum` | `math sum {flags} ...(columns) → number` | |
| 494 | +| `ls \| ` | `→ table` | |
| 495 | +| `1 + 2` | `→ int = 3` | |
| 496 | + |
| 497 | +In `str substring 1..2`, the cursor is on the range, so the status line underlines `<range>` in |
| 498 | +`str substring {flags} <range> ...(rest)`. |
| 499 | + |
| 500 | +When the line has a parse or type error, the status line shows the first one instead, in red: |
| 501 | + |
| 502 | +```text |
| 503 | +~> let x: int = "a" |
| 504 | + ✗ Type mismatch: expected int, found string |
| 505 | +``` |
| 506 | + |
| 507 | +An error shows up only once it's no longer about the text you're still typing: |
| 508 | + |
| 509 | +- `let x: int = "a"` shows no error until you type a space after `"a"`. |
| 510 | +- `str substring ` doesn't report its missing range while the cursor waits for it. Move on to |
| 511 | + `str substring | str length` and the status line shows |
| 512 | + `✗ Missing required positional argument: missing range`. |
| 513 | +- An unfinished line, such as one with an open `{`, shows no error. |
| 514 | +- A line that `use`s a module that isn't loaded yet shows no error and no preview. The parse behind |
| 515 | + the highlighting doesn't load the module, so the names it imports would look unknown. |
| 516 | + |
| 517 | +Each part can be turned off on its own. All of these default to `true`, and a change takes effect |
| 518 | +at the next prompt: |
| 519 | + |
| 520 | +```nu |
| 521 | +$env.config.status_line.enable = true # false hides the status line entirely |
| 522 | +$env.config.status_line.errors = true # the first parse or type error |
| 523 | +$env.config.status_line.signature = true # the signature of the command under the cursor |
| 524 | +$env.config.status_line.type = true # the type the pipeline outputs |
| 525 | +$env.config.status_line.preview = true # the value of a line of const commands |
| 526 | +``` |
| 527 | + |
| 528 | +The status line is drawn in `$env.config.color_config.status_line`, or in the `hints` style when |
| 529 | +that key isn't set. Errors use `$env.config.color_config.status_line_error`, which is `red` by |
| 530 | +default. With `$env.config.use_ansi_coloring = false`, the status line is plain text. See |
| 531 | +[Coloring and Theming](./coloring_and_theming.md) for the style syntax. |
| 532 | + |
| 533 | +```nu |
| 534 | +$env.config.color_config.status_line = 'cyan' |
| 535 | +$env.config.color_config.status_line_error = { fg: 'yellow' attr: b } |
| 536 | +``` |
| 537 | + |
463 | 538 | ## Customizing the Prompt |
464 | 539 |
|
465 | 540 | The Reedline prompt is configured using a number of environment variables. See [Prompt Configuration](./configuration.md#prompt-configuration) for details. |
|
0 commit comments