mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 19:07:42 +02:00
Progress bar Implementation (#7661)
# Description _(Description of your pull request goes here. **Provide examples and/or screenshots** if your changes affect the user experience.)_ I implemented the status bar we talk about yesterday. The idea was inspired by the progress bar of `wget`. I decided to go for the second suggestion by `@Reilly` > 2. add an Option<usize> or whatever to RawStream (and ListStream?) for situations where you do know the length ahead of time For now only works with the command `save` but after the approve of this PR we can see how we can implement it on commands like `cp` and `mv` When using `fetch` nushell will check if there is any `content-length` attribute in the request header. If so, then `fetch` will send it through the new `Option` variable in the `RawStream` to the `save`. If we know the total size we show the progress bar  but if we don't then we just show the stats like: data already saved, bytes per second, and time lapse.   Please let me know If I need to make any changes and I will be happy to do it. # User-Facing Changes A new flag (`--progress` `-p`) was added to the `save` command Examples: ```nu fetch https://github.com/torvalds/linux/archive/refs/heads/master.zip | save --progress -f main.zip fetch https://releases.ubuntu.com/22.04.1/ubuntu-22.04.1-desktop-amd64.iso | save --progress -f main.zip open main.zip --raw | save --progress main.copy ``` # Tests + Formatting 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 -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - I am getting some errors and its weird because the errors are showing up in files i haven't touch. Is this normal? # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
This commit is contained in:
@ -361,6 +361,26 @@ fn response_to_buffer(
|
||||
engine_state: &EngineState,
|
||||
span: Span,
|
||||
) -> nu_protocol::PipelineData {
|
||||
// Try to get the size of the file to be downloaded.
|
||||
// This is helpful to show the progress of the stream.
|
||||
let buffer_size = match &response.headers().get("content-length") {
|
||||
Some(content_length) => {
|
||||
let content_length = &(*content_length).clone(); // binding
|
||||
|
||||
let content_length = content_length
|
||||
.to_str()
|
||||
.unwrap_or("")
|
||||
.parse::<u64>()
|
||||
.unwrap_or(0);
|
||||
|
||||
if content_length == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(content_length)
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let buffered_input = BufReader::new(response);
|
||||
|
||||
PipelineData::ExternalStream {
|
||||
@ -370,6 +390,7 @@ fn response_to_buffer(
|
||||
}),
|
||||
engine_state.ctrlc.clone(),
|
||||
span,
|
||||
buffer_size,
|
||||
)),
|
||||
stderr: None,
|
||||
exit_code: None,
|
||||
|
@ -415,6 +415,7 @@ fn response_to_buffer(
|
||||
}),
|
||||
engine_state.ctrlc.clone(),
|
||||
span,
|
||||
None,
|
||||
)),
|
||||
stderr: None,
|
||||
exit_code: None,
|
||||
|
Reference in New Issue
Block a user