Skip to content

Commit 714dcbd

Browse files
authored
add status line docs (#2279)
1 parent 9224ba3 commit 714dcbd

3 files changed

Lines changed: 85 additions & 3 deletions

File tree

‎book/coloring_and_theming.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ This is the current list of primitives. Not all of these are configurable. The c
322322
| `row_index` | `green_bold` | \* |
323323
| `separator` | `default` | \* |
324324
| `hints` | `dark_gray` | \* |
325+
| `status_line` | the `hints` style | \* |
326+
| `status_line_error` | `red` | \* |
325327
| `search_result` | `{ bg: red, fg: default }` | \* |
326328
| `selection` | `{ attr: r }` | \* |
327329
| `selection_cursor` | `{ attr: n }` | \* |
@@ -637,5 +639,6 @@ See the [section dedicated to Reedline’s menus configuration](line_editor.md#m
637639

638640
The line editor does use a few `color_config` keys: `hints` styles the inline hints,
639641
`selection` styles text selected in Vi visual mode or Helix mode, and `selection_cursor`
640-
styles the character under the cursor inside a selection. The `shape_*` keys above
641-
style the syntax highlighting of the command line.
642+
styles the character under the cursor inside a selection. `status_line` styles the
643+
[status line](line_editor.md#status-line) under the prompt, and `status_line_error` styles
644+
an error shown there. The `shape_*` keys above style the syntax highlighting of the command line.

‎book/how_nushell_code_gets_run.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,17 @@ Put differently, only a small subset of commands and expressions can generate a
405405

406406
In general, the commands and resulting expressions will be fairly simple and **_without side effects_**. Otherwise, the parser could all-too-easily enter an unrecoverable state. Imagine, for instance, attempting to assign an infinite stream to a constant. The Parse stage would never complete!
407407

408+
A constant that is merely slow to compute, such as `const x = (1..10000000000 | math sum)`, can still be stopped. In a script or with `nu -c`, <kbd>Ctrl</kbd>+<kbd>C</kbd> interrupts it with an `Operation interrupted` error.
409+
408410
::: tip
409411
You can see which Nushell commands can return constant values using:
410412

411413
```nu
412414
help commands | where is_const
413415
```
414416

417+
When a line in the REPL uses only these commands, the [status line](./line_editor.md#status-line) previews its value as you type.
418+
415419
:::
416420

417421
For example, the `path join` command can output a constant value. Nushell also defines several useful paths in the `$nu` constant record. These can be combined to create useful parse-time constant evaluations like:

‎book/line_editor.md‎

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Nushell's line-editor [Reedline](https://github.com/nushell/reedline) is
44
cross-platform and designed to be modular and flexible. The line-editor is
55
in charge of controlling the command history, validations, completions, hints,
6-
screen paint, and more.
6+
the status line, screen paint, and more.
77

88
[[toc]]
99

@@ -460,6 +460,81 @@ $env.config.hinter.closure = {|ctx|
460460

461461
Set `$env.config.hinter.closure = null` to go back to the built-in history hints.
462462

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+
463538
## Customizing the Prompt
464539

465540
The Reedline prompt is configured using a number of environment variables. See [Prompt Configuration](./configuration.md#prompt-configuration) for details.

0 commit comments

Comments
 (0)