Skip to content

Commit

Permalink
--presets print names only if stdout is not a terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
mazznoer committed Nov 29, 2024
1 parent 7e68d44 commit 7c4460d
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clap::{CommandFactory, Parser, ValueEnum};
use lolcrab::{Gradient, Lolcrab, Opt};
use std::{
fs::File,
io::{self, BufReader, Write},
io::{self, BufReader, IsTerminal, Write},
path::PathBuf,
};

Expand Down Expand Up @@ -51,10 +51,14 @@ fn main() -> Result<(), io::Error> {
for g in Gradient::value_variants() {
let name = format!("{g:?}").to_lowercase();
let name = if name == "rdylgn" { "rd-yl-gn" } else { &name };
writeln!(stdout, "\n{name}\n")?;
lol.gradient = g.to_gradient();
lol.randomize_position();
lol.colorize_str(SAMPLE_TEXT, &mut stdout)?;
if stdout.is_terminal() {
writeln!(stdout, "\n{name}\n")?;
lol.gradient = g.to_gradient();
lol.randomize_position();
lol.colorize_str(SAMPLE_TEXT, &mut stdout)?;
} else {
writeln!(stdout, "{name}")?;
}
}
return Ok(());
}
Expand Down

0 comments on commit 7c4460d

Please sign in to comment.