Skip to content

Commit

Permalink
update to latest yansi and other deps
Browse files Browse the repository at this point in the history
needed a bunch of update for yansi 1.0
  • Loading branch information
chmouel committed Sep 23, 2024
1 parent e72c839 commit 0a0bcd9
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 46 deletions.
48 changes: 24 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repository = "chmouel/snazy"
serde = { version = "1.0.204", features = ["derive"] }
serde_json = "1.0.127"
chrono = { version = "0.4.38", default-features = false, features = ["clock"] }
yansi = "0.5.1"
yansi = "1.0.1"
clap = { version = "4", features = ["suggestions", "derive", "env"] }
regex = "1.10.6"
tempfile = "3.9.0"
Expand Down
12 changes: 6 additions & 6 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clap_complete::{generate, Generator, Shell};
use is_terminal::IsTerminal;
use std::collections::HashMap;
use std::{env, io};
use yansi::{Color, Paint};
use yansi::Color;

// `cstr!` converts tags to ANSI codes
const AFTER_HELP: &str = color_print::cstr!(
Expand Down Expand Up @@ -141,7 +141,7 @@ fn regexp_colorize(regexps: &[String]) -> HashMap<String, Color> {
let r = parts.next().unwrap().parse::<u8>().unwrap();
let g = parts.next().unwrap().parse::<u8>().unwrap();
let b = parts.next().unwrap().parse::<u8>().unwrap();
chosen = Color::RGB(r, g, b);
chosen = Color::Rgb(r, g, b);
} else {
// match colour in colours
chosen = match colour {
Expand All @@ -153,11 +153,11 @@ fn regexp_colorize(regexps: &[String]) -> HashMap<String, Color> {
"green" => Color::Green,
"white" => Color::White,
"black" => Color::Black,
"grey" => Color::RGB(128, 128, 128),
_ => Color::Default,
"grey" => Color::Rgb(128, 128, 128),
_ => Color::Primary,
};
}
if chosen == Color::Default {
if chosen == Color::Primary {
chosen = defchosen;
} else {
reg = regexp.replace(format!("{colour}:").as_str(), "");
Expand Down Expand Up @@ -211,7 +211,7 @@ pub fn build_cli_config() -> Config {
let regexp_colours = regexp_colorize(&args.regexp);
let colouring = colouring(args.color);
if !colouring {
Paint::disable();
yansi::disable();
}
let json_keys = make_json_keys(&args.json_keys);

Expand Down
13 changes: 8 additions & 5 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::sync::Arc;
use regex::Regex;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use yansi::{Color, Paint, Style};
use yansi::{Color, Paint};

use crate::config;
use crate::config::Config;
Expand Down Expand Up @@ -89,7 +89,7 @@ pub fn extract_info(rawline: &str, config: &Config) -> HashMap<String, String> {
}

if !config.kail_no_prefix && !kail_msg_prefix.is_empty() && msg.contains_key("msg") {
*msg.get_mut("msg").unwrap() = format!("{} {}", Paint::blue(kail_msg_prefix), msg["msg"]);
*msg.get_mut("msg").unwrap() = format!("{} {}", kail_msg_prefix.blue(), msg["msg"]);
}
msg
}
Expand Down Expand Up @@ -212,7 +212,7 @@ pub fn do_line(config: &Config, line: &str) -> Option<Info> {
}
let mut ts = String::new();
if msg.contains_key("ts") {
ts = Paint::fixed(13, msg.get("ts").unwrap()).to_string();
ts = msg.get("ts").unwrap().fixed(13).to_string();
}
let other = if msg.contains_key("others") {
format!(" {}", Paint::cyan(msg.get("others").unwrap()).italic())
Expand All @@ -236,9 +236,12 @@ 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);
// let style = Style::new(*value);
// ret = re
// .replace_all(&ret, style.paint("$r").to_string())
// .to_string();
ret = re
.replace_all(&ret, style.paint("$r").to_string())
.replace_all(&ret, Paint::paint("$r", *value).to_string())
.to_string();
}
ret
Expand Down
8 changes: 4 additions & 4 deletions src/parse_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod tests {
use std::{thread, vec};

use regex::Regex;
use yansi::Color;
use yansi::{Color, Paint};

use crate::config::Config;
use crate::parse::{action_on_regexp, do_line, extract_info};
Expand Down Expand Up @@ -103,8 +103,8 @@ mod tests {
ret,
format!(
"{} {} normal",
Color::Red.paint("red"),
Color::Blue.paint("blue")
"red".red().to_string(),
"blue".blue().to_string()
)
);
}
Expand Down Expand Up @@ -203,7 +203,7 @@ mod tests {
crate::parse::read_a_file(&config, file_path.to_str().unwrap(), writeto);
file.close().unwrap();
assert_eq!(
"\u{1b}[38;5;10mINFO\u{1b}[0m \u{1b}[38;5;13m14:20:32\u{1b}[0m hello world\n\u{1b}[38;5;14mDEBUG\u{1b}[0m \u{1b}[38;5;13m14:20:32\u{1b}[0m debug\n",
"\u{1b}[32mINFO\u{1b}[0m \u{1b}[38;5;13m14:20:32\u{1b}[0m hello world\n\u{1b}[38;5;14mDEBUG\u{1b}[0m \u{1b}[38;5;13m14:20:32\u{1b}[0m debug\n",
std::str::from_utf8(writeto).unwrap()
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ pub fn level_symbols(level: &str) -> String {

pub fn color_by_level(level: &str) -> String {
match level {
"DEBUG" => format!("{:<19}", Paint::fixed(14, "DEBUG").to_string()),
"WARNING" => format!("{:<19}", Paint::fixed(11, "WARN").to_string()),
"ERROR" => format!("{:<18}", Paint::fixed(9, "ERROR").to_string()),
"INFO" => format!("{:<19}", Paint::fixed(10, "INFO").to_string()),
_ => format!("{:<19}", Paint::fixed(10, level).to_string()),
"DEBUG" => format!("{:<19}", "DEBUG".fixed(14).to_string()),
"WARNING" => format!("{:<19}", "WARN".yellow().to_string()),
"ERROR" => format!("{:<18}", "ERROR".red().to_string()),
"INFO" => format!("{:<19}", "INFO".green().to_string()),
_ => format!("{:<19}", level.fixed(4).to_string()),
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ snazytest!(
kail_log_and_regexp,
["-rHello", "-rMoto", "--color", "always"],
r#"ns/pod[container]: {"level":"INFO","msg":"Hello Moto"}"#,
"\u{1b}[38;5;10mINFO\u{1b}[0m \u{1b}[34mns/pod[container]\u{1b}[0m \u{1b}[36mHello\u{1b}[0m \u{1b}[33mMoto\u{1b}[0m\n",
"\u{1b}[32mINFO\u{1b}[0m \u{1b}[34mns/pod[container]\u{1b}[0m \u{1b}[36mHello\u{1b}[0m \u{1b}[33mMoto\u{1b}[0m\n",
false
);

Expand Down

0 comments on commit 0a0bcd9

Please sign in to comment.