From 20f43906ea316bfa4a5e1e80361fb4df14df4991 Mon Sep 17 00:00:00 2001 From: Ossama Hjaji Date: Sun, 2 Apr 2023 23:42:41 +0200 Subject: [PATCH] replace --show-logo with --no-art (#1002) --- Cargo.lock | 11 ----------- Cargo.toml | 1 - src/cli.rs | 27 +++++++++++++-------------- src/info/mod.rs | 2 +- src/ui/printer.rs | 17 ++--------------- 5 files changed, 16 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0b9f826f6..ee9c656fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2190,7 +2190,6 @@ dependencies = [ "serde_yaml", "strum", "tera", - "terminal_size", "time", "time-humanize", "tokei", @@ -2984,16 +2983,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "terminal_size" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb20089a8ba2b69debd491f8d2d023761cbf196e999218c591fa1e7e15a21907" -dependencies = [ - "rustix", - "windows-sys 0.42.0", -] - [[package]] name = "textwrap" version = "0.11.0" diff --git a/Cargo.toml b/Cargo.toml index f520c7369..77de999a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,6 @@ serde_yaml = "0.9.19" # TODO With the new value parsers, we're really close to being able to eliminate # the strum dependency strum = { version = "0.24.1", features = ["derive"] } -terminal_size = "0.2" time = { version = "0.3.17", features = ["formatting"] } time-humanize = { version = "0.1.3", features = ["time"] } tokei = "12.1.2" diff --git a/src/cli.rs b/src/cli.rs index fac567829..7c69e1c27 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -30,12 +30,12 @@ pub struct CliOptions { #[command(flatten)] pub text_formatting: TextForamttingCliOptions, #[command(flatten)] - pub color_blocks: ColorBlocksCliOptions, - #[command(flatten)] pub ascii: AsciiCliOptions, #[command(flatten)] pub image: ImageCliOptions, #[command(flatten)] + pub visuals: VisualsCliOptions, + #[command(flatten)] pub developer: DeveloperCliOptions, #[command(flatten)] pub other: OtherCliOptions, @@ -124,11 +124,6 @@ pub struct AsciiCliOptions { /// If set to auto: true color will be enabled if supported by the terminal #[arg(long, default_value = "auto", value_name = "WHEN", value_enum)] pub true_color: When, - /// Specify when to show the logo - /// - /// If set to auto: the logo will be hidden if the terminal's width < 95 - #[arg(long, default_value = "always", value_name = "WHEN", value_enum)] - pub show_logo: When, } #[derive(Clone, Debug, Args, PartialEq, Eq)] @@ -181,11 +176,14 @@ pub struct TextForamttingCliOptions { pub no_bold: bool, } #[derive(Clone, Debug, Args, PartialEq, Eq, Default)] -#[command(next_help_heading = "COLOR BLOCKS")] -pub struct ColorBlocksCliOptions { +#[command(next_help_heading = "VISUALS")] +pub struct VisualsCliOptions { /// Hides the color palette #[arg(long)] pub no_color_palette: bool, + /// Hides the ascii art or image if provided + #[arg(long)] + pub no_art: bool, } #[derive(Clone, Debug, Args, PartialEq, Eq, Default)] @@ -216,7 +214,7 @@ impl Default for CliOptions { input: PathBuf::from("."), info: InfoCliOptions::default(), text_formatting: TextForamttingCliOptions::default(), - color_blocks: ColorBlocksCliOptions::default(), + visuals: VisualsCliOptions::default(), ascii: AsciiCliOptions::default(), image: ImageCliOptions::default(), developer: DeveloperCliOptions::default(), @@ -260,7 +258,6 @@ impl Default for AsciiCliOptions { ascii_colors: Default::default(), ascii_language: Default::default(), true_color: When::Auto, - show_logo: When::Always, } } } @@ -365,10 +362,13 @@ mod test { }, ascii: AsciiCliOptions { ascii_colors: vec![5, 0], - show_logo: When::Never, ascii_language: Some(Language::Lisp), ..Default::default() }, + visuals: VisualsCliOptions { + no_art: true, + ..Default::default() + }, ..Default::default() }; @@ -386,8 +386,7 @@ mod test { "--disabled-fields", "version", "url", - "--show-logo", - "never", + "--no-art", "--ascii-language", "lisp" ]) diff --git a/src/info/mod.rs b/src/info/mod.rs index ac7577964..9c68cc1bb 100644 --- a/src/info/mod.rs +++ b/src/info/mod.rs @@ -226,7 +226,7 @@ impl Info { text_colors, dominant_language, ascii_colors, - no_color_palette: cli_options.color_blocks.no_color_palette, + no_color_palette: cli_options.visuals.no_color_palette, no_title: cli_options.info.no_title, no_bold: cli_options.text_formatting.no_bold, }) diff --git a/src/ui/printer.rs b/src/ui/printer.rs index 8d8890a0f..6a634fd77 100644 --- a/src/ui/printer.rs +++ b/src/ui/printer.rs @@ -1,4 +1,4 @@ -use crate::cli::{CliOptions, When}; +use crate::cli::CliOptions; use crate::info::Info; use crate::ui::Language; use anyhow::{Context, Result}; @@ -7,10 +7,8 @@ use onefetch_ascii::AsciiArt; use onefetch_image::ImageBackend; use std::fmt::Write as _; use std::io::Write; -use terminal_size::{terminal_size, Width}; const CENTER_PAD_LENGTH: usize = 3; -const MAX_TERM_WIDTH: u16 = 95; #[derive(Clone, clap::ValueEnum, PartialEq, Eq, Debug)] pub enum SerializationFormat { @@ -33,17 +31,6 @@ pub struct Printer { impl Printer { pub fn new(writer: W, info: Info, cli_options: CliOptions) -> Result { - let art_off = match cli_options.ascii.show_logo { - When::Always => false, - When::Never => true, - When::Auto => { - if let Some((Width(width), _)) = terminal_size() { - width < MAX_TERM_WIDTH - } else { - false - } - } - }; let image = match cli_options.image.image { Some(p) => Some(image::open(p).context("Could not load the specified image")?), None => None, @@ -64,7 +51,7 @@ impl Printer { writer, info, output: cli_options.developer.output, - art_off, + art_off: cli_options.visuals.no_art, image, image_backend, color_resolution: cli_options.image.color_resolution,