add print multi line

This commit is contained in:
rick 2023-04-14 14:50:54 +02:00
parent cec3beaf90
commit cbd2669ef4
Signed by: Rick
GPG key ID: 5CBE8779CD27BCBA

View file

@ -29,9 +29,15 @@ impl Buffer {
}
pub fn print(&mut self, addr: Address, print_numbers: bool) {
let last_line = self.buffer.len().saturating_sub(1);
match addr {
Address::Actual => self.print_line(self.current_line, print_numbers),
Address::Line(l) => self.print_line(l.saturating_sub(1), print_numbers),
Address::Last => self.print_line(last_line, print_numbers),
Address::All => self.print_range(0, last_line, print_numbers),
Address::FromTo(a, b) => self.print_range(a, b, print_numbers),
Address::FromStartTo(a) => self.print_range(0, a, print_numbers),
Address::FromToEnd(a) => self.print_range(a, last_line, print_numbers),
Address::Null => println!("nul !"),
_ => println!("coucou2"),
}
@ -56,8 +62,14 @@ impl Buffer {
// affiche plusieurs lignes
fn print_range(&mut self, first: usize, last: usize, print_numbers: bool) {
for i in first..last {
self.print_line(i, print_numbers);
let len = self.buffer.len();
// anti idiot, vraiment utile vu que les adresses gères déjà ça ?
if len > 0 && (first <= len && last <= len && first <= last) {
for i in first..last {
self.print_line(i, print_numbers);
}
} else {
println!("?");
}
}
}