compiled and working sidebar in ratatui

This commit is contained in:
filipriec
2025-03-21 15:53:40 +01:00
parent c46bbc26e1
commit d067f5b515
10 changed files with 134 additions and 14 deletions

View File

@@ -0,0 +1,45 @@
// src/ui/handlers/rat_state.rs
use crossterm::event::{KeyCode, KeyModifiers};
use crate::config::config::Config;
use crate::state::state::UiState;
pub struct UiStateHandler;
impl UiStateHandler {
pub fn toggle_sidebar(
ui_state: &mut UiState,
config: &Config,
key: KeyCode,
modifiers: KeyModifiers,
) -> bool {
if let Some(action) = config.get_action_for_key_in_mode(&config.keybindings.common, key, modifiers) {
if action == "toggle_sidebar" {
ui_state.show_sidebar = !ui_state.show_sidebar;
return true;
}
}
false
}
// Keep your existing handle_ui_action method if you need it for other UI actions
pub fn handle_ui_action(
ui_state: &mut UiState,
config: &Config,
key: KeyCode,
modifiers: KeyModifiers,
) -> bool {
let mut action_performed = false;
// Check for sidebar toggle
if let Some(action) = config.get_action_for_key_in_mode(&config.keybindings.common, key, modifiers) {
if action == "toggle_sidebar" {
ui_state.show_sidebar = !ui_state.show_sidebar;
action_performed = true;
}
}
// Add other UI actions here following the same pattern
action_performed
}
}

View File

@@ -5,6 +5,7 @@ use crate::config::colors::Theme;
use ratatui::layout::{Constraint, Direction, Layout};
use ratatui::Frame;
use super::form::FormState;
use crate::state::state::UiState;
pub fn render_ui(
f: &mut Frame,
@@ -17,6 +18,7 @@ pub fn render_ui(
command_input: &str,
command_mode: bool,
command_message: &str,
ui_state: &UiState,
) {
let root = Layout::default()
.direction(Direction::Vertical)
@@ -45,6 +47,10 @@ pub fn render_ui(
&theme,
);
if ui_state.show_sidebar {
crate::components::handlers::sidebar::render_sidebar(f, main_chunks[0], theme);
}
// Status line
render_status_line(f, root[1], current_dir, theme, is_edit_mode);

View File

@@ -59,9 +59,13 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
&event_handler.command_input,
event_handler.command_mode,
&event_handler.command_message,
&app_state.ui,
);
})?;
let total_count = app_state.total_count;
let mut current_position = app_state.current_position;
let event = event_reader.read_event()?;
let (should_exit, message) = event_handler.handle_event(
event,
@@ -70,11 +74,13 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
&mut grpc_client,
&mut command_handler,
&mut form_state,
&mut app_state.is_saved,
app_state.total_count,
&mut app_state.current_position,
&mut app_state,
total_count,
&mut current_position,
).await?;
app_state.current_position = current_position;
// Handle position changes and update form state
if !event_handler.is_edit_mode {
let current_input = form_state.get_current_input();