Use rustyline for input

This commit is contained in:
Dheepak Krishnamurthy 2020-10-10 02:27:43 -06:00
parent 603e400bbd
commit 96fd6551f8
4 changed files with 290 additions and 205 deletions

View file

@ -109,33 +109,27 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
Key::Char('m') => {
app.mode = AppMode::TaskModify;
match app.task_current() {
Some(t) => app.modify = t.description().to_string(),
None => app.modify = "".to_string(),
Some(t) => app.modify.update(t.description(), 0),
None => app.modify.update("", 0),
}
app.cursor_location = app.modify.chars().count();
}
Key::Char('!') => {
app.mode = AppMode::TaskSubprocess;
app.cursor_location = app.command.chars().count();
}
Key::Char('l') => {
app.mode = AppMode::TaskLog;
app.cursor_location = app.command.chars().count();
}
Key::Char('a') => {
app.mode = AppMode::TaskAdd;
app.cursor_location = app.command.chars().count();
}
Key::Char('A') => {
app.mode = AppMode::TaskAnnotate;
app.cursor_location = app.command.chars().count();
}
Key::Char('?') => {
app.mode = AppMode::TaskHelpPopup;
}
Key::Char('/') => {
app.mode = AppMode::TaskFilter;
app.cursor_location = app.filter.chars().count();
}
_ => {}
},
@ -157,34 +151,23 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
}
},
Key::Esc => {
app.modify = "".to_string();
app.modify.update("", 0);
app.mode = AppMode::TaskReport;
}
Key::Right => {
if app.cursor_location < app.modify.chars().count() {
app.cursor_location += 1;
}
app.modify.move_forward(1);
}
Key::Left => {
if app.cursor_location > 0 {
app.cursor_location -= 1;
}
app.modify.move_backward(1);
}
Key::Char(c) => {
if app.cursor_location < app.modify.chars().count() {
app.modify.insert_str(app.cursor_location, &c.to_string());
} else {
app.modify.push(c);
}
app.cursor_location += 1;
app.modify.insert(c, 1);
}
Key::Delete => {
app.modify.delete(1);
}
Key::Backspace => {
if app.cursor_location > 0 {
app.cursor_location -= 1;
let mut cs = app.modify.chars().collect::<Vec<char>>();
cs.remove(app.cursor_location);
app.modify = cs.into_iter().collect();
}
app.modify.backspace(1);
}
_ => {}
},
@ -200,34 +183,23 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
}
},
Key::Esc => {
app.command = "".to_string();
app.command.update("", 0);
app.mode = AppMode::TaskReport;
}
Key::Right => {
if app.cursor_location < app.command.chars().count() {
app.cursor_location += 1;
}
app.command.move_forward(1);
}
Key::Left => {
if app.cursor_location > 0 {
app.cursor_location -= 1;
}
app.command.move_backward(1);
}
Key::Char(c) => {
if app.cursor_location < app.command.chars().count() {
app.command.insert_str(app.cursor_location, &c.to_string());
} else {
app.command.push(c);
}
app.cursor_location += 1;
app.command.insert(c, 1);
}
Key::Backspace => {
if app.cursor_location > 0 {
app.cursor_location -= 1;
let mut cs = app.command.chars().collect::<Vec<char>>();
cs.remove(app.cursor_location);
app.command = cs.into_iter().collect();
}
app.command.backspace(1);
}
Key::Delete => {
app.command.delete(1);
}
_ => {}
},
@ -243,34 +215,23 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
}
},
Key::Esc => {
app.command = "".to_string();
app.command.update("", 0);
app.mode = AppMode::TaskReport;
}
Key::Right => {
if app.cursor_location < app.command.chars().count() {
app.cursor_location += 1;
}
app.command.move_forward(1);
}
Key::Left => {
if app.cursor_location > 0 {
app.cursor_location -= 1;
}
app.command.move_backward(1);
}
Key::Char(c) => {
if app.cursor_location < app.command.chars().count() {
app.command.insert_str(app.cursor_location, &c.to_string());
} else {
app.command.push(c);
}
app.cursor_location += 1;
app.command.insert(c, 1);
}
Key::Backspace => {
if app.cursor_location > 0 {
app.cursor_location -= 1;
let mut cs = app.command.chars().collect::<Vec<char>>();
cs.remove(app.cursor_location);
app.command = cs.into_iter().collect();
}
app.command.backspace(1);
}
Key::Delete => {
app.command.delete(1);
}
_ => {}
},
@ -286,34 +247,23 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
}
},
Key::Esc => {
app.command = "".to_string();
app.command.update("", 0);
app.mode = AppMode::TaskReport;
}
Key::Right => {
if app.cursor_location < app.command.chars().count() {
app.cursor_location += 1;
}
app.command.move_forward(1);
}
Key::Left => {
if app.cursor_location > 0 {
app.cursor_location -= 1;
}
app.command.move_backward(1);
}
Key::Char(c) => {
if app.cursor_location < app.command.chars().count() {
app.command.insert_str(app.cursor_location, &c.to_string());
} else {
app.command.push(c);
}
app.cursor_location += 1;
app.command.insert(c, 1);
}
Key::Backspace => {
if app.cursor_location > 0 {
app.cursor_location -= 1;
let mut cs = app.command.chars().collect::<Vec<char>>();
cs.remove(app.cursor_location);
app.command = cs.into_iter().collect();
}
app.command.backspace(1);
}
Key::Delete => {
app.command.delete(1);
}
_ => {}
},
@ -329,34 +279,23 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
}
},
Key::Esc => {
app.command = "".to_string();
app.command.update("", 0);
app.mode = AppMode::TaskReport;
}
Key::Right => {
if app.cursor_location < app.command.chars().count() {
app.cursor_location += 1;
}
app.command.move_forward(1);
}
Key::Left => {
if app.cursor_location > 0 {
app.cursor_location -= 1;
}
app.command.move_backward(1);
}
Key::Char(c) => {
if app.cursor_location < app.command.chars().count() {
app.command.insert_str(app.cursor_location, &c.to_string());
} else {
app.command.push(c);
}
app.cursor_location += 1;
app.command.insert(c, 1);
}
Key::Backspace => {
if app.cursor_location > 0 {
app.cursor_location -= 1;
let mut cs = app.command.chars().collect::<Vec<char>>();
cs.remove(app.cursor_location);
app.command = cs.into_iter().collect();
}
app.command.backspace(1);
}
Key::Delete => {
app.command.delete(1);
}
_ => {}
},
@ -366,30 +305,19 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
app.update();
}
Key::Right => {
if app.cursor_location < app.filter.chars().count() {
app.cursor_location += 1;
}
app.filter.move_forward(1);
}
Key::Left => {
if app.cursor_location > 0 {
app.cursor_location -= 1;
}
app.filter.move_backward(1);
}
Key::Char(c) => {
if app.cursor_location < app.filter.chars().count() {
app.filter.insert_str(app.cursor_location, &c.to_string());
} else {
app.filter.push(c);
}
app.cursor_location += 1;
app.filter.insert(c, 1);
}
Key::Backspace => {
if app.cursor_location > 0 {
app.cursor_location -= 1;
let mut cs = app.filter.chars().collect::<Vec<char>>();
cs.remove(app.cursor_location);
app.filter = cs.into_iter().collect();
}
app.filter.backspace(1);
}
Key::Delete => {
app.filter.delete(1);
}
_ => {}
},