pay-respects/src/style.rs

32 lines
813 B
Rust
Raw Normal View History

2023-08-01 20:29:02 +02:00
use crate::suggestions::split_command;
2023-07-31 23:48:14 +02:00
use colored::*;
2023-07-30 18:40:18 +02:00
2023-08-01 20:29:02 +02:00
pub fn highlight_difference(suggested_command: &str, last_command: &str) -> String {
let split_suggested_command = split_command(suggested_command);
2023-07-31 23:42:19 +02:00
let split_last_command = split_command(last_command);
2023-07-30 18:40:18 +02:00
2023-08-01 20:29:02 +02:00
let mut old_entries = Vec::new();
for command in &split_suggested_command {
if command.is_empty() {
continue;
}
2023-08-01 20:29:02 +02:00
'old: for old in split_last_command.clone() {
if command == &old {
old_entries.push(command.clone());
break 'old;
2023-07-30 18:40:18 +02:00
}
}
2023-08-01 20:29:02 +02:00
}
let mut highlighted = suggested_command.to_string();
for entry in &split_suggested_command {
if old_entries.contains(entry) {
highlighted = highlighted.replace(entry, &entry.cyan());
2023-07-30 18:40:18 +02:00
} else {
2023-08-01 20:29:02 +02:00
highlighted = highlighted.replace(entry, &entry.red().bold());
2023-07-30 18:40:18 +02:00
}
}
2023-08-01 20:29:02 +02:00
highlighted
2023-07-30 18:40:18 +02:00
}