Skip to content

Refactor progress bar#1835

Closed
rodic wants to merge 18 commits into
lycheeverse:masterfrom
rodic:refactor-progress-bar
Closed

Refactor progress bar#1835
rodic wants to merge 18 commits into
lycheeverse:masterfrom
rodic:refactor-progress-bar

Conversation

@rodic

@rodic rodic commented Sep 1, 2025

Copy link
Copy Markdown
Contributor

Refactor of progress‑bar

  • Introduced LycheeProgressBar – a thin wrapper around the indicatif library that centralises all progress‑bar logic (configuration, styling, ticking, length handling, and finishing).
  • Replaced scattered direct usages of ProgressBar with the new wrapper, improving readability and making future UI changes easier to manage.
  • Added a dedicated configuration struct (LycheeProgressBarConfig) with sensible defaults (template, increment step, tick interval, progress characters).
  • Tests

rodic added 17 commits August 25, 2025 11:05
Print parameter is unnecessary. When the log level is set to info or higher:

- we don’t use the progress bar while checking links.
- we do use the progress bar when suggesting alternatives,
  but that code path does not invoke update.
- Introduced `LycheeProgressBarConfig` to hold all progress‑bar settings
  (template, increment, tick interval, progress characters) instead of
  scattering them as associated constants inside `LycheeProgressBar`.
- The wrapper now stores a `cfg: LycheeProgressBarConfig` instance.
- Added a `Default` implementation for `LycheeProgrssBarConfig` so
  existing callers continue to work unchanged.
The function can be replaced with set_length. It also doesn't need to print request next to the bar
@rodic rodic force-pushed the refactor-progress-bar branch 2 times, most recently from fdc3ea7 to 127fcf8 Compare September 1, 2025 14:35
let request = request?;
if let Some(pb) = &bar {
pb.inc_length(1);
pb.set_message(request.to_string());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think we need to set msg here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep it IMO because showing the extracted links and not only the link after having checked it, makes sense in my opinion.

@thomas-zahner thomas-zahner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Extracting the progress bar into a new struct and file does make sense and improves readability and maintainability 👍

let request = request?;
if let Some(pb) = &bar {
pb.inc_length(1);
pb.set_message(request.to_string());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep it IMO because showing the extracted links and not only the link after having checked it, makes sense in my opinion.

Comment on lines +181 to +192
let mut request_count = 0;
while let Some(request) = requests.next().await {
let request = request?;
if let Some(pb) = &bar {
pb.inc_length(1);
pb.set_message(request.to_string());
}
request_count += 1;
send_req
.send(Ok(request))
.await
.expect("Cannot send request");
}
if let Some(pb) = &bar {
pb.set_length(request_count);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original version of this section made more sense. Extracting the links from the inputs (and awaiting the requests, before executing the requests) and displaying the result after having executed the request are two independent highly concurrent processes. Because of that the progress bar size grows, even as we are already performing requests. So setting the progress bar length only after all requests were created makes no sense.

Run cargo run fixtures/ with your PR version and you will see, how the progress bar remains at 0 during the whole link check process, displaying something like 2114/0.

pub(crate) fn update(&self, message: Option<String>) {
self.bar.inc(self.config.increment);
if let Some(msg) = message {
self.bar.set_message(msg.clone());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to clone here

@rodic

rodic commented Sep 10, 2025

Copy link
Copy Markdown
Contributor Author

@thomas-zahner thanks a lot for reviewing this. I'm going to address the comments as soon as I can. I'm a bit busy these days, so sorry for the late response.

}

#[derive(Clone)]
pub(crate) struct LycheeProgressBar {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we call it ProgressBar instead? I think the Lychee is sort of implied. 😉 Same for the filename.

@mre

mre commented Sep 25, 2025

Copy link
Copy Markdown
Member

@rodic any updates?

@rodic

rodic commented Oct 1, 2025

Copy link
Copy Markdown
Contributor Author

I'm sorry @mre i'll try to get it done this week.

@mre

mre commented Oct 1, 2025

Copy link
Copy Markdown
Member

Ah no worries and no rush. Just wanted to avoid that this awesome work goes stale.

@rodic

rodic commented Oct 23, 2025

Copy link
Copy Markdown
Contributor Author

i apologize again for being late, i didn't forget about it :)

@thomas-zahner

Copy link
Copy Markdown
Member

@rodic I'm closing this in favour of #1914

There I've squashed this PR into one commit and dug a big deeper with refactoring. Thanks for the PR!

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.

3 participants