init
This commit is contained in:
52
src/diff.rs
Normal file
52
src/diff.rs
Normal file
@ -0,0 +1,52 @@
|
||||
pub struct Compare {
|
||||
pub right: String,
|
||||
pub left: String,
|
||||
pub eval: String
|
||||
}
|
||||
type Compared = Compare;
|
||||
|
||||
pub struct Comparer {
|
||||
formatted_right: Vec<String>,
|
||||
formatted_left: Vec<String>,
|
||||
formatted_eval: Vec<String>
|
||||
}
|
||||
impl Comparer {
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
formatted_right: Vec::new(),
|
||||
formatted_left: Vec::new(),
|
||||
formatted_eval: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn format_compare(&mut self, left_char: char, right_char: char) {
|
||||
if left_char == right_char {
|
||||
self.formatted_left.push(left_char.to_string());
|
||||
self.formatted_right.push(right_char.to_string());
|
||||
} else {
|
||||
self.formatted_left.push(color_print::cformat!("<r>{left_char}</>"));
|
||||
self.formatted_right.push(color_print::cformat!("<r>{right_char}</>"));
|
||||
};
|
||||
}
|
||||
|
||||
pub fn compare(&mut self, compare: Compare) -> Compared {
|
||||
let right_chars: Vec<char> = compare.right.chars().collect();
|
||||
|
||||
for (i, left_char) in compare.left.chars().enumerate() {
|
||||
match right_chars.get(i) {
|
||||
Some(right_char) => self.format_compare(left_char, *right_char),
|
||||
None => {
|
||||
compare.eval.chars().for_each(|char| {
|
||||
// self.formatted_eval
|
||||
});
|
||||
break
|
||||
},
|
||||
}
|
||||
}
|
||||
Compared {
|
||||
right: self.formatted_right.concat(),
|
||||
left: self.formatted_left.concat(),
|
||||
eval: self.formatted_eval.concat()
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user