From 927f323b75230e337652514eb56c5a92c38114b5 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 16 Oct 2024 11:13:22 -0400 Subject: [PATCH] fix: strip ansi escapes from cli input --- Cargo.lock | 12 ++++++++++-- Cargo.toml | 1 + src/main.rs | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c8efc40..3ecfd8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,15 +19,16 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "anstream" -version = "0.6.11" +version = "0.6.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" +checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", + "is_terminal_polyfill", "utf8parse", ] @@ -267,10 +268,17 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "kittysay" version = "0.8.0" dependencies = [ + "anstream", "clap", "clap-stdin", "color-eyre", diff --git a/Cargo.toml b/Cargo.toml index 6e72d6d..ddddf0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ categories = ["command-line-utilities"] edition = "2021" [dependencies] +anstream = "0.6.15" clap = { version = "4.5.9", features = ["derive"] } clap-stdin = "0.4.0" color-eyre = "0.6.3" diff --git a/src/main.rs b/src/main.rs index 452c2cf..7655a4e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ use color_eyre::eyre::Result; use clap::Parser; use clap_stdin::MaybeStdin; +use anstream::{adapter::strip_str, println}; use crossterm::terminal; use kittysay::{generate, FormatOptions, KITTY}; @@ -36,7 +37,7 @@ fn main() -> Result<()> { width, }; - let msg = generate(&args.message, &format_opts); + let msg = generate(&strip_str(&args.message).to_string(), &format_opts); let mut msg_color = console::Color::White; let mut cat_color = console::Color::White;