Skip to content

contains

Whether text contains an ANSI escape character (ESC, U+001B).

A cheap check for output that is styled, for instance to decide whether to strip it with strip before writing it to a file.

use helpers4::ansi::contains;

Cargo feature ansi (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features ansi

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.6", default-features = false, features = ["ansi"] }
pub fn contains(text: &str) -> bool
ParameterTypeDescription
text&strThe text to check.

booltrue when the text has an escape character.

use helpers4::ansi::contains;

assert!(contains("\u{1b}[32mok\u{1b}[0m"));
assert!(!contains("ok"));

src/ansi/contains.rs