Skip to content

Commit a89eeae

Browse files
authored
Merge pull request #7 from papitz/feature/editor_popout
Feature/editor popout
2 parents 1c700a7 + 866f46f commit a89eeae

6 files changed

Lines changed: 274 additions & 24 deletions

File tree

Cargo.lock

Lines changed: 112 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ ratatui = "0.28"
88
crossterm = "0.28"
99
serde = { version = "1.0", features = ["derive"] }
1010
serde_json = "1.0"
11-
directories = "5.0"
11+
directories = "5.0"
12+
edit = "0.1.5"

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@ tui-kanban
7171
- **?** - Show help
7272
- **q** - Quit the application
7373

74+
#### Editing
75+
In any field while you are editing.
76+
- **ctrl+e** - Open external editor ($EDITOR)
77+
7478
#### Task Detail View
75-
- **Tab** - Switch between fields (Title, Tags, Description)
79+
- **Tab or j** - Next field
80+
- **Shift+Tab or k** - Previous field
7681
- **Enter** - Edit focused field
7782
- **1-9** - Remove tag by number (when Tags field is focused)
7883
- **Esc** - Close task detail view

src/app.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub struct App {
1818
pub disable_saving: bool, // For testing
1919
pub theme: Theme,
2020
pub selected_theme_index: usize, // for theme selector view
21+
pub error_message: String,
2122
}
2223

2324
// which field is focused in task detail view
@@ -44,6 +45,21 @@ pub enum InputMode {
4445
RenamingColumn,
4546
ConfirmingDelete,
4647
SelectingTheme,
48+
ShowErrorInfo,
49+
}
50+
51+
impl InputMode {
52+
pub fn has_open_input(&self) -> bool {
53+
match self {
54+
Self::AddingTask
55+
| Self::AddingTag
56+
| Self::EditingTitle
57+
| Self::EditingDescription
58+
| Self::RenamingColumn
59+
| Self::AddingProject => true,
60+
_ => false,
61+
}
62+
}
4763
}
4864

4965
impl App {
@@ -77,6 +93,7 @@ impl App {
7793
disable_saving: false,
7894
theme,
7995
selected_theme_index: 0,
96+
error_message: String::new(),
8097
}
8198
}
8299

@@ -119,6 +136,7 @@ impl App {
119136
disable_saving: true,
120137
theme: Theme::default(),
121138
selected_theme_index: 0,
139+
error_message: String::new(),
122140
}
123141
}
124142

@@ -378,6 +396,20 @@ impl App {
378396
self.input_buffer.pop();
379397
}
380398

399+
// Open the external editor defined in $EDITOR
400+
pub fn open_external_editor(&mut self) {
401+
match edit::edit(&self.input_buffer) {
402+
Ok(edited) => self.input_buffer = edited,
403+
Err(e) => self.handle_error(e.to_string()),
404+
}
405+
}
406+
407+
// handle error by switching to error info mode
408+
fn handle_error(&mut self, error_message: String) {
409+
self.error_message = error_message;
410+
self.input_mode = InputMode::ShowErrorInfo;
411+
}
412+
381413
// submit input
382414
pub fn submit_input(&mut self) {
383415
match self.input_mode {
@@ -472,7 +504,8 @@ impl App {
472504
| InputMode::ViewingHelp
473505
| InputMode::ProjectList
474506
| InputMode::ConfirmingDelete
475-
| InputMode::SelectingTheme => {}
507+
| InputMode::SelectingTheme
508+
| InputMode::ShowErrorInfo => {}
476509
}
477510
self.cancel_input();
478511
}
@@ -496,6 +529,15 @@ impl App {
496529
};
497530
}
498531

532+
// cycle to previous field in task detail view
533+
pub fn previous_field(&mut self) {
534+
self.focused_field = match self.focused_field {
535+
TaskField::Title => TaskField::Description,
536+
TaskField::Description => TaskField::Tags,
537+
TaskField::Tags => TaskField::Title,
538+
}
539+
}
540+
499541
// start editing title
500542
pub fn start_editing_title(&mut self) {
501543
if let Some(column) = self.board().get_column(self.selected_column) {
@@ -641,6 +683,12 @@ impl App {
641683
self.input_mode = InputMode::Normal;
642684
}
643685

686+
// TODO: This should probably go back to the last mode instead of always Normal
687+
pub fn close_error_info(&mut self) {
688+
self.input_mode = InputMode::Normal;
689+
self.error_message.clear();
690+
}
691+
644692
// show help view
645693
pub fn show_help(&mut self) {
646694
self.input_mode = InputMode::ViewingHelp;

0 commit comments

Comments
 (0)