nushell/crates/nu-cli/src
Antoine Stevan 4e78f3649b
FEATURE: add the startup time to $nu (#8353)
# Description
in https://github.com/nushell/nushell/issues/8311 and the discord
server, the idea of moving the default banner from the `rust` source to
the `nushell` standar library has emerged 😋

however, in order to do this, one need to have access to all the
variables used in the default banner => all of them are accessible
because known constants, except for the startup time of the shell, which
is not anywhere in the shell...

#### this PR adds exactly this, i.e. the new `startup_time` to the `$nu`
variable, which is computed to have the exact same value as the value
shown in the banner.

## the changes
in order to achieve this, i had to
- add `startup_time` as an `i64` to the `EngineState` => this is, to the
best of my knowledge, the easiest way to pass such an information around
down to where the banner startup time is computed and where the `$nu`
variable is evaluated
- add `startup-time` to the `$nu` variable and use the `EngineState`
getter for `startup_time` to show it as a `Value::Duration`
- pass `engine_state` as a `&mut`able argument from `main.rs` down to
`repl.rs` to allow the setter to change the value of `startup_time` =>
without this, the value would not change and would show `-1ns` as the
default value...
- the value of the startup time is computed in `evaluate_repl` in
`repl.rs`, only once at the beginning, and the same value is used in the
default banner 👌

# User-Facing Changes
one can now access to the same time as shown in the default banner with
```bash
$nu.startup-time
```

# Tests + Formatting
- 🟢 `cargo fmt --all`
- 🟢 `cargo clippy --workspace -- -D warnings -D
clippy::unwrap_used -A clippy::needless_collect`
- 🟢 `cargo test --workspace`

# After Submitting
```
$nothing
```
2023-03-09 14:18:58 -06:00
..
completions Resolve Clippy warnings inside tests. (#8315) 2023-03-04 14:58:20 +01:00
menus Use variable names directly in the format strings (#7906) 2023-01-29 19:37:54 -06:00
commands.rs Remove perf flag to streamline logging configuration (#6834) 2022-10-21 10:20:21 -05:00
config_files.rs respect use_ansi_coloring configuration (#7912) 2023-02-02 00:03:05 +01:00
eval_file.rs pipe binary data to external commands (#8058) 2023-02-24 21:39:52 +01:00
lib.rs Split merging of parser delta and stack environment (#6005) 2022-07-14 17:09:27 +03:00
nu_highlight.rs Remove engine_state clones in REPL eval (#7713) 2023-01-10 17:22:32 -08:00
print.rs print pipeline contents in print (#8305) 2023-03-04 11:31:01 +13:00
prompt_update.rs Use variable names directly in the format strings (#7906) 2023-01-29 19:37:54 -06:00
prompt.rs Make the default prompt play nice with basic fonts (#8080) 2023-03-02 13:59:32 +13:00
reedline_config.rs Use variable names directly in the format strings (#7906) 2023-01-29 19:37:54 -06:00
repl.rs FEATURE: add the startup time to $nu (#8353) 2023-03-09 14:18:58 -06:00
syntax_highlight.rs Support redirect err and out to different streams (#7685) 2023-01-12 10:22:30 +01:00
util.rs respect use_ansi_coloring configuration (#7912) 2023-02-02 00:03:05 +01:00
validation.rs Remove engine_state clones in REPL eval (#7713) 2023-01-10 17:22:32 -08:00