Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Porgressbar rendering Checkbox (Fixes #1626) #1627

Merged
merged 14 commits into from
Feb 6, 2025
13 changes: 12 additions & 1 deletion lychee-bin/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use lychee_lib::{ResponseBody, Status};
use crate::archive::{Archive, Suggestion};
use crate::formatters::get_response_formatter;
use crate::formatters::response::ResponseFormatter;
use crate::options::OutputMode;
use crate::parse::parse_duration_secs;
use crate::verbosity::Verbosity;
use crate::{cache::Cache, stats::ResponseStats, ExitCode};
Expand Down Expand Up @@ -66,7 +67,17 @@ where
accept,
));

let formatter = get_response_formatter(&params.cfg.mode);
// Set the default formatter for progress bar output
let formatter_default = OutputMode::default();

// Make it easier to add new formatters in the future (without breaking the progress bar)
let allowed_output_modes = [OutputMode::Emoji, OutputMode::Plain, OutputMode::Color];

let formatter = get_response_formatter(if allowed_output_modes.contains(&params.cfg.mode) {
&params.cfg.mode
} else {
&formatter_default
});

let show_results_task = tokio::spawn(progress_bar_task(
recv_resp,
Expand Down
7 changes: 6 additions & 1 deletion lychee-bin/src/formatters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ pub(crate) fn get_stats_formatter(

/// Create a response formatter based on the given format option
pub(crate) fn get_response_formatter(mode: &OutputMode) -> Box<dyn ResponseFormatter> {
// Checks if color is supported in current environment or NO_COLOR is set (https://no-color.org)
if !supports_color() {
return Box::new(response::PlainFormatter);
// To fix `TaskFormatter` not working if color is not supported
return match mode {
OutputMode::Task => Box::new(response::TaskFormatter),
_ => Box::new(response::PlainFormatter),
};
Arteiii marked this conversation as resolved.
Show resolved Hide resolved
}
match mode {
OutputMode::Plain => Box::new(response::PlainFormatter),
Expand Down
4 changes: 3 additions & 1 deletion lychee-bin/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ impl FromStr for StatsFormat {
///
/// This decides over whether to use color,
/// emojis, or plain text for the output.
#[derive(Debug, Deserialize, Default, Clone, Display, EnumIter, EnumString, VariantNames)]
#[derive(
Debug, Deserialize, Default, Clone, Display, EnumIter, EnumString, VariantNames, PartialEq,
)]
#[non_exhaustive]
pub(crate) enum OutputMode {
/// Plain text output.
Expand Down