forked from extern/nushell
87717b9ddd
# Description <!-- Thank you for improving Nushell. Please, check our [contributing guide](../CONTRIBUTING.md) and talk to the core team before making major changes. Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience. --> moonlander pointed out in Discord that the transient prompt feature added in release 0.86 (implemented in #10391) is causing the normal prompt to be redrawn when the transient prompt variables are unset or set to null. This PR is for fixing that, although it's more of a bandaid fix. Maybe the transient prompt feature should be taken out entirely for now so more thought can be given to its implementation. Previously, I'd thought that when reedline redraws the prompt after a command is entered, it's a whole new prompt, but apparently it's actually the same prompt as the current line (?). So now, `nu_prompt` in `repl.rs` is an `Arc<RwLock<NushellPrompt>>` (rather than just a `NushellPrompt`), and this `Arc` is shared with the `TransientPrompt` object so that if it can't find one of the `TRANSIENT_PROMPT_*` variables, it uses a segment from `NushellPrompt` rather than re-evaluate `PROMPT_COMMAND`, `PROMPT_COMMAND_RIGHT`, etc. Using an `RwLock` means that there's a bunch of `.expect()`s all over the place, which is not nice. It could perhaps be avoided with some changes on the reedline side. # User-Facing Changes <!-- List of all changes that impact the user experience here. This helps us keep track of breaking changes. --> `$env.PROMPT_COMMAND` (and other such variables) should no longer be executed twice if the corresponding `$env.TRANSIENT_PROMPT_*` variable is not set. <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass (on Windows make sure to [enable developer mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging)) - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # Steps to reproduce Described by moonlander in Discord [here](https://discord.com/channels/601130461678272522/614593951969574961/1164928022126792844). Adding this to `env.nu` will result in `11` being added to `/tmp/run_count` every time any command is run. The expected behavior is a single `1` being added to `/tmp/run_count` instead of two. The prompt command should not be executed again when the prompt is redrawn after a command is executed. ```nu $env.PROMPT_COMMAND = {|| touch /tmp/run_count '1' | save /tmp/run_count --append '>' } # $env.TRANSIENT_PROMPT_COMMAND not set ``` If the following is added to `env.nu`, then `12` will be added to `/tmp/run_count` every time any command is run, which is expected behavior because the normal prompt command must be displayed the first time the prompt is shown, then the transient prompt command is run when the prompt is redrawn. ```nu $env.TRANSIENT_PROMPT_COMMAND = {|| touch /tmp/run_count '2' | save /tmp/run_count --append '>' } ``` Here's a screenshot of what adding that first snippet looks like (`cargo run` in the `main` branch): ![image](https://github.com/nushell/nushell/assets/45539777/b27a5c07-55b4-43c7-8a2c-0deba2d9d53a) Here's a screenshot of what it looks like with this PR (only one `1` is added to `/tmp/run_count` each time): ![image](https://github.com/nushell/nushell/assets/45539777/2b5c0a3a-8566-4428-9fda-1ffcc1dd6ae3) |
||
---|---|---|
.. | ||
nu_plugin_custom_values | ||
nu_plugin_example | ||
nu_plugin_formats | ||
nu_plugin_gstat | ||
nu_plugin_inc | ||
nu_plugin_python | ||
nu_plugin_query | ||
nu-cli | ||
nu-cmd-base | ||
nu-cmd-dataframe | ||
nu-cmd-extra | ||
nu-cmd-lang | ||
nu-color-config | ||
nu-command | ||
nu-engine | ||
nu-explore | ||
nu-glob | ||
nu-json | ||
nu-lsp | ||
nu-parser | ||
nu-path | ||
nu-plugin | ||
nu-pretty-hex | ||
nu-protocol | ||
nu-std | ||
nu-system | ||
nu-table | ||
nu-term-grid | ||
nu-test-support | ||
nu-utils | ||
README.md |
Nushell core libraries and plugins
These sub-crates form both the foundation for Nu and a set of plugins which extend Nu with additional functionality.
Foundational libraries are split into two kinds of crates:
- Core crates - those crates that work together to build the Nushell language engine
- Support crates - a set of crates that support the engine with additional features like JSON support, ANSI support, and more.
Plugins are likewise also split into two types:
- Core plugins - plugins that provide part of the default experience of Nu, including access to the system properties, processes, and web-connectivity features.
- Extra plugins - these plugins run a wide range of different capabilities like working with different file types, charting, viewing binary data, and more.