Skip to content

Commit

Permalink
ResponseBodyFormatter is now ResponseFormatter again
Browse files Browse the repository at this point in the history
  • Loading branch information
mre committed Jun 14, 2024
1 parent bfc921d commit 5583d21
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lychee-bin/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use lychee_lib::{ResponseBody, Status};

use crate::archive::{Archive, Suggestion};
use crate::formatters::get_response_formatter;
use crate::formatters::response::ResponseBodyFormatter;
use crate::formatters::response::ResponseFormatter;
use crate::verbosity::Verbosity;
use crate::{cache::Cache, stats::ResponseStats, ExitCode};

Expand Down Expand Up @@ -181,7 +181,7 @@ async fn progress_bar_task(
mut recv_resp: mpsc::Receiver<Response>,
verbose: Verbosity,
pb: Option<ProgressBar>,
formatter: Box<dyn ResponseBodyFormatter>,
formatter: Box<dyn ResponseFormatter>,
mut stats: ResponseStats,
) -> Result<(Option<ProgressBar>, ResponseStats)> {
while let Some(response) = recv_resp.recv().await {
Expand Down Expand Up @@ -298,7 +298,7 @@ fn show_progress(
output: &mut dyn Write,
progress_bar: &Option<ProgressBar>,
response: &Response,
formatter: &dyn ResponseBodyFormatter,
formatter: &dyn ResponseFormatter,
verbose: &Verbosity,
) -> Result<()> {
let out = formatter.format_response(response.body());
Expand Down
4 changes: 2 additions & 2 deletions lychee-bin/src/formatters/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub(crate) mod log;
pub(crate) mod response;
pub(crate) mod stats;

use self::{response::ResponseBodyFormatter, stats::StatsFormatter};
use self::{response::ResponseFormatter, stats::StatsFormatter};
use crate::options::{OutputMode, StatsFormat};
use supports_color::Stream;

Expand All @@ -29,7 +29,7 @@ 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 ResponseBodyFormatter> {
pub(crate) fn get_response_formatter(mode: &OutputMode) -> Box<dyn ResponseFormatter> {
if !supports_color() {
return Box::new(response::PlainFormatter);
}
Expand Down
4 changes: 2 additions & 2 deletions lychee-bin/src/formatters/response/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ use lychee_lib::{CacheStatus, ResponseBody, Status};

use crate::formatters::color::{DIM, GREEN, NORMAL, PINK, YELLOW};

use super::{ResponseBodyFormatter, MAX_RESPONSE_OUTPUT_WIDTH};
use super::{ResponseFormatter, MAX_RESPONSE_OUTPUT_WIDTH};

/// A colorized formatter for the response body
///
/// This formatter is used when the terminal supports color and the user
/// has not explicitly requested raw, uncolored output.
pub(crate) struct ColorFormatter;

impl ResponseBodyFormatter for ColorFormatter {
impl ResponseFormatter for ColorFormatter {
fn format_response(&self, body: &ResponseBody) -> String {
// Determine the color based on the status.
let status_color = match body.status {
Expand Down
4 changes: 2 additions & 2 deletions lychee-bin/src/formatters/response/emoji.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use lychee_lib::{CacheStatus, ResponseBody, Status};

use super::ResponseBodyFormatter;
use super::ResponseFormatter;

/// An emoji formatter for the response body
///
/// This formatter replaces certain textual elements with emojis for a more
/// visual output.
pub(crate) struct EmojiFormatter;

impl ResponseBodyFormatter for EmojiFormatter {
impl ResponseFormatter for EmojiFormatter {
fn format_response(&self, body: &ResponseBody) -> String {
let emoji = match body.status {
Status::Ok(_) | Status::Cached(CacheStatus::Ok(_)) => "✅",
Expand Down
2 changes: 1 addition & 1 deletion lychee-bin/src/formatters/response/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ pub(crate) const MAX_RESPONSE_OUTPUT_WIDTH: usize = 10;
/// This trait is used to convert response body into a human-readable string.
/// It can be implemented for different formatting styles such as
/// colorized output or plaintext.
pub(crate) trait ResponseBodyFormatter: Send + Sync {
pub(crate) trait ResponseFormatter: Send + Sync {
fn format_response(&self, body: &ResponseBody) -> String;
}
4 changes: 2 additions & 2 deletions lychee-bin/src/formatters/response/plain.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use lychee_lib::ResponseBody;

use super::ResponseBodyFormatter;
use super::ResponseFormatter;

/// A basic formatter that just returns the response body as a string
/// without any color codes or other formatting.
Expand All @@ -12,7 +12,7 @@ use super::ResponseBodyFormatter;
/// or when the terminal does not support color.
pub(crate) struct PlainFormatter;

impl ResponseBodyFormatter for PlainFormatter {
impl ResponseFormatter for PlainFormatter {
fn format_response(&self, body: &ResponseBody) -> String {
body.to_string()
}
Expand Down

0 comments on commit 5583d21

Please sign in to comment.