119 lines
2.1 KiB
Rust
119 lines
2.1 KiB
Rust
use std::str::FromStr;
|
|
|
|
#[derive(Debug)]
|
|
pub enum Address {
|
|
Actual,
|
|
Last,
|
|
Line(usize),
|
|
FromStartTo(usize),
|
|
FromToEnd(usize),
|
|
FromTo(usize, usize),
|
|
Null,
|
|
}
|
|
|
|
impl Address {
|
|
pub fn is_null(&self) -> bool {
|
|
match self {
|
|
Self::Null => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn parse_address(addr: &str) -> Address {
|
|
let mut tmp = String::from(addr);
|
|
tmp.retain(|c| c != ' ');
|
|
let addr = tmp.as_str();
|
|
|
|
if addr.is_empty() {
|
|
Address::Actual
|
|
} else if let Ok(l) = usize::from_str(addr) {
|
|
Address::Line(l)
|
|
} else {
|
|
match addr {
|
|
"." => Address::Actual,
|
|
"$" => Address::Last,
|
|
_ => Address::Null,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum Command {
|
|
Append(Address),
|
|
Insert(Address),
|
|
Change(Address),
|
|
Delete(Address),
|
|
// bool pour check ou pas (e et E) TODO mettre le chemin vers le fichier
|
|
Edit(bool),
|
|
// TODO chemin vers fichier
|
|
File(),
|
|
// TODO
|
|
Help,
|
|
// TODO
|
|
SetHelp,
|
|
Join(Address),
|
|
// TODO nom de la marque
|
|
Mark(Address),
|
|
List(Address),
|
|
// TODO
|
|
Move(Address),
|
|
Number(Address),
|
|
Print(Address),
|
|
Prompt,
|
|
// bool pour check ou pas (q et Q)
|
|
Quit(bool),
|
|
// TODO
|
|
Read,
|
|
// TODO
|
|
Substitute,
|
|
// TODO
|
|
CopyLines,
|
|
Undo,
|
|
// TODO
|
|
Write,
|
|
// TODO
|
|
Line,
|
|
// TODO
|
|
ShellCommand,
|
|
// TODO
|
|
Null,
|
|
// TODO
|
|
Global,
|
|
// TODO
|
|
NonMatched,
|
|
}
|
|
|
|
/*
|
|
fn parse_without_addr(c: char) -> Command {
|
|
match c {
|
|
'q' => Command::Quit(false),
|
|
'Q' => Command::Quit(true),
|
|
_ => Command::Help,
|
|
}
|
|
}
|
|
*/
|
|
|
|
fn parse(c: char, addr: Address) -> Command {
|
|
match c {
|
|
'p' => Command::Print(addr),
|
|
'n' => Command::Number(addr),
|
|
'q' => Command::Quit(false),
|
|
'Q' => Command::Quit(true),
|
|
_ => Command::Help,
|
|
}
|
|
}
|
|
|
|
pub fn parse_command(c: char, addr: Address) -> Command {
|
|
parse(c, addr)
|
|
/*
|
|
if let Some(a) = addr {
|
|
println!("Ok");
|
|
parse_with_addr(c, a)
|
|
} else {
|
|
println!("No");
|
|
parse_without_addr(c)
|
|
}
|
|
*/
|
|
}
|