it works amazingly well now, we can select the table name via command line

This commit is contained in:
filipriec
2025-05-30 22:46:32 +02:00
parent b0c865ab76
commit ff74e1aaa1
4 changed files with 387 additions and 140 deletions

View File

@@ -15,8 +15,9 @@ use crate::components::{
};
use crate::config::colors::themes::Theme;
use ratatui::{
layout::{Constraint, Direction, Layout, Rect},
style::Style,
// layout::{Constraint, Direction, Layout, Rect}, // Rect might be unused if all areas are handled
layout::{Constraint, Direction, Layout}, // Style might be unused if all styling is in components
// style::Style, // Style might be unused
Frame,
};
use crate::state::pages::canvas_state::CanvasState;
@@ -47,7 +48,7 @@ pub fn render_ui(
event_handler_command_input: &str,
event_handler_command_mode_active: bool,
event_handler_command_message: &str,
navigation_state: &NavigationState,
navigation_state: &NavigationState, // This is the correct reference
total_count: u64,
current_position: u64,
current_dir: &str,
@@ -56,28 +57,31 @@ pub fn render_ui(
) {
render_background(f, f.area(), theme);
const PALETTE_OPTIONS_HEIGHT_FOR_LAYOUT: u16 = 15; // Matches component's internal const
const PALETTE_OPTIONS_HEIGHT_FOR_LAYOUT: u16 = 15;
let mut bottom_area_constraints: Vec<Constraint> = vec![Constraint::Length(1)];
let mut bottom_area_constraints: Vec<Constraint> = vec![Constraint::Length(1)]; // For status_line
let command_palette_area_height = if navigation_state.active {
1 + PALETTE_OPTIONS_HEIGHT_FOR_LAYOUT // Input line + fixed height for options
} else if event_handler_command_mode_active {
1
1 // Normal command line
} else {
0
0 // Neither is active
};
if command_palette_area_height > 0 {
// This constraint is for the command_render_area (palette or command line)
bottom_area_constraints.push(Constraint::Length(command_palette_area_height));
}
let mut main_layout_constraints = vec![Constraint::Min(1)];
let mut main_layout_constraints = vec![Constraint::Min(1)]; // Main content area
if app_state.ui.show_buffer_list {
main_layout_constraints.insert(0, Constraint::Length(1));
main_layout_constraints.insert(0, Constraint::Length(1)); // Buffer list at the top
}
// bottom_area_constraints already contains status_line and potentially command_palette_area
main_layout_constraints.extend(bottom_area_constraints);
let root_chunks = Layout::default()
.direction(Direction::Vertical)
.constraints(main_layout_constraints)
@@ -85,8 +89,9 @@ pub fn render_ui(
let mut chunk_idx = 0;
let buffer_list_area = if app_state.ui.show_buffer_list {
let area = Some(root_chunks[chunk_idx]);
chunk_idx += 1;
Some(root_chunks[0])
area
} else {
None
};
@@ -97,12 +102,19 @@ pub fn render_ui(
let status_line_area = root_chunks[chunk_idx];
chunk_idx += 1;
let mut command_render_area = None;
if command_palette_area_height > 0 {
let command_render_area = if command_palette_area_height > 0 {
// Check if there's a chunk available for command_render_area
if root_chunks.len() > chunk_idx {
command_render_area = Some(root_chunks[chunk_idx]);
Some(root_chunks[chunk_idx])
} else {
// This case should ideally not happen if constraints are set up correctly
// but as a fallback, don't try to render if no area.
None
}
}
} else {
None
};
// --- Render main content views ---
if app_state.ui.show_intro {
@@ -110,7 +122,7 @@ pub fn render_ui(
} else if app_state.ui.show_register {
render_register(
f, main_content_area, theme, register_state, app_state,
register_state.current_field() < 4,
register_state.current_field() < 4, // Assuming 4 fields before buttons
highlight_state,
);
} else if app_state.ui.show_add_table {
@@ -127,7 +139,7 @@ pub fn render_ui(
} else if app_state.ui.show_login {
render_login(
f, main_content_area, theme, login_state, app_state,
login_state.current_field() < 2,
login_state.current_field() < 2, // Assuming 2 fields before buttons
highlight_state,
);
} else if app_state.ui.show_admin {
@@ -145,14 +157,15 @@ pub fn render_ui(
);
}
let available_width = form_actual_area.width;
// Center the form if space allows, otherwise use available width
let form_render_area = if available_width >= 80 {
Layout::default().direction(Direction::Horizontal)
.constraints([Constraint::Min(0), Constraint::Length(80), Constraint::Min(0)])
.split(main_content_area)[1]
.split(form_actual_area)[1] // Use form_actual_area here
} else {
Layout::default().direction(Direction::Horizontal)
.constraints([Constraint::Min(0), Constraint::Length(available_width.min(80)), Constraint::Min(0)])
.split(form_actual_area)[1]
.constraints([Constraint::Min(0), Constraint::Length(available_width), Constraint::Min(0)])
.split(form_actual_area)[1] // Use form_actual_area here
};
let fields_vec: Vec<&str> = form_state.fields.iter().map(AsRef::as_ref).collect();
let values_vec: Vec<&String> = form_state.values.iter().collect();
@@ -162,32 +175,30 @@ pub fn render_ui(
total_count, current_position,
);
}
// --- End main content views ---
if let Some(area) = buffer_list_area {
if app_state.ui.show_buffer_list {
render_buffer_list(f, area, theme, buffer_state, app_state);
}
// No need to check app_state.ui.show_buffer_list again, area is Some only if true
render_buffer_list(f, area, theme, buffer_state, app_state);
}
render_status_line(f, status_line_area, current_dir, theme, is_event_handler_edit_mode, current_fps);
if let Some(area) = command_render_area {
// Render command line or find_file_palette
if let Some(palette_or_command_area) = command_render_area { // Use the calculated area
if navigation_state.active {
// Call the new component
find_file_palette::render_find_file_palette(
f,
area,
palette_or_command_area, // Use the correct area
theme,
&navigation_state.input,
&navigation_state.filtered_options.iter().map(|(_, opt)| opt.clone()).collect::<Vec<_>>(),
navigation_state.selected_index,
navigation_state, // Pass the navigation_state directly
);
} else if event_handler_command_mode_active {
render_command_line(
f,
area,
palette_or_command_area, // Use the correct area
event_handler_command_input,
true,
true, // Assuming it's always active when this branch is hit
theme,
event_handler_command_message,
);