red/src/enums.rs

118 lines
2.1 KiB
Rust

#[derive(Debug)]
pub enum Address {
Actual,
Last,
Line(u32),
FromStartTo(u32),
FromToEnd(u32),
FromTo(u32, u32),
Null,
}
impl Address {
pub fn is_null(&self) -> bool {
println!("{:?}", self);
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 {
match addr {
"." => Address::Actual,
"$" => Address::Last,
_ => Address::Null,
}
}
}
#[derive(Debug)]
pub enum Command {
ChangeAddr(Address),
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)
}
*/
}