|
|
@ -36,7 +36,8 @@ pub struct Editor {
|
|
|
|
size: (u16, u16),
|
|
|
|
size: (u16, u16),
|
|
|
|
surface: Surface,
|
|
|
|
surface: Surface,
|
|
|
|
cache: Surface,
|
|
|
|
cache: Surface,
|
|
|
|
prompt: Prompt,
|
|
|
|
prompt: Option<Prompt>,
|
|
|
|
|
|
|
|
should_close: bool,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Editor {
|
|
|
|
impl Editor {
|
|
|
@ -46,7 +47,6 @@ impl Editor {
|
|
|
|
let mut terminal = Terminal::new(backend)?;
|
|
|
|
let mut terminal = Terminal::new(backend)?;
|
|
|
|
let size = terminal::size().unwrap();
|
|
|
|
let size = terminal::size().unwrap();
|
|
|
|
let area = Rect::new(0, 0, size.0, size.1);
|
|
|
|
let area = Rect::new(0, 0, size.0, size.1);
|
|
|
|
let prompt = Prompt::new();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let mut editor = Editor {
|
|
|
|
let mut editor = Editor {
|
|
|
|
terminal,
|
|
|
|
terminal,
|
|
|
@ -55,7 +55,8 @@ impl Editor {
|
|
|
|
surface: Surface::empty(area),
|
|
|
|
surface: Surface::empty(area),
|
|
|
|
cache: Surface::empty(area),
|
|
|
|
cache: Surface::empty(area),
|
|
|
|
// TODO; move to state
|
|
|
|
// TODO; move to state
|
|
|
|
prompt,
|
|
|
|
prompt: None,
|
|
|
|
|
|
|
|
should_close: false,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(file) = args.values_of_t::<PathBuf>("files").unwrap().pop() {
|
|
|
|
if let Some(file) = args.values_of_t::<PathBuf>("files").unwrap().pop() {
|
|
|
@ -65,6 +66,15 @@ impl Editor {
|
|
|
|
Ok(editor)
|
|
|
|
Ok(editor)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn set_commands(self) {
|
|
|
|
|
|
|
|
let commands = |input: &str| match input {
|
|
|
|
|
|
|
|
"q" => self.should_close = true,
|
|
|
|
|
|
|
|
_ => (),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
let prompt = Prompt::new(|input| None, commands);
|
|
|
|
|
|
|
|
self.prompt = Some(prompt);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn open(&mut self, path: PathBuf) -> Result<(), Error> {
|
|
|
|
pub fn open(&mut self, path: PathBuf) -> Result<(), Error> {
|
|
|
|
self.view = Some(View::open(path, self.size)?);
|
|
|
|
self.view = Some(View::open(path, self.size)?);
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
@ -304,10 +314,14 @@ impl Editor {
|
|
|
|
let mut reader = EventStream::new();
|
|
|
|
let mut reader = EventStream::new();
|
|
|
|
let keymap = keymap::default();
|
|
|
|
let keymap = keymap::default();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.set_commands();
|
|
|
|
self.render();
|
|
|
|
self.render();
|
|
|
|
|
|
|
|
|
|
|
|
loop {
|
|
|
|
loop {
|
|
|
|
// Handle key events
|
|
|
|
// Handle key events
|
|
|
|
|
|
|
|
if self.should_close {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
let mut event = reader.next().await;
|
|
|
|
let mut event = reader.next().await;
|
|
|
|
match event {
|
|
|
|
match event {
|
|
|
|
Some(Ok(Event::Resize(width, height))) => {
|
|
|
|
Some(Ok(Event::Resize(width, height))) => {
|
|
|
@ -324,13 +338,6 @@ impl Editor {
|
|
|
|
|
|
|
|
|
|
|
|
self.render();
|
|
|
|
self.render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Some(Ok(Event::Key(KeyEvent {
|
|
|
|
|
|
|
|
code: KeyCode::Char('q'),
|
|
|
|
|
|
|
|
..
|
|
|
|
|
|
|
|
}))) => {
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Some(Ok(Event::Key(event))) => {
|
|
|
|
Some(Ok(Event::Key(event))) => {
|
|
|
|
// TODO: sequences (`gg`)
|
|
|
|
// TODO: sequences (`gg`)
|
|
|
|
// TODO: handle count other than 1
|
|
|
|
// TODO: handle count other than 1
|
|
|
|