sidebar fixed bugs and buffer implementation 1
This commit is contained in:
@@ -10,6 +10,7 @@ next_option = ["l", "Right"]
|
|||||||
previous_option = ["h", "Left"]
|
previous_option = ["h", "Left"]
|
||||||
select = ["Enter"]
|
select = ["Enter"]
|
||||||
toggle_sidebar = ["ctrl+t"]
|
toggle_sidebar = ["ctrl+t"]
|
||||||
|
toggle_buffer_list = ["ctrl+b"]
|
||||||
next_field = ["Tab"]
|
next_field = ["Tab"]
|
||||||
prev_field = ["Shift+Tab"]
|
prev_field = ["Shift+Tab"]
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ save_and_quit = ["ctrl+shift+s"]
|
|||||||
move_up = ["Up"]
|
move_up = ["Up"]
|
||||||
move_down = ["Down"]
|
move_down = ["Down"]
|
||||||
toggle_sidebar = ["ctrl+t"]
|
toggle_sidebar = ["ctrl+t"]
|
||||||
|
toggle_buffer_list = ["ctrl+b"]
|
||||||
|
|
||||||
# MODE SPECIFIC
|
# MODE SPECIFIC
|
||||||
# READ ONLY MODE
|
# READ ONLY MODE
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
// src/components/common.rs
|
// src/components/common.rs
|
||||||
pub mod command_line;
|
pub mod command_line;
|
||||||
pub mod status_line;
|
pub mod status_line;
|
||||||
|
pub mod buffer_list;
|
||||||
pub mod background;
|
pub mod background;
|
||||||
pub mod dialog;
|
pub mod dialog;
|
||||||
pub mod autocomplete;
|
pub mod autocomplete;
|
||||||
|
|
||||||
pub use command_line::*;
|
pub use command_line::*;
|
||||||
pub use status_line::*;
|
pub use status_line::*;
|
||||||
|
pub use buffer_list::*;
|
||||||
pub use background::*;
|
pub use background::*;
|
||||||
pub use dialog::*;
|
pub use dialog::*;
|
||||||
pub use autocomplete::*;
|
pub use autocomplete::*;
|
||||||
|
|||||||
53
client/src/components/common/buffer_list.rs
Normal file
53
client/src/components/common/buffer_list.rs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
// src/components/common/buffer_list.rs
|
||||||
|
|
||||||
|
use crate::config::colors::themes::Theme;
|
||||||
|
use crate::state::app::state::AppState;
|
||||||
|
use ratatui::{
|
||||||
|
layout::Rect,
|
||||||
|
style::{Style, Stylize},
|
||||||
|
text::Line,
|
||||||
|
widgets::{Block, Borders, List, ListItem, ListState},
|
||||||
|
Frame,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn render_buffer_list(
|
||||||
|
f: &mut Frame,
|
||||||
|
area: Rect,
|
||||||
|
theme: &Theme,
|
||||||
|
app_state: &AppState,
|
||||||
|
) {
|
||||||
|
let mut items = Vec::new();
|
||||||
|
let mut current_buffer_name = "*scratch*"; // Default if nothing else is shown
|
||||||
|
|
||||||
|
// Determine the active buffer name based on UI state
|
||||||
|
if app_state.ui.show_intro {
|
||||||
|
current_buffer_name = "Intro";
|
||||||
|
} else if app_state.ui.show_register {
|
||||||
|
current_buffer_name = "Register";
|
||||||
|
} else if app_state.ui.show_login {
|
||||||
|
current_buffer_name = "Login";
|
||||||
|
} else if app_state.ui.show_admin {
|
||||||
|
current_buffer_name = "Admin Panel";
|
||||||
|
} else if app_state.ui.show_form {
|
||||||
|
current_buffer_name = "Data Form"; // Or derive from selected profile/table if needed
|
||||||
|
}
|
||||||
|
|
||||||
|
items.push(ListItem::new(Line::from(vec![
|
||||||
|
" ".into(), // Padding
|
||||||
|
current_buffer_name.fg(theme.highlight),
|
||||||
|
" ".into(), // Padding
|
||||||
|
])));
|
||||||
|
|
||||||
|
let list = List::new(items)
|
||||||
|
.block(
|
||||||
|
Block::default()
|
||||||
|
.borders(Borders::TOP) // Simple top border
|
||||||
|
.border_style(Style::default().fg(theme.secondary)),
|
||||||
|
)
|
||||||
|
.style(Style::default().bg(theme.bg).fg(theme.fg));
|
||||||
|
|
||||||
|
let mut state = ListState::default();
|
||||||
|
|
||||||
|
f.render_stateful_widget(list, area, &mut state);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -43,12 +43,6 @@ pub async fn handle_navigation_event(
|
|||||||
previous_option(app_state, intro_state);
|
previous_option(app_state, intro_state);
|
||||||
return Ok(EventOutcome::Ok(String::new()));
|
return Ok(EventOutcome::Ok(String::new()));
|
||||||
}
|
}
|
||||||
"toggle_sidebar" => {
|
|
||||||
toggle_sidebar(app_state);
|
|
||||||
return Ok(EventOutcome::Ok(format!("Sidebar {}",
|
|
||||||
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
"next_field" => {
|
"next_field" => {
|
||||||
next_field(form_state);
|
next_field(form_state);
|
||||||
return Ok(EventOutcome::Ok(String::new()));
|
return Ok(EventOutcome::Ok(String::new()));
|
||||||
@@ -140,10 +134,6 @@ pub fn previous_option(app_state: &mut AppState, intro_state: &mut IntroState) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_sidebar(app_state: &mut AppState) {
|
|
||||||
app_state.ui.show_sidebar = !app_state.ui.show_sidebar;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn next_field(form_state: &mut FormState) {
|
pub fn next_field(form_state: &mut FormState) {
|
||||||
if !form_state.fields.is_empty() {
|
if !form_state.fields.is_empty() {
|
||||||
form_state.current_field = (form_state.current_field + 1) % form_state.fields.len();
|
form_state.current_field = (form_state.current_field + 1) % form_state.fields.len();
|
||||||
|
|||||||
@@ -101,6 +101,13 @@ impl EventHandler {
|
|||||||
);
|
);
|
||||||
return Ok(EventOutcome::Ok(message));
|
return Ok(EventOutcome::Ok(message));
|
||||||
}
|
}
|
||||||
|
if UiStateHandler::toggle_buffer_list(&mut app_state.ui, config, key_code, modifiers) {
|
||||||
|
let message = format!("Buffer {}",
|
||||||
|
if app_state.ui.show_buffer_list { "shown" } else { "hidden" }
|
||||||
|
);
|
||||||
|
return Ok(EventOutcome::Ok(message));
|
||||||
|
}
|
||||||
|
// --- End Global UI Toggles ---
|
||||||
|
|
||||||
match current_mode {
|
match current_mode {
|
||||||
AppMode::General => {
|
AppMode::General => {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ pub struct DialogState {
|
|||||||
|
|
||||||
pub struct UiState {
|
pub struct UiState {
|
||||||
pub show_sidebar: bool,
|
pub show_sidebar: bool,
|
||||||
|
pub show_buffer_list: bool,
|
||||||
pub show_intro: bool,
|
pub show_intro: bool,
|
||||||
pub show_admin: bool,
|
pub show_admin: bool,
|
||||||
pub show_form: bool,
|
pub show_form: bool,
|
||||||
@@ -136,6 +137,7 @@ impl Default for UiState {
|
|||||||
show_form: false,
|
show_form: false,
|
||||||
show_login: false,
|
show_login: false,
|
||||||
show_register: false,
|
show_register: false,
|
||||||
|
show_buffer_list: false,
|
||||||
focus_outside_canvas: false,
|
focus_outside_canvas: false,
|
||||||
dialog: DialogState::default(),
|
dialog: DialogState::default(),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,4 +21,18 @@ impl UiStateHandler {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn toggle_buffer_list(
|
||||||
|
ui_state: &mut UiState,
|
||||||
|
config: &Config,
|
||||||
|
key: KeyCode,
|
||||||
|
modifiers: KeyModifiers,
|
||||||
|
) -> bool {
|
||||||
|
if let Some(action) = config.get_common_action(key, modifiers) {
|
||||||
|
if action == "toggle_buffer_list" {
|
||||||
|
ui_state.show_buffer_list = !ui_state.show_buffer_list;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use crate::components::{
|
use crate::components::{
|
||||||
render_background,
|
render_background,
|
||||||
|
render_buffer_list,
|
||||||
render_command_line,
|
render_command_line,
|
||||||
render_status_line,
|
render_status_line,
|
||||||
intro::intro::render_intro,
|
intro::intro::render_intro,
|
||||||
@@ -40,16 +41,42 @@ pub fn render_ui(
|
|||||||
) {
|
) {
|
||||||
render_background(f, f.area(), theme);
|
render_background(f, f.area(), theme);
|
||||||
|
|
||||||
|
// Adjust layout based on whether buffer list is shown
|
||||||
|
let constraints = if app_state.ui.show_buffer_list {
|
||||||
|
vec![
|
||||||
|
Constraint::Min(1), // Main content
|
||||||
|
Constraint::Length(1), // Buffer list
|
||||||
|
Constraint::Length(1), // Status line
|
||||||
|
Constraint::Length(1), // Command line
|
||||||
|
]
|
||||||
|
} else {
|
||||||
|
vec![
|
||||||
|
Constraint::Min(1), // Main content
|
||||||
|
Constraint::Length(1), // Status line (no buffer list)
|
||||||
|
Constraint::Length(1), // Command line
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
let root = Layout::default()
|
let root = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([
|
.constraints(constraints)
|
||||||
Constraint::Min(1),
|
|
||||||
Constraint::Length(1),
|
|
||||||
Constraint::Length(1),
|
|
||||||
])
|
|
||||||
.split(f.area());
|
.split(f.area());
|
||||||
|
|
||||||
let main_content_area = root[0];
|
let main_content_area = root[0];
|
||||||
|
let mut buffer_list_area = None;
|
||||||
|
let status_line_area;
|
||||||
|
let command_line_area;
|
||||||
|
|
||||||
|
// Assign areas based on layout
|
||||||
|
if app_state.ui.show_buffer_list {
|
||||||
|
buffer_list_area = Some(root[1]);
|
||||||
|
status_line_area = root[2];
|
||||||
|
command_line_area = root[3];
|
||||||
|
} else {
|
||||||
|
status_line_area = root[1];
|
||||||
|
command_line_area = root[2];
|
||||||
|
}
|
||||||
|
|
||||||
if app_state.ui.show_intro {
|
if app_state.ui.show_intro {
|
||||||
render_intro(f, intro_state, main_content_area, theme);
|
render_intro(f, intro_state, main_content_area, theme);
|
||||||
} else if app_state.ui.show_register {
|
} else if app_state.ui.show_register {
|
||||||
@@ -61,7 +88,7 @@ pub fn render_ui(
|
|||||||
app_state,
|
app_state,
|
||||||
register_state.current_field < 4
|
register_state.current_field < 4
|
||||||
);
|
);
|
||||||
}else if app_state.ui.show_login {
|
} else if app_state.ui.show_login {
|
||||||
render_login(
|
render_login(
|
||||||
f,
|
f,
|
||||||
main_content_area,
|
main_content_area,
|
||||||
@@ -136,10 +163,14 @@ pub fn render_ui(
|
|||||||
total_count,
|
total_count,
|
||||||
current_position,
|
current_position,
|
||||||
);
|
);
|
||||||
} else{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render_status_line(f, root[1], current_dir, theme, is_edit_mode);
|
// Render buffer list if enabled and area is available
|
||||||
render_command_line(f, root[2], command_input, command_mode, theme, command_message);
|
if let Some(area) = buffer_list_area {
|
||||||
|
if app_state.ui.show_buffer_list {
|
||||||
|
render_buffer_list(f, area, theme, app_state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
render_status_line(f, status_line_area, current_dir, theme, is_edit_mode);
|
||||||
|
render_command_line(f, command_line_area, command_input, command_mode, theme, command_message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user