add print multi line
This commit is contained in:
parent
cec3beaf90
commit
cbd2669ef4
1 changed files with 14 additions and 2 deletions
|
@ -29,9 +29,15 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print(&mut self, addr: Address, print_numbers: bool) {
|
pub fn print(&mut self, addr: Address, print_numbers: bool) {
|
||||||
|
let last_line = self.buffer.len().saturating_sub(1);
|
||||||
match addr {
|
match addr {
|
||||||
Address::Actual => self.print_line(self.current_line, print_numbers),
|
Address::Actual => self.print_line(self.current_line, print_numbers),
|
||||||
Address::Line(l) => self.print_line(l.saturating_sub(1), 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 !"),
|
Address::Null => println!("nul !"),
|
||||||
_ => println!("coucou2"),
|
_ => println!("coucou2"),
|
||||||
}
|
}
|
||||||
|
@ -56,8 +62,14 @@ impl Buffer {
|
||||||
|
|
||||||
// affiche plusieurs lignes
|
// affiche plusieurs lignes
|
||||||
fn print_range(&mut self, first: usize, last: usize, print_numbers: bool) {
|
fn print_range(&mut self, first: usize, last: usize, print_numbers: bool) {
|
||||||
|
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 {
|
for i in first..last {
|
||||||
self.print_line(i, print_numbers);
|
self.print_line(i, print_numbers);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
println!("?");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue