mirror of
https://github.com/nushell/nushell.git
synced 2025-07-01 07:00:37 +02:00
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 ```
This commit is contained in:
@ -147,6 +147,7 @@ pub struct EngineState {
|
||||
pub regex_cache: Arc<Mutex<LruCache<String, Regex>>>,
|
||||
pub is_interactive: bool,
|
||||
pub is_login: bool,
|
||||
startup_time: i64,
|
||||
}
|
||||
|
||||
// The max number of compiled regexes to keep around in a LRU cache, arbitrarily chosen
|
||||
@ -199,6 +200,7 @@ impl EngineState {
|
||||
))),
|
||||
is_interactive: false,
|
||||
is_login: false,
|
||||
startup_time: -1,
|
||||
}
|
||||
}
|
||||
|
||||
@ -1015,6 +1017,14 @@ impl EngineState {
|
||||
pub fn get_file_contents(&self) -> &Vec<(Vec<u8>, usize, usize)> {
|
||||
&self.file_contents
|
||||
}
|
||||
|
||||
pub fn get_startup_time(&self) -> i64 {
|
||||
self.startup_time
|
||||
}
|
||||
|
||||
pub fn set_startup_time(&mut self, startup_time: i64) {
|
||||
self.startup_time = startup_time;
|
||||
}
|
||||
}
|
||||
|
||||
/// A temporary extension to the global state. This handles bridging between the global state and the
|
||||
|
Reference in New Issue
Block a user