@@ -36,7 +36,8 @@ pub struct Editor {
3636 size: (u16, u16),
3737 surface: Surface,
3838 cache: Surface,
39− prompt: Prompt,
39+ prompt: Option<Prompt>,
40+ should_close: bool,
4041}
4142
4243impl Editor {
@@ -46,7 +47,6 @@ impl Editor {
4647 let mut terminal = Terminal::new(backend)?;
4748 let size = terminal::size().unwrap();
4849 let area = Rect::new(0, 0, size.0, size.1);
49− let prompt = Prompt::new();
5050
5151 let mut editor = Editor {
5252 terminal,
@@ -55,7 +55,8 @@ impl Editor {
5555 surface: Surface::empty(area),
5656 cache: Surface::empty(area),
5757 // TODO; move to state
58− prompt,
58+ prompt: None,
59+ should_close: false,
5960 };
6061
6162 if let Some(file) = args.values_of_t::<PathBuf>("files").unwrap().pop() {
@@ -65,6 +66,15 @@ impl Editor {
6566 Ok(editor)
6667 }
6768
69+ pub fn set_commands(self) {
70+ let commands = |input: &str| match input {
71+ "q" => self.should_close = true,
72+ _ => (),
73+ };
74+ let prompt = Prompt::new(|input| None, commands);
75+ self.prompt = Some(prompt);
76+ }
77+
6878 pub fn open(&mut self, path: PathBuf) -> Result<(), Error> {
6979 self.view = Some(View::open(path, self.size)?);
7080 Ok(())
@@ -304,10 +314,14 @@ impl Editor {
304314 let mut reader = EventStream::new();
305315 let keymap = keymap::default();
306316
317+ self.set_commands();
307318 self.render();
308319
309320 loop {
310321 // Handle key events
322+ if self.should_close {
323+ break;
324+ }
311325 let mut event = reader.next().await;
312326 match event {
313327 Some(Ok(Event::Resize(width, height))) => {
@@ -324,13 +338,6 @@ impl Editor {
324338
325339 self.render();
326340 }
327− Some(Ok(Event::Key(KeyEvent {
328− code: KeyCode::Char('q'),
329− ..
330− }))) => {
331− break;
332− }
333−
334341 Some(Ok(Event::Key(event))) => {
335342 // TODO: sequences (`gg`)
336343 // TODO: handle count other than 1