select between open editors, create new ones with ctrl+N
This commit is contained in:
parent
7d1a2bc412
commit
8194ff2ec2
2 changed files with 30 additions and 5 deletions
|
@ -108,11 +108,12 @@ impl Editor {
|
||||||
}
|
}
|
||||||
self.status_line();
|
self.status_line();
|
||||||
print!(
|
print!(
|
||||||
"{}",
|
"{}{}",
|
||||||
cursor::Goto(
|
cursor::Goto(
|
||||||
self.physical_column() as u16 + 1,
|
self.physical_column() as u16 + 1,
|
||||||
(self.cursor.line - self.scroll) as u16 + 1
|
(self.cursor.line - self.scroll) as u16 + 1
|
||||||
)
|
),
|
||||||
|
cursor::Show
|
||||||
);
|
);
|
||||||
stdout().flush().unwrap();
|
stdout().flush().unwrap();
|
||||||
}
|
}
|
||||||
|
|
30
src/main.rs
30
src/main.rs
|
@ -5,7 +5,7 @@ use std::{
|
||||||
};
|
};
|
||||||
use termion::{
|
use termion::{
|
||||||
clear, color,
|
clear, color,
|
||||||
cursor::Goto,
|
cursor::{self, Goto},
|
||||||
event::{Event, Key},
|
event::{Event, Key},
|
||||||
input::TermRead,
|
input::TermRead,
|
||||||
raw::{IntoRawMode, RawTerminal},
|
raw::{IntoRawMode, RawTerminal},
|
||||||
|
@ -50,8 +50,9 @@ impl Navigator {
|
||||||
|
|
||||||
fn draw(&self) {
|
fn draw(&self) {
|
||||||
print!(
|
print!(
|
||||||
"{}{}Open editors: {}",
|
"{}{}{}Open editors: {}",
|
||||||
clear::All,
|
clear::All,
|
||||||
|
cursor::Hide,
|
||||||
Goto(1, 1),
|
Goto(1, 1),
|
||||||
self.editors.len()
|
self.editors.len()
|
||||||
);
|
);
|
||||||
|
@ -73,20 +74,43 @@ impl Navigator {
|
||||||
match key {
|
match key {
|
||||||
Key::Esc => self.quit(),
|
Key::Esc => self.quit(),
|
||||||
Key::Char('\n') => self.open_selected(),
|
Key::Char('\n') => self.open_selected(),
|
||||||
|
Key::Ctrl('n') => self.new_editor(),
|
||||||
|
Key::Up => self.nav_up(),
|
||||||
|
Key::Down => self.nav_down(),
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn nav_up(&mut self) {
|
||||||
|
if self.selected > Some(0) {
|
||||||
|
self.selected = Some(self.selected.unwrap() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn nav_down(&mut self) {
|
||||||
|
if let Some(index) = self.selected.as_mut() {
|
||||||
|
if *index < self.editors.len() - 1 {
|
||||||
|
*index += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn open_selected(&mut self) {
|
fn open_selected(&mut self) {
|
||||||
if let Some(index) = self.selected {
|
if let Some(index) = self.selected {
|
||||||
self.editors[index].open();
|
self.editors[index].open();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn new_editor(&mut self) {
|
||||||
|
self.selected = Some(self.editors.len());
|
||||||
|
self.editors.push(Editor::new(None));
|
||||||
|
self.open_selected();
|
||||||
|
}
|
||||||
|
|
||||||
fn quit(&self) {
|
fn quit(&self) {
|
||||||
print!("{}", clear::All);
|
print!("{}{}", clear::All, cursor::Show);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue