forked from mars/breed
added append mode
This commit is contained in:
parent
86b607e22f
commit
bb6862d123
24
src/main.rs
24
src/main.rs
|
@ -20,7 +20,7 @@ use std::io::{ stdin, stdout, Read, Stdout, Write };
|
||||||
|
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
cursor,
|
cursor,
|
||||||
event::{Event, KeyCode, KeyEvent}
|
event::{ Event, KeyCode, KeyEvent, read },
|
||||||
terminal,
|
terminal,
|
||||||
ExecutableCommand,
|
ExecutableCommand,
|
||||||
Result
|
Result
|
||||||
|
@ -116,6 +116,7 @@ enum Mode {
|
||||||
Normal,
|
Normal,
|
||||||
Command,
|
Command,
|
||||||
Visual,
|
Visual,
|
||||||
|
Append,
|
||||||
Insert,
|
Insert,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,6 +126,7 @@ impl Mode {
|
||||||
match self {
|
match self {
|
||||||
Mode::Normal => Style::SteadyBlock,
|
Mode::Normal => Style::SteadyBlock,
|
||||||
Mode::Visual => Style::BlinkingBlock,
|
Mode::Visual => Style::BlinkingBlock,
|
||||||
|
Mode::Append => Style::BlinkingBar,
|
||||||
Mode::Insert => Style::BlinkingBar,
|
Mode::Insert => Style::BlinkingBar,
|
||||||
Mode::Command => Style::SteadyUnderScore,
|
Mode::Command => Style::SteadyUnderScore,
|
||||||
}
|
}
|
||||||
|
@ -174,6 +176,7 @@ impl State {
|
||||||
Mode::Normal => self.on_normal_event(event),
|
Mode::Normal => self.on_normal_event(event),
|
||||||
Mode::Command => self.on_command_event(event),
|
Mode::Command => self.on_command_event(event),
|
||||||
Mode::Visual => self.on_visual_event(event),
|
Mode::Visual => self.on_visual_event(event),
|
||||||
|
Mode::Append => self.on_append_event(event),
|
||||||
Mode::Insert => self.on_insert_event(event),
|
Mode::Insert => self.on_insert_event(event),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,6 +187,10 @@ impl State {
|
||||||
KeyCode::Char('i') => {
|
KeyCode::Char('i') => {
|
||||||
self.mode = Mode::Insert;
|
self.mode = Mode::Insert;
|
||||||
}
|
}
|
||||||
|
KeyCode::Char('a') => {
|
||||||
|
self.move_cursor(Direction::Right);
|
||||||
|
self.mode = Mode::Append;
|
||||||
|
}
|
||||||
KeyCode::Char(':') => {
|
KeyCode::Char(':') => {
|
||||||
self.mode = Mode::Command;
|
self.mode = Mode::Command;
|
||||||
}
|
}
|
||||||
|
@ -223,6 +230,19 @@ impl State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn on_append_event(&mut self, event: Event) {
|
||||||
|
match event {
|
||||||
|
Event::Key(KeyEvent { code, .. }) => match code {
|
||||||
|
KeyCode::Esc => {
|
||||||
|
self.move_cursor(Direction::Left);
|
||||||
|
self.mode = Mode::Normal;
|
||||||
|
}
|
||||||
|
_ => self.on_insert_event(event),
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn on_insert_event(&mut self, event: Event) {
|
fn on_insert_event(&mut self, event: Event) {
|
||||||
match event {
|
match event {
|
||||||
Event::Key(KeyEvent { code, .. }) => match code {
|
Event::Key(KeyEvent { code, .. }) => match code {
|
||||||
|
@ -274,7 +294,7 @@ impl State {
|
||||||
fn screen_main(stdout: &mut Stdout, mut state: State) -> Result<()> {
|
fn screen_main(stdout: &mut Stdout, mut state: State) -> Result<()> {
|
||||||
while !state.quit {
|
while !state.quit {
|
||||||
state.draw(stdout)?;
|
state.draw(stdout)?;
|
||||||
let event = event::read()?;
|
let event = read()?;
|
||||||
state.on_event(event);
|
state.on_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user