diff options
| author | soryu <soryu@soryu.co> | 2026-01-20 17:23:34 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-01-20 17:23:46 +0000 |
| commit | 055e2c4a72e3b2331a18fdc9f8132ef990af7e38 (patch) | |
| tree | 75b92637b9132594b76a5a86f5f854bca1ddee49 /makima/src/daemon/tui/event.rs | |
| parent | 54c6d409e1d5667f4ab7f63a43e1459e68575c94 (diff) | |
| download | soryu-055e2c4a72e3b2331a18fdc9f8132ef990af7e38.tar.gz soryu-055e2c4a72e3b2331a18fdc9f8132ef990af7e38.zip | |
Update CLI to show log history as well
Diffstat (limited to 'makima/src/daemon/tui/event.rs')
| -rw-r--r-- | makima/src/daemon/tui/event.rs | 57 |
1 files changed, 53 insertions, 4 deletions
diff --git a/makima/src/daemon/tui/event.rs b/makima/src/daemon/tui/event.rs index 0e3874b..2fed55a 100644 --- a/makima/src/daemon/tui/event.rs +++ b/makima/src/daemon/tui/event.rs @@ -3,7 +3,7 @@ use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyModifiers}; use std::time::Duration; -use super::app::{Action, App, InputMode, ViewType}; +use super::app::{Action, App, CreateFormField, InputMode, ViewType}; /// Poll for events with timeout pub fn poll_event(timeout: Duration) -> std::io::Result<Option<Event>> { @@ -22,15 +22,16 @@ pub fn handle_key_event(app: &App, key: KeyEvent) -> Action { } match app.input_mode { - InputMode::Normal => handle_normal_mode(key), + InputMode::Normal => handle_normal_mode(app, key), InputMode::Search => handle_search_mode(key), InputMode::Confirm => handle_confirm_mode(key), InputMode::EditName | InputMode::EditDescription => handle_edit_mode(key), + InputMode::CreateName | InputMode::CreateDescription => handle_create_mode(app, key), } } /// Handle key events in normal navigation mode -fn handle_normal_mode(key: KeyEvent) -> Action { +fn handle_normal_mode(app: &App, key: KeyEvent) -> Action { // Check for Ctrl+C first if key.modifiers.contains(KeyModifiers::CONTROL) { match key.code { @@ -55,6 +56,9 @@ fn handle_normal_mode(key: KeyEvent) -> Action { KeyCode::Char('d') => Action::Delete, KeyCode::Char('c') => Action::Navigate, // cd to worktree + // New contract (only in contracts view) + KeyCode::Char('n') if app.view_type == ViewType::Contracts => Action::NewContract, + // Preview toggle (space to show details in preview pane) KeyCode::Char(' ') => Action::Select, @@ -180,13 +184,58 @@ fn handle_edit_mode(key: KeyEvent) -> Action { } } +/// Handle key events in create contract mode +fn handle_create_mode(app: &App, key: KeyEvent) -> Action { + // Check for Ctrl+C first + if key.modifiers.contains(KeyModifiers::CONTROL) { + if let KeyCode::Char('c') = key.code { + return Action::Quit; + } + } + + let current_field = app.create_state.current_field(); + + match key.code { + // Submit form + KeyCode::Enter => { + // If on contract type field, toggle instead of submit + if current_field == CreateFormField::ContractType { + Action::CreateToggle + } else { + Action::CreateSubmit + } + } + + // Cancel + KeyCode::Esc => Action::CreateCancel, + + // Navigate between fields + KeyCode::Tab => Action::CreateNextField, + KeyCode::BackTab => Action::CreatePrevField, + KeyCode::Up => Action::CreatePrevField, + KeyCode::Down => Action::CreateNextField, + + // Toggle for contract type field + KeyCode::Char(' ') if current_field == CreateFormField::ContractType => Action::CreateToggle, + KeyCode::Left if current_field == CreateFormField::ContractType => Action::CreateToggle, + KeyCode::Right if current_field == CreateFormField::ContractType => Action::CreateToggle, + + // Text input (for text fields) + KeyCode::Char(c) if current_field != CreateFormField::ContractType => Action::CreateChar(c), + KeyCode::Backspace if current_field != CreateFormField::ContractType => Action::CreateBackspace, + + _ => Action::None, + } +} + /// Get help text for current mode pub fn get_help_text(mode: InputMode) -> &'static str { match mode { - InputMode::Normal => "j/k: nav | Enter: open | Esc/h: back | e: edit | d: del | c: cd | /: search | q: quit", + InputMode::Normal => "j/k: nav | Enter: open | Esc/h: back | e: edit | d: del | n: new | /: search | q: quit", InputMode::Search => "Type to search | Enter/Esc: exit search | Up/Down: navigate", InputMode::Confirm => "y: confirm | n/Esc: cancel", InputMode::EditName | InputMode::EditDescription => "Type to edit | Tab: switch field | Enter: save | Esc: cancel", + InputMode::CreateName | InputMode::CreateDescription => "Type to edit | Tab/↑↓: switch field | Enter: create | Esc: cancel", } } |
