cursor hidden if not active
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
use crossterm::{
|
use crossterm::{
|
||||||
execute,
|
execute,
|
||||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||||
cursor::{SetCursorStyle, EnableBlinking, Show, MoveTo},
|
cursor::{SetCursorStyle, EnableBlinking, Show, Hide, MoveTo},
|
||||||
};
|
};
|
||||||
use ratatui::{backend::CrosstermBackend, Terminal};
|
use ratatui::{backend::CrosstermBackend, Terminal};
|
||||||
use std::io::{self, stdout, Write};
|
use std::io::{self, stdout, Write};
|
||||||
@@ -64,6 +64,22 @@ impl TerminalCore {
|
|||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn show_cursor(&mut self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
execute!(
|
||||||
|
self.terminal.backend_mut(),
|
||||||
|
Show
|
||||||
|
)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn hide_cursor(&mut self) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
execute!(
|
||||||
|
self.terminal.backend_mut(),
|
||||||
|
Hide
|
||||||
|
)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for TerminalCore {
|
impl Drop for TerminalCore {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use crate::services::grpc_client::GrpcClient;
|
|||||||
use crate::services::ui_service::UiService;
|
use crate::services::ui_service::UiService;
|
||||||
use crate::tui::terminal::EventReader;
|
use crate::tui::terminal::EventReader;
|
||||||
use crate::modes::common::commands::CommandHandler;
|
use crate::modes::common::commands::CommandHandler;
|
||||||
|
use crate::modes::handlers::mode_manager::{AppMode, ModeManager};
|
||||||
use crate::config::colors::themes::Theme;
|
use crate::config::colors::themes::Theme;
|
||||||
use crate::config::binds::config::Config;
|
use crate::config::binds::config::Config;
|
||||||
use crate::ui::handlers::render::render_ui;
|
use crate::ui::handlers::render::render_ui;
|
||||||
@@ -61,6 +62,28 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
);
|
);
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
// --- Cursor Visibility Logic ---
|
||||||
|
let current_mode = ModeManager::derive_mode(&app_state, &event_handler);
|
||||||
|
match current_mode {
|
||||||
|
AppMode::Edit => {
|
||||||
|
terminal.show_cursor()?;
|
||||||
|
}
|
||||||
|
AppMode::ReadOnly => {
|
||||||
|
if !app_state.ui.focus_outside_canvas {
|
||||||
|
terminal.show_cursor()?;
|
||||||
|
} else {
|
||||||
|
terminal.hide_cursor()?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AppMode::General => {
|
||||||
|
terminal.hide_cursor()?;
|
||||||
|
}
|
||||||
|
AppMode::Command => {
|
||||||
|
terminal.hide_cursor()?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// --- End Cursor Visibility Logic ---
|
||||||
|
|
||||||
let total_count = app_state.total_count;
|
let total_count = app_state.total_count;
|
||||||
let mut current_position = app_state.current_position;
|
let mut current_position = app_state.current_position;
|
||||||
// Store position before event handling to detect navigation
|
// Store position before event handling to detect navigation
|
||||||
|
|||||||
Reference in New Issue
Block a user