use regex::Regex;
use std::{borrow::Cow, sync::LazyLock};
pub const ANSI_REGEX_PATTERN: &str = concat!(
"(?:\\x1B\\][^\\x07\\x1B\\x9C]*?(?:\\x07|\\x1B\\\\|\\x9C))",
"|",
"(?:\\x1B\\[[\\[\\]()#;?]*(?:[0-9]{1,4}(?:[;:][0-9]{0,4})*)?[0-9A-PR-TZcf-nq-uy=><~])",
"|",
"(?:\\x9B[\\[\\]()#;?]*(?:[0-9]{1,4}(?:[;:][0-9]{0,4})*)?[0-9A-PR-TZcf-nq-uy=><~])",
"|",
"(?:\\x1B[ABCDHIKJSTZ=><sum78EMcNO])",
"|",
"(?:\\x1B[()][AB012])",
"|",
"(?:\\x1B#[34568])",
"|",
"(?:\\x1B[0-9]+n)"
);
static ANSI_REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new(ANSI_REGEX_PATTERN).expect("valid ANSI regex"));
pub(crate) fn strip_ansi(string: &str) -> Cow<'_, str> {
ANSI_REGEX.replace_all(string, "")
}