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

replace --show-logo with --no-art #1002

Merged
merged 1 commit into from
Apr 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
27 changes: 13 additions & 14 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -260,7 +258,6 @@ impl Default for AsciiCliOptions {
ascii_colors: Default::default(),
ascii_language: Default::default(),
true_color: When::Auto,
show_logo: When::Always,
}
}
}
Expand Down Expand Up @@ -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()
};

Expand All @@ -386,8 +386,7 @@ mod test {
"--disabled-fields",
"version",
"url",
"--show-logo",
"never",
"--no-art",
"--ascii-language",
"lisp"
])
Expand Down
2 changes: 1 addition & 1 deletion src/info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
17 changes: 2 additions & 15 deletions src/ui/printer.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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 {
Expand All @@ -33,17 +31,6 @@ pub struct Printer<W> {

impl<W: Write> Printer<W> {
pub fn new(writer: W, info: Info, cli_options: CliOptions) -> Result<Self> {
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,
Expand All @@ -64,7 +51,7 @@ impl<W: Write> Printer<W> {
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,
Expand Down