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() {
|
2023-07-31 19:59:16 +02:00
|
|
|
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) {
|
2023-08-01 20:40:19 +02:00
|
|
|
highlighted = highlighted.replace(entry, &entry.cyan().to_string());
|
2023-07-30 18:40:18 +02:00
|
|
|
} else {
|
2023-08-01 20:40:19 +02:00
|
|
|
highlighted = highlighted.replace(entry, &entry.red().bold().to_string());
|
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
|
|
|
}
|