#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Motion {
Up(usize),
Down(usize),
Left(usize),
Right(usize),
LineStart,
LineEnd,
FileStart,
FileEnd,
Find(char),
FindReverse(char),
WordForward,
WordBackward,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Operator {
Delete,
Yank,
Change,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TextObject {
Word,
Line,
ToLineEnd,
ToLineStart,
InParentheses,
InBrackets,
InBraces,
InQuotes,
}
#[derive(Debug, Clone)]
pub struct CommandState {
count: usize,
operator: Option<Operator>,
motion: Option<Motion>,
text_object: Option<TextObject>,
}
impl CommandState {
pub fn new() -> Self {
Self {
count: 0,
operator: None,
motion: None,
text_object: None,
}
}
pub fn get_count(&self) -> usize {
if self.count == 0 {
1
} else {
self.count
}
}
pub fn parse_count(&mut self, c: char) {
if let Some(digit) = c.to_digit(10) {
self.count = self.count * 10 + digit as usize;
}
}
pub fn has_count(&self) -> bool {
self.count > 0
}
pub fn set_operator(&mut self, operator: Operator) {
self.operator = Some(operator);
}
pub fn get_operator(&self) -> Option<Operator> {
self.operator
}
pub fn set_motion(&mut self, motion: Motion) {
self.motion = Some(motion);
}
pub fn get_motion(&self) -> Option<Motion> {
self.motion
}
pub fn set_text_object(&mut self, text_object: TextObject) {
self.text_object = Some(text_object);
}
pub fn get_text_object(&self) -> Option<TextObject> {
self.text_object
}
pub fn clear(&mut self) {
self.count = 0;
self.operator = None;
self.motion = None;
self.text_object = None;
}
}