Skip to content

Commit

Permalink
fix colouring by nummber
Browse files Browse the repository at this point in the history
  • Loading branch information
chmouel committed Sep 24, 2024
1 parent 80ea3e8 commit d721bf2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ fn regexp_colorize(regexps: &[String]) -> HashMap<String, Color> {
let g = parts.next().unwrap().parse::<u8>().unwrap();
let b = parts.next().unwrap().parse::<u8>().unwrap();
chosen = Color::Rgb(r, g, b);
} else if let Ok(col) = colour.parse::<u8>() {
chosen = Color::Fixed(col);
} else {
// match colour in colours
chosen = match colour {
Expand Down
15 changes: 8 additions & 7 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::sync::Arc;
use regex::Regex;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use yansi::Style;
use yansi::{Color, Paint};

use crate::config;
Expand Down Expand Up @@ -236,13 +237,13 @@ pub fn apply_regexps(regexps: &HashMap<String, Color>, msg: String) -> String {
let mut ret = msg;
for (key, value) in regexps {
let re = Regex::new(format!(r"(?P<r>{})", key.as_str()).as_str()).unwrap();
// let style = Style::new(*value);
// ret = re
// .replace_all(&ret, style.paint("$r").to_string())
// .to_string();
ret = re
.replace_all(&ret, Paint::paint("$r", *value).to_string())
.to_string();
let style = Style::new().fg(*value);
let matched = re.find(&ret);
if matched.is_none() {
continue;
}
let replace = matched.unwrap().as_str().paint(style).to_string();
ret = re.replace_all(&ret, replace).to_string();
}
ret
}
Expand Down

0 comments on commit d721bf2

Please sign in to comment.