Skip to content

Commit

Permalink
minor usabulity improvements for profile modal
Browse files Browse the repository at this point in the history
  • Loading branch information
aprxi committed Aug 17, 2024
1 parent dadac6d commit 8730d4f
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
46 changes: 37 additions & 9 deletions lumni/src/apps/builtin/llm/prompt/src/tui/modals/profiles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@ impl ProfileEditModal {

Ok(WindowEvent::Modal(ModalAction::WaitForKeyEvent))
}

fn cancel_edit(&mut self) {
self.settings_editor.cancel_edit();
self.ui_state.set_edit_mode(EditMode::NotEditing);
}
}

#[async_trait]
Expand Down Expand Up @@ -434,16 +439,39 @@ impl ModalWindowTrait for ProfileEditModal {
) -> Result<WindowEvent, ApplicationError> {
let key_code = key_event.current_key().code;

match self.ui_state.focus {
Focus::ProfileList | Focus::RenamingProfile => {
self.handle_profile_list_input(key_code).await
}
Focus::SettingsList => {
self.handle_settings_list_input(key_code).await
}
let result = match self.ui_state.focus {
Focus::ProfileList => match key_code {
KeyCode::Right | KeyCode::Tab => {
if !self.profile_list.is_empty() {
self.ui_state.set_focus(Focus::SettingsList);
self.load_profile().await?;
}
Ok(WindowEvent::Modal(ModalAction::WaitForKeyEvent))
}
_ => Ok(self.handle_profile_list_input(key_code).await?),
},
Focus::SettingsList => match key_code {
KeyCode::Left
| KeyCode::Char('q')
| KeyCode::Esc
| KeyCode::Tab => {
if self.ui_state.edit_mode == EditMode::NotEditing {
self.ui_state.set_focus(Focus::ProfileList);
} else {
self.cancel_edit();
}
Ok(WindowEvent::Modal(ModalAction::WaitForKeyEvent))
}
_ => Ok(self.handle_settings_list_input(key_code).await?),
},
Focus::NewProfileType => {
self.handle_new_profile_type_input(key_code).await
Ok(self.handle_new_profile_type_input(key_code).await?)
}
}
Focus::RenamingProfile => {
Ok(self.handle_profile_list_input(key_code).await?)
}
};

result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,15 @@ impl ProfileEditRenderer {
) {
(Focus::ProfileList, EditMode::NotEditing) => {
"↑↓: Navigate | Enter: Select/Create | R: Rename | D: Delete | \
Tab: Settings | Esc: Close"
→/Tab: Settings | Esc: Close"
}
(Focus::RenamingProfile, EditMode::RenamingProfile) => {
"Enter: Confirm Rename | Esc: Cancel"
}
(Focus::SettingsList, EditMode::NotEditing) => {
"↑↓: Navigate | Enter: Edit | n: New | N: New Secure | D: \
Delete | C: Clear | S: Show/Hide Secure | Tab: Profiles | \
Esc: Close"
Delete | C: Clear | S: Show/Hide Secure | ←/Tab/q/Esc: \
Profiles"
}
(Focus::SettingsList, EditMode::EditingValue) => {
"Enter: Save | Esc: Cancel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ impl ProfileList {
}
}

pub fn is_empty(&self) -> bool {
self.profiles.is_empty()
}

pub fn get_selected_profile(&self) -> Option<&str> {
self.profiles.get(self.selected_index).map(|s| s.as_str())
}
Expand Down

0 comments on commit 8730d4f

Please sign in to comment.