Skip to content

FEATURE: add the startup time to $nu - #8353

Merged
fdncred merged 6 commits into
nushell:mainfrom
amtoine:feature/add-startup-time-to-engine-state-and-nu-variable
Mar 9, 2023
Merged

fdncred merged 6 commits into
nushell:mainfrom
amtoine:feature/add-startup-time-to-engine-state-and-nu-variable

Conversation

@amtoine

@amtoine amtoine commented Mar 7, 2023

Copy link
Copy Markdown
Member

Description

in #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 &mutable 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

$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

amtoine added 4 commits March 7, 2023 19:36
This is the easiest way i found to carry the startup around without
changing a bunch of function arguments and function calls.
Important things to note:
- i broken the `if` statement into two part, to only comput the
startup_time once, otherwise, it would change as `nushell` gets
older and older...
- i use `EngineState.get_startup_time` in the banner to avoid re-
computing the time elapsed

> **Note**
> i'm not super happy with the `let config = & ... .clone();` thing
> but no idea how to make `cargo` happy here 🤔
> would love some feedback here!
This commit is here to allow `EngineState.set_startup_time` to
take effet globally.
Without these `&mut`, the `engine_state.startup_time` would not
change really...
@amtoine

amtoine commented Mar 7, 2023

Copy link
Copy Markdown
Member Author

this is the script i talk about 😋
and it needs the startup time to be an exact clone of the default banner of course 🤔
this is a very first pure-clone draft and it would have to be augmented, but that's the gist of it 😌

def banner [] {
$"(ansi green)     __  ,(ansi reset)
(ansi green) .--\(\)°'.' (ansi reset)Welcome to (ansi green)Nushell(ansi reset),
(ansi green)'|, . ,'   (ansi reset)based on the (ansi green)nu(ansi reset) language,
(ansi green) !_-\(_\\    (ansi reset)where all data is structured!

Please join our (ansi purple)Discord(ansi reset) community at (ansi purple)https://discord.gg/NtAbbGn(ansi reset)
Our (ansi green_bold)GitHub(ansi reset) repository is at (ansi green_bold)https://github.com/nushell/nushell(ansi reset)
Our (ansi green)Documentation(ansi reset) is located at (ansi green)https://nushell.sh(ansi reset)
(ansi cyan)Tweet(ansi reset) us at (ansi cyan_bold)@nu_shell(ansi reset)
Learn how to remove this at: (ansi green)https://nushell.sh/book/configuration.html#remove-welcome-message(ansi reset)

It's been this long since (ansi green)Nushell(ansi reset)'s first commit:
((date now) - ('2019-05-10 09:59:12-0700' | into datetime))

Startup Time: ($nu.startup-time)"
}

@fdncred

fdncred commented Mar 9, 2023

Copy link
Copy Markdown
Contributor

@amtoine There are some small fixes that need to happen so the CI goes green. Do you have time for those?

@amtoine

amtoine commented Mar 9, 2023

Copy link
Copy Markdown
Member Author

@amtoine There are some small fixes that need to happen so the CI goes green. Do you have time for those?

ooh i did not see the conflicts!
let me fix those 👌

@amtoine

amtoine commented Mar 9, 2023

Copy link
Copy Markdown
Member Author

no more conflicts but still issues...

and i cannot run the tests on my machine 'cause it overflows my RAM and swap 😭

@amtoine

amtoine commented Mar 9, 2023

Copy link
Copy Markdown
Member Author

okey it finally did compile, i can have a look at the issue 👍

@amtoine

amtoine commented Mar 9, 2023

Copy link
Copy Markdown
Member Author

i think this might be solved with 09ebf47 🤔

@codecov

codecov Bot commented Mar 9, 2023

Copy link
Copy Markdown

Codecov Report

Merging #8353 (09ebf47) into main (ccd72fa) will decrease coverage by 0.02%.
The diff coverage is 8.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8353      +/-   ##
==========================================
- Coverage   68.49%   68.48%   -0.02%     
==========================================
  Files         620      620              
  Lines       99480    99495      +15     
==========================================
- Hits        68139    68135       -4     
- Misses      31341    31360      +19     
Impacted Files Coverage Δ
crates/nu-cli/src/repl.rs 24.35% <0.00%> (-0.08%) ⬇️
src/main.rs 83.41% <0.00%> (ø)
src/run.rs 73.77% <0.00%> (ø)
crates/nu-protocol/src/engine/engine_state.rs 78.11% <14.28%> (-0.26%) ⬇️
crates/nu-engine/src/nu_variable.rs 35.52% <20.00%> (-0.53%) ⬇️

... and 3 files with indirect coverage changes

@amtoine

amtoine commented Mar 9, 2023

Copy link
Copy Markdown
Member Author

yeah 🥳

@fdncred
fdncred merged commit 4e78f36 into nushell:main Mar 9, 2023
@fdncred

fdncred commented Mar 9, 2023

Copy link
Copy Markdown
Contributor

Thanks!

@amtoine

amtoine commented Mar 10, 2023

Copy link
Copy Markdown
Member Author

Thanks!

👍

@amtoine
amtoine deleted the feature/add-startup-time-to-engine-state-and-nu-variable branch March 10, 2023 18:05
fdncred added a commit that referenced this pull request May 10, 2023
…ary (#8406)

Related to:
- #8311 
- #8353

# Description
with the new `$nu.startup-time` from #8353 and as mentionned in #8311,
we are now able to fully move the `nushell` banner from the `rust`
source base to the standard library.

this PR
- removes all the `rust` source code for the banner
- rewrites a perfect clone of the banner to `std.nu`, called `std
banner`
- call `std banner` from `default_config.nu`

# User-Facing Changes
see the demo: https://asciinema.org/a/566521

- no config will show the banner (e.g. `cargo run --release --
--no-config-file`)
- a custom config without the `if $env.config.show_banner` block and no
call to `std banner` would never show the banner
- a custom config with the block and `config.show_banner = true` will
show the banner
- a custom config with the block and `config.show_banner = false` will
NOT show the banner

# Tests + Formatting
a new test line has been added to `tests.nu` to check the length of the
`std banner` output.
- 🟢 `toolkit fmt`
- 🟢 `toolkit clippy`
- 🟢 `toolkit test`
- 🟢 `toolkit test stdlib`

# After Submitting
```
$nothing
```

---------

Co-authored-by: Darren Schroeder <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants