From 7c4460d39f1743fcaf8872e2bc88179f0ae9a4fd Mon Sep 17 00:00:00 2001 From: Nor Khasyatillah Date: Fri, 29 Nov 2024 14:47:32 +0700 Subject: [PATCH] `--presets` print names only if stdout is not a terminal --- src/main.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 89c61f4..60f7b19 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, }; @@ -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(()); }