Fix Porgressbar rendering Checkbox (Fixes #1626) (#1627)

* fixes #1610
This commit is contained in:
Ben 2025-02-07 00:05:21 +01:00 committed by GitHub
parent d3d7f6a56b
commit 7c4b1325cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 3 deletions

View file

@ -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};
@ -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,

View file

@ -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),
};
}
match mode {
OutputMode::Plain => Box::new(response::PlainFormatter),

View file

@ -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.