summaryrefslogtreecommitdiff
path: root/makima/src/daemon/tui/app.rs
diff options
context:
space:
mode:
authorsoryu <soryu@soryu.co>2026-01-21 15:58:34 +0000
committersoryu <soryu@soryu.co>2026-01-21 15:58:34 +0000
commitda246c4c4e23c9ad976705f9a3fa80e0d75b4425 (patch)
treeddc3b93ed269e60dac1aa9113000daeac4a1b6e6 /makima/src/daemon/tui/app.rs
parent7155e6cd7ddf25a5a4d4f6d6abecd49f0cf519dc (diff)
downloadsoryu-da246c4c4e23c9ad976705f9a3fa80e0d75b4425.tar.gz
soryu-da246c4c4e23c9ad976705f9a3fa80e0d75b4425.zip
Update CLI to show repo suggestions
Diffstat (limited to 'makima/src/daemon/tui/app.rs')
-rw-r--r--makima/src/daemon/tui/app.rs85
1 files changed, 82 insertions, 3 deletions
diff --git a/makima/src/daemon/tui/app.rs b/makima/src/daemon/tui/app.rs
index ea431b8..cb0e8f3 100644
--- a/makima/src/daemon/tui/app.rs
+++ b/makima/src/daemon/tui/app.rs
@@ -78,6 +78,16 @@ pub enum CreateFormField {
Repository,
}
+/// Repository suggestion from history
+#[derive(Debug, Clone)]
+pub struct RepositorySuggestion {
+ pub name: String,
+ pub repository_url: Option<String>,
+ pub local_path: Option<String>,
+ pub source_type: String,
+ pub use_count: i32,
+}
+
/// State for create contract form
#[derive(Debug, Clone, Default)]
pub struct CreateContractState {
@@ -94,11 +104,13 @@ pub struct CreateContractState {
/// Cursor position in current text field
pub cursor: usize,
/// Available repository suggestions
- pub repo_suggestions: Vec<String>,
+ pub repo_suggestions: Vec<RepositorySuggestion>,
/// Selected suggestion index (for repository field)
pub selected_suggestion: usize,
/// Whether suggestions popup is visible
pub show_suggestions: bool,
+ /// Whether suggestions have been loaded
+ pub suggestions_loaded: bool,
}
impl CreateContractState {
@@ -113,6 +125,47 @@ impl CreateContractState {
repo_suggestions: Vec::new(),
selected_suggestion: 0,
show_suggestions: false,
+ suggestions_loaded: false,
+ }
+ }
+
+ /// Set repository suggestions
+ pub fn set_suggestions(&mut self, suggestions: Vec<RepositorySuggestion>) {
+ self.repo_suggestions = suggestions;
+ self.selected_suggestion = 0;
+ self.show_suggestions = !self.repo_suggestions.is_empty();
+ self.suggestions_loaded = true;
+ }
+
+ /// Apply the selected suggestion to the form
+ pub fn apply_selected_suggestion(&mut self) {
+ if let Some(suggestion) = self.repo_suggestions.get(self.selected_suggestion) {
+ // Apply the suggestion
+ if let Some(ref url) = suggestion.repository_url {
+ self.repository_url = url.clone();
+ } else if let Some(ref path) = suggestion.local_path {
+ self.repository_url = path.clone();
+ }
+ self.cursor = self.repository_url.len();
+ self.show_suggestions = false;
+ }
+ }
+
+ /// Navigate to next suggestion
+ pub fn next_suggestion(&mut self) {
+ if !self.repo_suggestions.is_empty() {
+ self.selected_suggestion = (self.selected_suggestion + 1) % self.repo_suggestions.len();
+ }
+ }
+
+ /// Navigate to previous suggestion
+ pub fn prev_suggestion(&mut self) {
+ if !self.repo_suggestions.is_empty() {
+ self.selected_suggestion = if self.selected_suggestion == 0 {
+ self.repo_suggestions.len() - 1
+ } else {
+ self.selected_suggestion - 1
+ };
}
}
@@ -156,14 +209,14 @@ impl CreateContractState {
pub fn next_field(&mut self) {
self.focused_field = (self.focused_field + 1) % 4;
self.cursor = self.current_value().map(|v| v.len()).unwrap_or(0);
- self.show_suggestions = false;
+ // Don't hide suggestions - they stay visible
}
/// Move to previous field
pub fn prev_field(&mut self) {
self.focused_field = if self.focused_field == 0 { 3 } else { self.focused_field - 1 };
self.cursor = self.current_value().map(|v| v.len()).unwrap_or(0);
- self.show_suggestions = false;
+ // Don't hide suggestions - they stay visible
}
/// Toggle contract type
@@ -445,6 +498,14 @@ pub enum Action {
contract_type: String,
repository_url: Option<String>,
},
+ /// Request to load repository suggestions (internal)
+ LoadRepoSuggestions,
+ /// Navigate to next suggestion in create form
+ CreateNextSuggestion,
+ /// Navigate to previous suggestion in create form
+ CreatePrevSuggestion,
+ /// Apply selected suggestion in create form
+ CreateApplySuggestion,
}
/// A displayable item in the TUI
@@ -1068,6 +1129,8 @@ impl App {
if self.view_type == ViewType::Contracts {
self.create_state = CreateContractState::new();
self.input_mode = InputMode::CreateName;
+ // Request to load repository suggestions
+ return Action::LoadRepoSuggestions;
}
Action::None
}
@@ -1125,6 +1188,22 @@ impl App {
// Pass through to caller for API call
Action::PerformCreateContract { name, description, contract_type, repository_url }
}
+ Action::LoadRepoSuggestions => {
+ // Pass through to caller for API call
+ Action::LoadRepoSuggestions
+ }
+ Action::CreateNextSuggestion => {
+ self.create_state.next_suggestion();
+ Action::None
+ }
+ Action::CreatePrevSuggestion => {
+ self.create_state.prev_suggestion();
+ Action::None
+ }
+ Action::CreateApplySuggestion => {
+ self.create_state.apply_selected_suggestion();
+ Action::None
+ }
Action::None => Action::None,
}
}