a better coloring crate
fix overzealous resetting
bendn 2023-09-17
parent dab3822 · commit 15ab24d
-rw-r--r--Cargo.toml2
-rw-r--r--src/cfstr.rs10
-rw-r--r--tests/basic.rs3
3 files changed, 10 insertions, 5 deletions
diff --git a/Cargo.toml b/Cargo.toml
index afbfcad..4a9f193 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "comat"
-version = "0.1.2"
+version = "0.1.3"
edition = "2021"
authors = ["bendn <[email protected]>"]
license = "MIT"
diff --git a/src/cfstr.rs b/src/cfstr.rs
index 898da31..4891e46 100644
--- a/src/cfstr.rs
+++ b/src/cfstr.rs
@@ -91,11 +91,15 @@ impl Parse for CFStr {
.split_once(':')
.map(|(a, b)| (a.to_string(), b.to_string()))
{
- if a != "reset" {
- out.push_str(name2ansi("reset").unwrap());
- }
+ let mut reset = false;
for a in a.split(',') {
if let Some(ansi) = name2ansi(a) {
+ if !reset {
+ reset = true;
+ if a != "reset" {
+ out.push_str(name2ansi("reset").unwrap());
+ }
+ }
out.push_str(ansi);
} else {
out.push('{');
diff --git a/tests/basic.rs b/tests/basic.rs
index 21a4ace..580d8eb 100644
--- a/tests/basic.rs
+++ b/tests/basic.rs
@@ -3,6 +3,7 @@ use comat::comat;
fn basic() {
assert_eq!(comat!("{red}yes{reset}"), "\x1b[0;34;31myes\x1b[0m");
assert_eq!(comat!("{thing:red}"), "\x1b[0m\x1b[0;34;31m{thing}\x1b[0m");
+ assert_eq!(comat!("{n:.0}"), "{n:.0}");
}
#[test]
@@ -18,5 +19,5 @@ fn take() {
#[test]
fn resetty() {
- assert_eq!(comat!("{:reset}"), "\x1b[0m{}\x1b[0m")
+ assert_eq!(comat!("{:reset}"), "\x1b[0m{}\x1b[0m");
}