## Description
Fixes#19519
`input listen --raw` and `std/input display --raw` both documented a
`raw_flags` field that does not exist. The implementation emits
`raw_modifiers` instead:
```console
$ printf 'a' | script -qfec "nu -n -c 'input listen --types [key] --raw | to nuon'" /dev/null
{type: key, key_type: char, code: a, modifiers: [], raw_code: 97, raw_modifiers: 0}
$ printf '\033OP' | script -qfec "nu -n -c 'input listen --types [key] --raw | to nuon'" /dev/null
{type: key, key_type: f, code: "1", modifiers: [], raw_modifiers: 0}
```
So `raw_modifiers` is added to key and mouse events, while `raw_code` is
added
only for character keys (`create_key_event` pushes it inside
`if let KeyCode::Char(c)`). The old help said neither of these.
This also fixes two related gaps in `extra_description`:
- It listed "4 `key_type` variants", but `get_keycode_name` has a fifth,
`KeyCode::Modifier(m) => "modifier"` (crossterm maps these through the
kitty
keyboard protocol, e.g. `ModifierKeyCode::LeftShift`).
- It listed the five base event shapes without mentioning the extra
fields
added under `--raw`.
Help text only — no behavior change. Two files:
`crates/nu-command/src/platform/input/input_listen.rs` and
`crates/nu-std/std/input/mod.nu`.
## User-facing changes (Release notes)
- n/a (documentation only; no behavior change)
## Additional notes
- Verified with a rebuilt `nu` binary that `help input listen` and
`help display` render the corrected text, and that `--raw` output is
unchanged for both a character key and F1.
- `cargo test -p nu-command --lib`: 953 passed / 0 failed / 2 ignored.
Example tests: 261 passed / 0 failed. `cargo fmt --check` and the
`typos`
check on both changed files are clean.
- Related: #15868 (older report about `input listen`'s wrong output-type
docs),
#19513 (the output-type fix). This PR does not close either.
Co-authored-by: wangjianjun <passionworkeer@users.noreply.github.com>
Co-authored-by: wangjianjun <opuswang@tencent.com>
## Description
`input listen` returns a different record for each event type: focus,
key, mouse, paste and resize. Its signature declared the key event
record as the only output type. `let` checks the value against that type
at runtime (`enforce-runtime-annotations`, on by default since 0.114.0),
so any event other than a key press failed with a type mismatch.
`std/input display` stores each event with `let`, so focusing the
window, moving the mouse, pasting or resizing all stopped it.
You only see this when the first event isn't a key press. Some terminals
send a focus report as soon as an app turns on focus reporting, and in
those terminals `display` fails before you press anything.
This PR declares the output type as `record`, and fixes three related
problems:
- `display`'s formatter used `str substring 1..-1` to strip both braces
from the `to nuon` text. Ranges include their end, so the closing brace
stayed.
- `input listen` turned off mouse capture, bracketed paste, focus
reporting and the kitty keyboard flags only when it returned an event. A
timeout or a read error returned early and left them all on. A guard now
turns them off on every return path, including a failure partway through
turning them on.
- `input listen --types []` turned on no event types, so it could never
return an event. It waited until `--timeout`, or forever without one. An
empty `--types` is now an error, like an unknown event type or a
non-list value, and it fails before `input listen` changes any terminal
mode.
- The help text called the `--raw` field `raw_flags` (it's
`raw_modifiers`), and it left out the `modifier` key type and the
`--raw` fields. Now that the output type is a plain `record`, the help
text is the only place the fields are listed.
## User-facing changes (Release notes)
- `let x = input listen` works for every event type. It used to fail
with a type mismatch on focus, mouse, paste and resize events.
- `std/input display` prints focus, mouse, paste and resize events
instead of stopping with a type mismatch, and lines no longer end with a
stray `}`.
- `input listen --types []` fails right away with "--types expects at
least one event type". It used to wait until the timeout, or forever
without one.
- `input listen` no longer leaves mouse capture, bracketed paste, focus
reporting or kitty keyboard flags turned on after it times out or fails.
## Additional notes
- closes#19507
- closes#19520
- Some terminals send a focus report every time focus reporting is
turned on. There, `display` prints `focus gained` over and over, because
each `input listen` call turns focus reporting on again, and plain
`input listen` returns that report right away. The help for both
commands now says to leave `focus` out of `--types`, which keeps focus
reporting off: `input display --types [key mouse paste resize]`.
# Description
Uses "normal" module `std/<submodule>/mod.nu` instead of renaming the
files (as requested in #13842).
# User-Facing Changes
No user-facing changes other than in `view files` results. Imports
remain the same after this PR.
# Tests + Formatting
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`
Also manually confirmed that it does not interfere with nupm, since we
did have a conflict at one point (and it's not possible to test here).
# Performance Tests
## Linux
### Nushell Startup - No config
```nu
bench --pretty -n 200 { <path_to>/nu -c "exit" }
```
| Release | Startup Time |
| --- | --- |
| 0.98.0 | 22ms 730µs 768ns +/- 1ms 515µs 942ns
| This commit | 9ms 312µs 68ns +/- 709µs 378ns
| Yesterday's nightly | 9ms 230µs 953ns +/- 9ms 67µs 689ns
### Nushell Startup - Load full standard library
Measures relative impact of a full `use std *`, which isn't recommended,
but worth tracking.
```nu
bench --pretty -n 200 { <path_to>/nu -c "use std *; exit" }
```
| Release | Startup Time |
| --- | --- |
| 0.98.0 | 23ms 10µs 636ns +/- 1ms 277µs 854ns
| This commit | 26ms 922µs 769ns +/- 562µs 538ns
| Yesterday's nightly | 28ms 133µs 95ns +/- 761µs 943ns
| `deprecated_dirs` removal PR * | 23ms 610µs 333ns +/- 369µs 436ns
\* Current increase is partially due to double-loading `dirs` with
removal warning in older version.
# After Submitting
Still TODO - Update standard library doc