killing of the buffer now works amazingly well
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
use crate::config::colors::themes::Theme;
|
||||
use crate::state::app::buffer::BufferState;
|
||||
use crate::state::app::state::AppState; // Add this import
|
||||
use ratatui::{
|
||||
layout::{Alignment, Rect},
|
||||
style::Style,
|
||||
@@ -17,6 +18,7 @@ pub fn render_buffer_list(
|
||||
area: Rect,
|
||||
theme: &Theme,
|
||||
buffer_state: &BufferState,
|
||||
app_state: &AppState, // Add this parameter
|
||||
) {
|
||||
// --- Style Definitions ---
|
||||
let active_style = Style::default()
|
||||
@@ -37,6 +39,9 @@ pub fn render_buffer_list(
|
||||
let mut spans = Vec::new();
|
||||
let mut current_width = 0;
|
||||
|
||||
// TODO: Replace with actual table name from server response
|
||||
let current_table_name = Some("2025_customer");
|
||||
|
||||
for (original_index, view) in buffer_state.history.iter().enumerate() {
|
||||
// Filter: Only process views matching the active layer
|
||||
if get_view_layer(view) != active_layer {
|
||||
@@ -44,7 +49,7 @@ pub fn render_buffer_list(
|
||||
}
|
||||
|
||||
let is_active = original_index == buffer_state.active_index;
|
||||
let buffer_name = view.display_name();
|
||||
let buffer_name = view.display_name_with_context(current_table_name);
|
||||
let buffer_text = format!(" {} ", buffer_name);
|
||||
let text_width = UnicodeWidthStr::width(buffer_text.as_str());
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ pub fn get_view_layer(view: &AppView) -> u8 {
|
||||
match view {
|
||||
AppView::Intro => 1,
|
||||
AppView::Login | AppView::Register | AppView::Admin | AppView::AddTable | AppView::AddLogic => 2,
|
||||
AppView::Form(_) | AppView::Scratch => 3,
|
||||
AppView::Form | AppView::Scratch => 3,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,10 +121,7 @@ impl EventHandler {
|
||||
else if ui.show_admin { AppView::Admin }
|
||||
else if ui.show_add_logic { AppView::AddLogic }
|
||||
else if ui.show_add_table { AppView::AddTable }
|
||||
else if ui.show_form {
|
||||
let form_name = app_state.selected_profile.clone().unwrap_or_else(|| "Data Form".to_string());
|
||||
AppView::Form(form_name)
|
||||
}
|
||||
else if ui.show_form { AppView::Form } // Remove the dynamic name part
|
||||
else { AppView::Scratch }
|
||||
};
|
||||
buffer_state.update_history(current_view);
|
||||
@@ -177,8 +174,14 @@ impl EventHandler {
|
||||
return Ok(EventOutcome::Ok("Switched to previous buffer".to_string()));
|
||||
}
|
||||
}
|
||||
//"close_buffer" => {
|
||||
// let message = buffer_state.close_buffer_with_intro_fallback();
|
||||
// return Ok(EventOutcome::Ok(message));
|
||||
//}
|
||||
"close_buffer" => {
|
||||
let message = buffer_state.close_buffer_with_intro_fallback();
|
||||
// TODO: Replace with actual table name from server response
|
||||
let current_table_name = Some("2025_customer"); // Your hardcoded table name
|
||||
let message = buffer_state.close_buffer_with_intro_fallback(current_table_name);
|
||||
return Ok(EventOutcome::Ok(message));
|
||||
}
|
||||
_ => {}
|
||||
|
||||
@@ -8,11 +8,13 @@ pub enum AppView {
|
||||
Admin,
|
||||
AddTable,
|
||||
AddLogic,
|
||||
Form(String),
|
||||
Form, // Remove the String parameter
|
||||
Scratch,
|
||||
}
|
||||
|
||||
impl AppView {
|
||||
/// Returns the display name for the view.
|
||||
/// For Form, pass the current table name to get dynamic naming.
|
||||
pub fn display_name(&self) -> &str {
|
||||
match self {
|
||||
AppView::Intro => "Intro",
|
||||
@@ -21,12 +23,25 @@ impl AppView {
|
||||
AppView::Admin => "Admin_Panel",
|
||||
AppView::AddTable => "Add_Table",
|
||||
AppView::AddLogic => "Add_Logic",
|
||||
AppView::Form(name) => name.as_str(),
|
||||
AppView::Form => "Form", // Default fallback
|
||||
AppView::Scratch => "*scratch*",
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the display name with dynamic context (for Form buffers)
|
||||
pub fn display_name_with_context(&self, current_table_name: Option<&str>) -> String {
|
||||
match self {
|
||||
AppView::Form => {
|
||||
current_table_name
|
||||
.unwrap_or("Data Form")
|
||||
.to_string()
|
||||
}
|
||||
_ => self.display_name().to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rest of BufferState implementation remains the same
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct BufferState {
|
||||
pub history: Vec<AppView>,
|
||||
@@ -80,7 +95,7 @@ impl BufferState {
|
||||
true
|
||||
}
|
||||
|
||||
pub fn close_buffer_with_intro_fallback(&mut self) -> String {
|
||||
pub fn close_buffer_with_intro_fallback(&mut self, current_table_name: Option<&str>) -> String {
|
||||
let current_view_cloned = self.get_active_view().cloned();
|
||||
if let Some(AppView::Intro) = current_view_cloned {
|
||||
return "Cannot close intro buffer".to_string();
|
||||
@@ -88,7 +103,7 @@ impl BufferState {
|
||||
|
||||
let closed_name = current_view_cloned
|
||||
.as_ref()
|
||||
.map(|v| v.display_name().to_string())
|
||||
.map(|v| v.display_name_with_context(current_table_name))
|
||||
.unwrap_or_else(|| "Unknown".to_string());
|
||||
|
||||
if self.close_active_buffer() {
|
||||
|
||||
@@ -13,10 +13,7 @@ pub fn handle_intro_selection(
|
||||
index: usize,
|
||||
) {
|
||||
let target_view = match index {
|
||||
0 => {
|
||||
let form_name = app_state.selected_profile.clone().unwrap_or_else(|| "Data Form".to_string());
|
||||
AppView::Form(form_name)
|
||||
}
|
||||
0 => AppView::Form,
|
||||
1 => AppView::Admin,
|
||||
2 => AppView::Login,
|
||||
3 => AppView::Register,
|
||||
|
||||
@@ -201,7 +201,7 @@ pub fn render_ui(
|
||||
// Render buffer list if enabled and area is available
|
||||
if let Some(area) = buffer_list_area {
|
||||
if app_state.ui.show_buffer_list {
|
||||
render_buffer_list(f, area, theme, buffer_state);
|
||||
render_buffer_list(f, area, theme, buffer_state, app_state);
|
||||
}
|
||||
}
|
||||
render_status_line(f, status_line_area, current_dir, theme, is_edit_mode, current_fps);
|
||||
|
||||
@@ -104,7 +104,7 @@ pub async fn run_ui() -> Result<()> {
|
||||
// --- DATA2: Adjust initial view based on auth status ---
|
||||
if auto_logged_in {
|
||||
// User is auto-logged in, go to main app view
|
||||
buffer_state.history = vec![AppView::Form("Adresar".to_string())];
|
||||
buffer_state.history = vec![AppView::Form];
|
||||
buffer_state.active_index = 0;
|
||||
info!("Initial view set to Form due to auto-login.");
|
||||
}
|
||||
@@ -163,7 +163,7 @@ pub async fn run_ui() -> Result<()> {
|
||||
}
|
||||
AppView::AddTable => app_state.ui.show_add_table = true,
|
||||
AppView::AddLogic => app_state.ui.show_add_logic = true,
|
||||
AppView::Form(_) => app_state.ui.show_form = true,
|
||||
AppView::Form => app_state.ui.show_form = true,
|
||||
AppView::Scratch => {} // Or show a scratchpad component
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user