Skip to content

refactor: progress bar#1914

Merged
thomas-zahner merged 13 commits into
lycheeverse:masterfrom
thomas-zahner:refactor-progress-bar
Nov 27, 2025
Merged

refactor: progress bar#1914
thomas-zahner merged 13 commits into
lycheeverse:masterfrom
thomas-zahner:refactor-progress-bar

Conversation

@thomas-zahner

@thomas-zahner thomas-zahner commented Nov 11, 2025

Copy link
Copy Markdown
Member

Clone of #1835 with one additional commit with the review comments resolved. Then the main work - more refactoring. The PR retains the current behaviour as much as possible. The only notable behavioural difference is that the bar no longer uses enable_steady_tick and the spinner animation has been removed as described in the summary comment.

Closes #1736

Comment thread lychee-bin/src/commands/check.rs Outdated
@thomas-zahner thomas-zahner requested a review from mre November 11, 2025 14:59
@thomas-zahner thomas-zahner force-pushed the refactor-progress-bar branch 3 times, most recently from ec8d326 to 906c708 Compare November 12, 2025 12:45
rodic and others added 6 commits November 12, 2025 15:11
Not refreshing the bar when no progress happens,
improves usability when awaiting user input from stdin. (`lychee -`)
Also add a debugging statement as users might wonder why lychee blocks.
Comment thread lychee-bin/src/commands/check.rs Outdated
Comment thread lychee-bin/src/commands/check.rs Outdated
Comment thread lychee-bin/src/progress.rs Outdated
The only resulting difference is that the progress bar message
now shows the response detailed, which only affects erroneous
link check results. So in practice the difference is barely noticeable
while reducing complexity qute a bit.
@thomas-zahner

thomas-zahner commented Nov 14, 2025

Copy link
Copy Markdown
Member Author

Summary

@mre I realised that not showing the progress bar as requested in #1736 is not feasible. What bothered me the most, is that the progress bar was clogging up stdin when waiting for user input with lychee -. This way the UX is pretty bad when manually typing something or pasting content, as the progress bar overwrites any input.

So I mostly explored 2 ideas when working on this PR.

  1. Change the timing when the progress bar was displayed as it seemed wrong to me initially.
  2. Fully hide the progress bar if waiting for stdin.

As the link collection and checking is so highly async it means that we had to introduce some special handling for stdin. We would have to make sure that the stdin element would always be the first input that is checked. This would require a huge effort for such a minimal issue as everything is so async and it would increase complexity in the codebase. For example running cargo run - README you can see how it is nondeterministic whether README is checked before blocking for stdin or the other way around.

With this in mind I thought about the second approach. But this doesn't work either because of the concurrency. We would basically have to hide the progress as with --no-progress as soon as stdin is present as input. But this wouldn't make sense because it would fully hide the progress for all inputs, e.g. also for README with cargo run - README

This is why I came up with the simple solution of removing enable_steady_tick for the progress bar. This means the progress bar is shown the same way but there is no longer a thread in the background which clutters the terminal if we block on stdin. Simple solution for a simple problem. 😅 I've also disabled the spinner animation as it might look like lychee got stuck if the animation doesn't steadily tick.

I've spent more time on this than I should admit but I've also refactored and simplified the code around progress quite a bit.

@mre

mre commented Nov 18, 2025

Copy link
Copy Markdown
Member

This is why I came up with the simple solution of removing enable_steady_tick for the progress bar. This means the progress bar is shown the same way but there is no longer a thread in the background which clutters the terminal if we block on stdin. Simple solution for a simple problem.

Sorry, I don't quite understand what you mean by "thread in the background." 😅 What is the architectural advantage of that approach? One thread less I guess? But how does it avoid cluttering the terminal?

I've spent more time on this than I should admit but I've also refactored and simplified the code around progress quite a bit.

Thanks for that! It looks much cleaner.

One more rebase and we can merge this I guess. Good work!

@thomas-zahner

Copy link
Copy Markdown
Member Author

Sorry, I don't quite understand what you mean by "thread in the background." 😅 What is the architectural advantage of that approach? One thread less I guess? But how does it avoid cluttering the terminal?

It's not really about an architectural advantage (though one thread less is nice as well) but about UX. Try running cargo run -. Conceptually, it should behave the same as running cat or sort. lychee waits for user input to be link checked until pressing CTRL+D. Compare it with the current release and this PR. Without this PR the progress bar continuously overwrites any user input because of the background thread. See the difference in this recording.

asciicast

@thomas-zahner thomas-zahner merged commit caf63cc into lycheeverse:master Nov 27, 2025
7 checks passed
@mre mre mentioned this pull request Nov 27, 2025
mre added a commit that referenced this pull request Nov 27, 2025
In #1914, work was done to hide the
progress bar on `stdin`. The simple solution of removing enable_steady_tick for
the progress bar. This worked well for avoiding cluttering the output while the
user typed their input.

However, the initial progress bar still gets shown, which is not ideal. This
commit slightly imporves the behavior by waiting for all inputs before showing
the progress bar. We do this by iterating over the inputs and checking if any
of them is `stdin`.

This way, the progress bar does no longer get shown. To start the processing,
the user has to press Ctrl^D, which is customs for other Unix tools as well.
Other behavior remains unchanged.
@mre mre mentioned this pull request Dec 5, 2025
mre added a commit that referenced this pull request Mar 13, 2026
In #1914, work was done to hide the
progress bar on `stdin`. The simple solution of removing enable_steady_tick for
the progress bar. This worked well for avoiding cluttering the output while the
user typed their input.

However, the initial progress bar still gets shown, which is not ideal. This
commit slightly imporves the behavior by waiting for all inputs before showing
the progress bar. We do this by iterating over the inputs and checking if any
of them is `stdin`.

This way, the progress bar does no longer get shown. To start the processing,
the user has to press Ctrl^D, which is customs for other Unix tools as well.
Other behavior remains unchanged.
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.

Don't update progress bar when waiting for user input

3 participants