mirror of
https://github.com/kdheepak/taskwarrior-tui.git
synced 2025-08-26 21:27:19 +02:00
Implement readline editing features
This commit is contained in:
parent
087aa14584
commit
7cf5e1a1f3
1 changed files with 185 additions and 20 deletions
205
src/main.rs
205
src/main.rs
|
@ -19,6 +19,9 @@ use app::{AppMode, TTApp};
|
||||||
const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
|
const APP_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
const APP_NAME: &str = env!("CARGO_PKG_NAME");
|
const APP_NAME: &str = env!("CARGO_PKG_NAME");
|
||||||
|
|
||||||
|
use rustyline::At;
|
||||||
|
use rustyline::Word;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let matches = App::new(APP_NAME)
|
let matches = App::new(APP_NAME)
|
||||||
.version(APP_VERSION)
|
.version(APP_VERSION)
|
||||||
|
@ -154,21 +157,48 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
|
||||||
app.modify.update("", 0);
|
app.modify.update("", 0);
|
||||||
app.mode = AppMode::TaskReport;
|
app.mode = AppMode::TaskReport;
|
||||||
}
|
}
|
||||||
Key::Right => {
|
Key::Ctrl('f') | Key::Right => {
|
||||||
app.modify.move_forward(1);
|
app.modify.move_forward(1);
|
||||||
}
|
}
|
||||||
Key::Left => {
|
Key::Ctrl('b') | Key::Left => {
|
||||||
app.modify.move_backward(1);
|
app.modify.move_backward(1);
|
||||||
}
|
}
|
||||||
Key::Char(c) => {
|
Key::Char(c) => {
|
||||||
app.modify.insert(c, 1);
|
app.modify.insert(c, 1);
|
||||||
}
|
}
|
||||||
Key::Delete => {
|
|
||||||
app.modify.delete(1);
|
|
||||||
}
|
|
||||||
Key::Backspace => {
|
Key::Backspace => {
|
||||||
app.modify.backspace(1);
|
app.modify.backspace(1);
|
||||||
}
|
}
|
||||||
|
Key::Ctrl('d') | Key::Delete => {
|
||||||
|
app.modify.delete(1);
|
||||||
|
}
|
||||||
|
Key::Ctrl('a') | Key::Home => {
|
||||||
|
app.modify.move_home();
|
||||||
|
}
|
||||||
|
Key::Ctrl('e') | Key::End => {
|
||||||
|
app.modify.move_end();
|
||||||
|
}
|
||||||
|
Key::Ctrl('k') => {
|
||||||
|
app.modify.kill_line();
|
||||||
|
}
|
||||||
|
Key::Ctrl('u') => {
|
||||||
|
app.modify.discard_line();
|
||||||
|
}
|
||||||
|
Key::Ctrl('w') => {
|
||||||
|
app.modify.delete_prev_word(Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('d') => {
|
||||||
|
app.modify.delete_word(At::AfterEnd, Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('f') => {
|
||||||
|
app.modify.move_to_next_word(At::AfterEnd, Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('b') => {
|
||||||
|
app.modify.move_to_prev_word(Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('t') => {
|
||||||
|
app.modify.transpose_words(1);
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
AppMode::TaskSubprocess => match input {
|
AppMode::TaskSubprocess => match input {
|
||||||
|
@ -186,10 +216,10 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
|
||||||
app.command.update("", 0);
|
app.command.update("", 0);
|
||||||
app.mode = AppMode::TaskReport;
|
app.mode = AppMode::TaskReport;
|
||||||
}
|
}
|
||||||
Key::Right => {
|
Key::Ctrl('f') | Key::Right => {
|
||||||
app.command.move_forward(1);
|
app.command.move_forward(1);
|
||||||
}
|
}
|
||||||
Key::Left => {
|
Key::Ctrl('b') | Key::Left => {
|
||||||
app.command.move_backward(1);
|
app.command.move_backward(1);
|
||||||
}
|
}
|
||||||
Key::Char(c) => {
|
Key::Char(c) => {
|
||||||
|
@ -198,9 +228,36 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
|
||||||
Key::Backspace => {
|
Key::Backspace => {
|
||||||
app.command.backspace(1);
|
app.command.backspace(1);
|
||||||
}
|
}
|
||||||
Key::Delete => {
|
Key::Ctrl('d') | Key::Delete => {
|
||||||
app.command.delete(1);
|
app.command.delete(1);
|
||||||
}
|
}
|
||||||
|
Key::Ctrl('a') | Key::Home => {
|
||||||
|
app.command.move_home();
|
||||||
|
}
|
||||||
|
Key::Ctrl('e') | Key::End => {
|
||||||
|
app.command.move_end();
|
||||||
|
}
|
||||||
|
Key::Ctrl('k') => {
|
||||||
|
app.command.kill_line();
|
||||||
|
}
|
||||||
|
Key::Ctrl('u') => {
|
||||||
|
app.command.discard_line();
|
||||||
|
}
|
||||||
|
Key::Ctrl('w') => {
|
||||||
|
app.command.delete_prev_word(Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('d') => {
|
||||||
|
app.command.delete_word(At::AfterEnd, Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('f') => {
|
||||||
|
app.command.move_to_next_word(At::AfterEnd, Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('b') => {
|
||||||
|
app.command.move_to_prev_word(Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('t') => {
|
||||||
|
app.command.transpose_words(1);
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
AppMode::TaskLog => match input {
|
AppMode::TaskLog => match input {
|
||||||
|
@ -218,10 +275,10 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
|
||||||
app.command.update("", 0);
|
app.command.update("", 0);
|
||||||
app.mode = AppMode::TaskReport;
|
app.mode = AppMode::TaskReport;
|
||||||
}
|
}
|
||||||
Key::Right => {
|
Key::Ctrl('f') | Key::Right => {
|
||||||
app.command.move_forward(1);
|
app.command.move_forward(1);
|
||||||
}
|
}
|
||||||
Key::Left => {
|
Key::Ctrl('b') | Key::Left => {
|
||||||
app.command.move_backward(1);
|
app.command.move_backward(1);
|
||||||
}
|
}
|
||||||
Key::Char(c) => {
|
Key::Char(c) => {
|
||||||
|
@ -230,9 +287,36 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
|
||||||
Key::Backspace => {
|
Key::Backspace => {
|
||||||
app.command.backspace(1);
|
app.command.backspace(1);
|
||||||
}
|
}
|
||||||
Key::Delete => {
|
Key::Ctrl('d') | Key::Delete => {
|
||||||
app.command.delete(1);
|
app.command.delete(1);
|
||||||
}
|
}
|
||||||
|
Key::Ctrl('a') | Key::Home => {
|
||||||
|
app.command.move_home();
|
||||||
|
}
|
||||||
|
Key::Ctrl('e') | Key::End => {
|
||||||
|
app.command.move_end();
|
||||||
|
}
|
||||||
|
Key::Ctrl('k') => {
|
||||||
|
app.command.kill_line();
|
||||||
|
}
|
||||||
|
Key::Ctrl('u') => {
|
||||||
|
app.command.discard_line();
|
||||||
|
}
|
||||||
|
Key::Ctrl('w') => {
|
||||||
|
app.command.delete_prev_word(Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('d') => {
|
||||||
|
app.command.delete_word(At::AfterEnd, Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('f') => {
|
||||||
|
app.command.move_to_next_word(At::AfterEnd, Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('b') => {
|
||||||
|
app.command.move_to_prev_word(Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('t') => {
|
||||||
|
app.command.transpose_words(1);
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
AppMode::TaskAnnotate => match input {
|
AppMode::TaskAnnotate => match input {
|
||||||
|
@ -250,10 +334,10 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
|
||||||
app.command.update("", 0);
|
app.command.update("", 0);
|
||||||
app.mode = AppMode::TaskReport;
|
app.mode = AppMode::TaskReport;
|
||||||
}
|
}
|
||||||
Key::Right => {
|
Key::Ctrl('f') | Key::Right => {
|
||||||
app.command.move_forward(1);
|
app.command.move_forward(1);
|
||||||
}
|
}
|
||||||
Key::Left => {
|
Key::Ctrl('b') | Key::Left => {
|
||||||
app.command.move_backward(1);
|
app.command.move_backward(1);
|
||||||
}
|
}
|
||||||
Key::Char(c) => {
|
Key::Char(c) => {
|
||||||
|
@ -262,9 +346,36 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
|
||||||
Key::Backspace => {
|
Key::Backspace => {
|
||||||
app.command.backspace(1);
|
app.command.backspace(1);
|
||||||
}
|
}
|
||||||
Key::Delete => {
|
Key::Ctrl('d') | Key::Delete => {
|
||||||
app.command.delete(1);
|
app.command.delete(1);
|
||||||
}
|
}
|
||||||
|
Key::Ctrl('a') | Key::Home => {
|
||||||
|
app.command.move_home();
|
||||||
|
}
|
||||||
|
Key::Ctrl('e') | Key::End => {
|
||||||
|
app.command.move_end();
|
||||||
|
}
|
||||||
|
Key::Ctrl('k') => {
|
||||||
|
app.command.kill_line();
|
||||||
|
}
|
||||||
|
Key::Ctrl('u') => {
|
||||||
|
app.command.discard_line();
|
||||||
|
}
|
||||||
|
Key::Ctrl('w') => {
|
||||||
|
app.command.delete_prev_word(Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('d') => {
|
||||||
|
app.command.delete_word(At::AfterEnd, Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('f') => {
|
||||||
|
app.command.move_to_next_word(At::AfterEnd, Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('b') => {
|
||||||
|
app.command.move_to_prev_word(Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('t') => {
|
||||||
|
app.command.transpose_words(1);
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
AppMode::TaskAdd => match input {
|
AppMode::TaskAdd => match input {
|
||||||
|
@ -282,10 +393,10 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
|
||||||
app.command.update("", 0);
|
app.command.update("", 0);
|
||||||
app.mode = AppMode::TaskReport;
|
app.mode = AppMode::TaskReport;
|
||||||
}
|
}
|
||||||
Key::Right => {
|
Key::Ctrl('f') | Key::Right => {
|
||||||
app.command.move_forward(1);
|
app.command.move_forward(1);
|
||||||
}
|
}
|
||||||
Key::Left => {
|
Key::Ctrl('b') | Key::Left => {
|
||||||
app.command.move_backward(1);
|
app.command.move_backward(1);
|
||||||
}
|
}
|
||||||
Key::Char(c) => {
|
Key::Char(c) => {
|
||||||
|
@ -294,9 +405,36 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
|
||||||
Key::Backspace => {
|
Key::Backspace => {
|
||||||
app.command.backspace(1);
|
app.command.backspace(1);
|
||||||
}
|
}
|
||||||
Key::Delete => {
|
Key::Ctrl('d') | Key::Delete => {
|
||||||
app.command.delete(1);
|
app.command.delete(1);
|
||||||
}
|
}
|
||||||
|
Key::Ctrl('a') | Key::Home => {
|
||||||
|
app.command.move_home();
|
||||||
|
}
|
||||||
|
Key::Ctrl('e') | Key::End => {
|
||||||
|
app.command.move_end();
|
||||||
|
}
|
||||||
|
Key::Ctrl('k') => {
|
||||||
|
app.command.kill_line();
|
||||||
|
}
|
||||||
|
Key::Ctrl('u') => {
|
||||||
|
app.command.discard_line();
|
||||||
|
}
|
||||||
|
Key::Ctrl('w') => {
|
||||||
|
app.command.delete_prev_word(Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('d') => {
|
||||||
|
app.command.delete_word(At::AfterEnd, Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('f') => {
|
||||||
|
app.command.move_to_next_word(At::AfterEnd, Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('b') => {
|
||||||
|
app.command.move_to_prev_word(Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('t') => {
|
||||||
|
app.command.transpose_words(1);
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
AppMode::TaskFilter => match input {
|
AppMode::TaskFilter => match input {
|
||||||
|
@ -304,10 +442,10 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
|
||||||
app.mode = AppMode::TaskReport;
|
app.mode = AppMode::TaskReport;
|
||||||
app.update();
|
app.update();
|
||||||
}
|
}
|
||||||
Key::Right => {
|
Key::Ctrl('f') | Key::Right => {
|
||||||
app.filter.move_forward(1);
|
app.filter.move_forward(1);
|
||||||
}
|
}
|
||||||
Key::Left => {
|
Key::Ctrl('b') | Key::Left => {
|
||||||
app.filter.move_backward(1);
|
app.filter.move_backward(1);
|
||||||
}
|
}
|
||||||
Key::Char(c) => {
|
Key::Char(c) => {
|
||||||
|
@ -316,9 +454,36 @@ fn tui_main(_config: &str) -> Result<(), Box<dyn Error>> {
|
||||||
Key::Backspace => {
|
Key::Backspace => {
|
||||||
app.filter.backspace(1);
|
app.filter.backspace(1);
|
||||||
}
|
}
|
||||||
Key::Delete => {
|
Key::Ctrl('d') | Key::Delete => {
|
||||||
app.filter.delete(1);
|
app.filter.delete(1);
|
||||||
}
|
}
|
||||||
|
Key::Ctrl('a') | Key::Home => {
|
||||||
|
app.filter.move_home();
|
||||||
|
}
|
||||||
|
Key::Ctrl('e') | Key::End => {
|
||||||
|
app.filter.move_end();
|
||||||
|
}
|
||||||
|
Key::Ctrl('k') => {
|
||||||
|
app.filter.kill_line();
|
||||||
|
}
|
||||||
|
Key::Ctrl('u') => {
|
||||||
|
app.filter.discard_line();
|
||||||
|
}
|
||||||
|
Key::Ctrl('w') => {
|
||||||
|
app.filter.delete_prev_word(Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('d') => {
|
||||||
|
app.filter.delete_word(At::AfterEnd, Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('f') => {
|
||||||
|
app.filter.move_to_next_word(At::AfterEnd, Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('b') => {
|
||||||
|
app.filter.move_to_prev_word(Word::Emacs, 1);
|
||||||
|
}
|
||||||
|
Key::Alt('t') => {
|
||||||
|
app.filter.transpose_words(1);
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
AppMode::TaskError => match input {
|
AppMode::TaskError => match input {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue