2023-07-31 23:42:19 +02:00
|
|
|
use crate::corrections::split_command;
|
2023-07-31 23:48:14 +02:00
|
|
|
use colored::*;
|
2023-07-30 18:40:18 +02:00
|
|
|
|
|
|
|
|
pub fn highlight_difference(corrected_command: &str, last_command: &str) -> String {
|
|
|
|
|
let mut highlighted_command = String::new();
|
|
|
|
|
|
2023-07-31 23:42:19 +02:00
|
|
|
let split_corrected_command = split_command(corrected_command);
|
|
|
|
|
let split_last_command = split_command(last_command);
|
2023-07-30 18:40:18 +02:00
|
|
|
|
|
|
|
|
for new in split_corrected_command {
|
2023-07-31 23:48:14 +02:00
|
|
|
if new.is_empty() {
|
2023-07-31 19:59:16 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
2023-07-30 18:40:18 +02:00
|
|
|
let mut changed = true;
|
|
|
|
|
for old in split_last_command.clone() {
|
|
|
|
|
if new == old {
|
|
|
|
|
changed = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if changed {
|
2023-07-30 18:58:14 +02:00
|
|
|
let colored = new.red().bold();
|
|
|
|
|
highlighted_command = format!("{}{}", highlighted_command, colored);
|
2023-07-30 18:40:18 +02:00
|
|
|
} else {
|
2023-07-30 18:58:14 +02:00
|
|
|
let colored = new.green();
|
|
|
|
|
highlighted_command = format!("{}{}", highlighted_command, colored);
|
2023-07-30 18:40:18 +02:00
|
|
|
}
|
|
|
|
|
highlighted_command.push(' ');
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-31 19:19:20 +02:00
|
|
|
highlighted_command.trim().to_string()
|
2023-07-30 18:40:18 +02:00
|
|
|
}
|