refactor: have ansi_num_color return both sides' colors

This commit is contained in:
Kiana Sheibani 2024-08-15 00:16:23 -04:00
parent 126268d8e3
commit c2158f85f7
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
2 changed files with 7 additions and 8 deletions

View file

@ -676,8 +676,7 @@ fn player_matchup(
g_func((deviation1 * deviation1 + deviation2 * deviation2).sqrt()) * advantage, g_func((deviation1 * deviation1 + deviation2 * deviation2).sqrt()) * advantage,
)); ));
let color = ansi_num_color(advantage, 0.2, 2.0); let (color, other_color) = ansi_num_color(advantage, 0.2, 2.0);
let other_color = ansi_num_color(-advantage, 0.2, 2.0);
let len1 = prefix1.as_deref().map(|s| s.len() + 1).unwrap_or(0) + name1.len(); let len1 = prefix1.as_deref().map(|s| s.len() + 1).unwrap_or(0) + name1.len();
let len2 = prefix2.as_deref().map(|s| s.len() + 1).unwrap_or(0) + name2.len(); let len2 = prefix2.as_deref().map(|s| s.len() + 1).unwrap_or(0) + name2.len();

View file

@ -41,7 +41,7 @@ pub fn read_string() -> String {
line.trim().to_owned() line.trim().to_owned()
} }
pub fn ansi_num_color(num: f64, threshold1: f64, threshold2: f64) -> &'static str { pub fn ansi_num_color(num: f64, threshold1: f64, threshold2: f64) -> (&'static str, &'static str) {
let sign = num > 0.0; let sign = num > 0.0;
let num_abs = num.abs(); let num_abs = num.abs();
let severity = if num_abs < threshold1 { let severity = if num_abs < threshold1 {
@ -53,11 +53,11 @@ pub fn ansi_num_color(num: f64, threshold1: f64, threshold2: f64) -> &'static st
}; };
match (sign, severity) { match (sign, severity) {
(false, 1) => "31", (false, 1) => ("31", "32"),
(true, 1) => "32", (true, 1) => ("32", "31"),
(false, 2) => "91", (false, 2) => ("91", "92"),
(true, 2) => "92", (true, 2) => ("92", "91"),
_ => "39", _ => ("39", "39"),
} }
} }