working general mode only with canvas, removing highlight, readonly or edit

This commit is contained in:
filipriec
2025-08-23 23:34:14 +02:00
parent 88a4b2d69c
commit 06cc1663b3
6 changed files with 112 additions and 259 deletions

View File

@@ -29,8 +29,9 @@ use crate::ui::handlers::context::DialogPurpose;
use crate::utils::columns::filter_user_columns;
use canvas::keymap::KeyEventOutcome;
use anyhow::{Context, Result};
use crossterm::cursor::SetCursorStyle;
use crossterm::cursor::{SetCursorStyle, MoveTo};
use crossterm::event as crossterm_event;
use crossterm::ExecutableCommand;
use tracing::{error, info, warn};
use tokio::sync::mpsc;
use std::time::Instant;
@@ -641,53 +642,63 @@ pub async fn run_ui() -> Result<()> {
if event_processed || needs_redraw || position_changed {
let current_mode = ModeManager::derive_mode(&app_state, &event_handler, &router);
match current_mode {
AppMode::Edit => { terminal.show_cursor()?; }
AppMode::Highlight => { terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?; terminal.show_cursor()?; }
AppMode::ReadOnly => {
if !app_state.ui.focus_outside_canvas { terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?; }
else { terminal.set_cursor_style(SetCursorStyle::SteadyUnderScore)?; }
terminal.show_cursor().context("Failed to show cursor in ReadOnly mode")?;
}
AppMode::General => {
if app_state.ui.focus_outside_canvas { terminal.set_cursor_style(SetCursorStyle::SteadyUnderScore)?; terminal.show_cursor()?; }
else { terminal.hide_cursor()?; }
if app_state.ui.focus_outside_canvas {
// General mode, focus outside canvas but canvas exists
if let Some(editor) = &app_state.form_editor {
// Get last known cursor position from canvas
let x = editor.cursor_position() as u16;
let y = editor.current_field() as u16;
// Force underscore cursor at that position
terminal.set_cursor_style(SetCursorStyle::SteadyUnderScore)?;
terminal.show_cursor()?;
// Move cursor to last known canvas position
terminal.set_cursor_position(x, y)?;
} else {
// No canvas at all → hide cursor
terminal.hide_cursor()?;
}
} else {
// General mode, focus inside canvas → let canvas handle cursor
// Do nothing here
}
}
AppMode::Command => { terminal.set_cursor_style(SetCursorStyle::SteadyUnderScore)?; terminal.show_cursor().context("Failed to show cursor in Command mode")?; }
AppMode::Command => {
// Command line overlay → always steady block
terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?;
terminal
.show_cursor()
.context("Failed to show cursor in Command mode")?;
}
}
// Temporarily work around borrow checker by extracting needed values
// Workaround for borrow checker
let current_dir = app_state.current_dir.clone();
// Since we can't borrow app_state both mutably and immutably,
// we'll need to either:
// 1. Modify render_ui to take just app_state and access form_state internally, OR
// 2. Extract the specific fields render_ui needs from app_state
// For now, using approach where we temporarily clone what we need
let form_state_clone = app_state.form_state().unwrap().clone();
terminal.draw(|f| {
// Use a mutable clone for rendering
let mut temp_form_state = form_state_clone.clone();
render_ui(
f,
&mut router,
&buffer_state,
&theme,
event_handler.is_edit_mode,
&event_handler.command_input,
event_handler.command_mode,
&event_handler.command_message,
&event_handler.navigation_state,
&current_dir,
current_fps,
&app_state,
);
// If render_ui modified the form_state, we'd need to sync it back
// But typically render functions don't modify state, just read it
}).context("Terminal draw call failed")?;
terminal
.draw(|f| {
let mut temp_form_state = form_state_clone.clone();
render_ui(
f,
&mut router,
&buffer_state,
&theme,
event_handler.is_edit_mode,
&event_handler.command_input,
event_handler.command_mode,
&event_handler.command_message,
&event_handler.navigation_state,
&current_dir,
current_fps,
&app_state,
);
})
.context("Terminal draw call failed")?;
needs_redraw = false;
}