mirror of
https://github.com/Hopiu/lychee.git
synced 2026-04-15 19:00:58 +00:00
parent
d3d7f6a56b
commit
7c4b1325cd
3 changed files with 21 additions and 3 deletions
|
|
@ -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(¶ms.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(¶ms.cfg.mode) {
|
||||
¶ms.cfg.mode
|
||||
} else {
|
||||
&formatter_default
|
||||
});
|
||||
|
||||
let show_results_task = tokio::spawn(progress_bar_task(
|
||||
recv_resp,
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in a new issue