working state
This commit is contained in:
37
src/main.rs
37
src/main.rs
@@ -52,15 +52,17 @@ enum Mode {
|
|||||||
Chord(Chord),
|
Chord(Chord),
|
||||||
Normal,
|
Normal,
|
||||||
Command(Chord),
|
Command(Chord),
|
||||||
|
Visual((usize, usize)),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Mode {
|
impl Display for Mode {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Mode::Insert(_) => write!(f, "- INSERT -"),
|
Mode::Normal => write!(f, "-- NORMAL --"),
|
||||||
Mode::Chord(_) => write!(f, "- CHORD -"),
|
Mode::Insert(_) => write!(f, "-- INSERT --"),
|
||||||
Mode::Normal => write!(f, "- NORMAL -"),
|
Mode::Chord(_) => write!(f, "-- CHORD --"),
|
||||||
Mode::Command(_) => write!(f, "- COMMAND -"),
|
Mode::Command(_) => write!(f, "-- COMMAND --"),
|
||||||
|
Mode::Visual(_) => write!(f, "-- VISUAL --"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,6 +78,11 @@ impl Mode {
|
|||||||
'k' => app.grid.selected_cell.1 = app.grid.selected_cell.1.saturating_sub(1),
|
'k' => app.grid.selected_cell.1 = app.grid.selected_cell.1.saturating_sub(1),
|
||||||
// >
|
// >
|
||||||
'l' => app.grid.selected_cell.0 = app.grid.selected_cell.0.saturating_add(1),
|
'l' => app.grid.selected_cell.0 = app.grid.selected_cell.0.saturating_add(1),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Mode::Normal = app.mode {
|
||||||
|
match key {
|
||||||
// edit cell
|
// edit cell
|
||||||
'i' | 'a' => {
|
'i' | 'a' => {
|
||||||
let (x, y) = app.grid.selected_cell;
|
let (x, y) = app.grid.selected_cell;
|
||||||
@@ -88,11 +95,13 @@ impl Mode {
|
|||||||
'A' => { /* insert col after */ }
|
'A' => { /* insert col after */ }
|
||||||
'o' => { /* insert row below */ }
|
'o' => { /* insert row below */ }
|
||||||
'O' => { /* insert row above */ }
|
'O' => { /* insert row above */ }
|
||||||
|
'v' => app.mode = Mode::Visual(app.grid.selected_cell),
|
||||||
':' => app.mode = Mode::Command(Chord::new(':')),
|
':' => app.mode = Mode::Command(Chord::new(':')),
|
||||||
// loose chars will put you into chord mode
|
// loose chars will put you into chord mode
|
||||||
c => app.mode = Mode::Chord(Chord::new(c)),
|
c => app.mode = Mode::Chord(Chord::new(c)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct App {
|
struct App {
|
||||||
@@ -153,6 +162,7 @@ impl App {
|
|||||||
}),
|
}),
|
||||||
layout[0],
|
layout[0],
|
||||||
),
|
),
|
||||||
|
Mode::Visual(start_pos) => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
frame.render_widget(&self.grid, layout[1]);
|
frame.render_widget(&self.grid, layout[1]);
|
||||||
@@ -182,7 +192,14 @@ impl App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Err(_) => match chord.as_string().as_str() {
|
||||||
|
"d " | "dw" => {
|
||||||
|
let loc = self.grid.selected_cell;
|
||||||
|
self.grid.set_cell_raw(loc, String::new());
|
||||||
|
self.mode = Mode::Normal;
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@@ -226,6 +243,18 @@ impl App {
|
|||||||
},
|
},
|
||||||
_ => todo!(),
|
_ => todo!(),
|
||||||
},
|
},
|
||||||
|
Mode::Visual(start_pos) => {
|
||||||
|
if let event::Event::Key(key) = event::read()? {
|
||||||
|
match key.code {
|
||||||
|
event::KeyCode::Char(c) => {
|
||||||
|
Mode::process_key(self, c);
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
event::KeyCode::Esc => self.mode = Mode::Normal,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Mode::Command(editor) => match event::read()? {
|
Mode::Command(editor) => match event::read()? {
|
||||||
event::Event::Key(key) => match key.code {
|
event::Event::Key(key) => match key.code {
|
||||||
event::KeyCode::Esc => {
|
event::KeyCode::Esc => {
|
||||||
|
|||||||
Reference in New Issue
Block a user