append become insert
This commit is contained in:
parent
22d7ddca69
commit
112cc09732
3 changed files with 15 additions and 11 deletions
|
@ -52,17 +52,17 @@ impl Buffer {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn append(&mut self, addr: Address, lines: Vec<String>) {
|
||||
pub fn insert(&mut self, addr: Address, lines: Vec<String>) {
|
||||
self.has_changed = true;
|
||||
match addr {
|
||||
Address::Actual => self.append_buffer(self.current_line, lines),
|
||||
Address::Line(l) => self.append_buffer(l, lines),
|
||||
Address::Last => self.append_buffer(self.buffer.len(), lines),
|
||||
Address::Actual | Address::Empty => self.insert_buffer(self.current_line, lines),
|
||||
Address::Line(l) => self.insert_buffer(l, lines),
|
||||
Address::Last => self.insert_buffer(self.buffer.len(), lines),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn append_buffer(&mut self, line: usize, lines: Vec<String>) {
|
||||
fn insert_buffer(&mut self, line: usize, lines: Vec<String>) {
|
||||
for (i, l) in lines.iter().enumerate() {
|
||||
self.buffer.insert(i + line, Ok(l.to_string()));
|
||||
self.current_line = i + line;
|
||||
|
@ -72,13 +72,17 @@ impl Buffer {
|
|||
pub fn print(&mut self, addr: Address, print_numbers: bool) {
|
||||
let last_line = self.buffer.len();
|
||||
match addr {
|
||||
Address::Actual => self.print_line(self.current_line, print_numbers),
|
||||
Address::Actual | Address::Empty => {
|
||||
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::FromTo(a, b) => self.print_range(a.saturating_sub(1), 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::FromToEnd(a) => {
|
||||
self.print_range(a.saturating_sub(1), last_line, print_numbers)
|
||||
}
|
||||
Address::FromActTo(a) => self.print_range(self.current_line, a, print_numbers),
|
||||
Address::FromActToEnd => self.print_range(self.current_line, last_line, print_numbers),
|
||||
Address::Null => println!("nul !"),
|
||||
|
|
|
@ -147,7 +147,7 @@ fn parse_without_addr(c: char) -> Command {
|
|||
|
||||
fn parse(c: char, addr: Address) -> Result<Command, String> {
|
||||
match c {
|
||||
'a' => {
|
||||
'i' => {
|
||||
if addr.is_multi_line() {
|
||||
Err(String::from("Erreur d'adresse"))
|
||||
} else {
|
||||
|
|
|
@ -66,7 +66,7 @@ fn execute_command(buffer: &mut Buffer, c: Command) -> Exit {
|
|||
}
|
||||
}
|
||||
|
||||
buffer.append(a, new_lines);
|
||||
buffer.insert(a, new_lines);
|
||||
}
|
||||
Command::Print(a) => buffer.print(a, false),
|
||||
Command::Number(a) => buffer.print(a, true),
|
||||
|
@ -93,7 +93,7 @@ fn execute_command(buffer: &mut Buffer, c: Command) -> Exit {
|
|||
|
||||
fn parse_line(input: &str) -> Result<Command, String> {
|
||||
let address = take_while(check_address_complete);
|
||||
let command = one_of::<_, _, (&str, ErrorKind)>("apnqQw");
|
||||
let command = one_of::<_, _, (&str, ErrorKind)>("ipnqQw");
|
||||
|
||||
//if let Ok((input, (a, c))) = alt(address, command).parse(input) {
|
||||
let tmp = (address, command).parse(input);
|
||||
|
|
Loading…
Reference in a new issue