save split config that works
This commit is contained in:
@@ -6,7 +6,7 @@ pub struct Theme {
|
||||
pub bg: Color,
|
||||
pub fg: Color,
|
||||
pub accent: Color,
|
||||
pub secondary: Color, // Add this field
|
||||
pub secondary: Color,
|
||||
pub highlight: Color,
|
||||
pub warning: Color,
|
||||
pub border: Color,
|
||||
|
||||
@@ -17,8 +17,8 @@ pub fn render_form(
|
||||
inputs: &[&String],
|
||||
theme: &Theme,
|
||||
is_edit_mode: bool,
|
||||
total_count: u64, // Add total count
|
||||
current_position: u64, // Add current position
|
||||
total_count: u64,
|
||||
current_position: u64,
|
||||
) {
|
||||
// Create Adresar card
|
||||
let adresar_card = Block::default()
|
||||
@@ -61,9 +61,13 @@ pub fn render_form(
|
||||
let input_container = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(if is_edit_mode {
|
||||
Style::default().fg(theme.accent)
|
||||
if form_state.has_unsaved_changes {
|
||||
Style::default().fg(theme.warning) // Red color
|
||||
} else {
|
||||
Style::default().fg(theme.accent) // Blue color
|
||||
}
|
||||
} else {
|
||||
Style::default().fg(theme.secondary)
|
||||
Style::default().fg(theme.secondary) // Yellow color
|
||||
})
|
||||
.style(Style::default().bg(theme.bg));
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ impl EventHandler {
|
||||
app_terminal: &mut AppTerminal,
|
||||
form_state: &mut FormState,
|
||||
is_saved: &mut bool,
|
||||
total_count: usize,
|
||||
current_position: &mut usize,
|
||||
total_count: u64,
|
||||
current_position: &mut u64,
|
||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
||||
if let Event::Key(key) = event {
|
||||
if !self.is_edit_mode && config.is_enter_edit_mode(key.code, key.modifiers) {
|
||||
|
||||
@@ -23,6 +23,7 @@ pub struct FormState {
|
||||
pub fax: String,
|
||||
pub current_field: usize,
|
||||
pub fields: Vec<&'static str>,
|
||||
pub has_unsaved_changes: bool,
|
||||
}
|
||||
|
||||
impl FormState {
|
||||
@@ -44,6 +45,7 @@ impl FormState {
|
||||
skladu: String::new(),
|
||||
fax: String::new(),
|
||||
current_field: 0,
|
||||
has_unsaved_changes: false,
|
||||
fields: vec![
|
||||
"Firma", "KZ", "DRC", "Ulica", "PSC", "Mesto", "Stat", "Banka",
|
||||
"Ucet", "Skladm", "ICO", "Kontakt", "Telefon", "Skladu", "Fax",
|
||||
@@ -57,8 +59,8 @@ impl FormState {
|
||||
area: Rect,
|
||||
theme: &Theme,
|
||||
is_edit_mode: bool,
|
||||
total_count: usize,
|
||||
current_position: usize,
|
||||
total_count: u64,
|
||||
current_position: u64,
|
||||
) {
|
||||
render_form(
|
||||
f,
|
||||
@@ -71,8 +73,8 @@ impl FormState {
|
||||
],
|
||||
&theme,
|
||||
is_edit_mode,
|
||||
total_count as u64, // Convert to u64 here
|
||||
current_position as u64, // Convert to u64 here
|
||||
total_count,
|
||||
current_position,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ pub fn render_ui(
|
||||
form_state: &mut FormState,
|
||||
theme: &Theme,
|
||||
is_edit_mode: bool,
|
||||
total_count: usize,
|
||||
current_position: usize,
|
||||
total_count: u64,
|
||||
current_position: u64,
|
||||
current_dir: &str,
|
||||
command_input: &str,
|
||||
command_mode: bool,
|
||||
|
||||
@@ -5,8 +5,8 @@ use std::env;
|
||||
pub struct AppState {
|
||||
pub is_saved: bool,
|
||||
pub current_dir: String,
|
||||
pub total_count: usize,
|
||||
pub current_position: usize,
|
||||
pub total_count: u64,
|
||||
pub current_position: u64,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
@@ -22,11 +22,11 @@ impl AppState {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn update_total_count(&mut self, total_count: usize) {
|
||||
pub fn update_total_count(&mut self, total_count: u64) {
|
||||
self.total_count = total_count;
|
||||
}
|
||||
|
||||
pub fn update_current_position(&mut self, current_position: usize) {
|
||||
pub fn update_current_position(&mut self, current_position: u64) {
|
||||
self.current_position = current_position;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
// Fetch the total count of Adresar entries
|
||||
let total_count = app_terminal.get_adresar_count().await?;
|
||||
app_state.update_total_count(total_count as usize);
|
||||
app_state.update_current_position((total_count + 1) as usize);
|
||||
app_state.update_total_count(total_count);
|
||||
app_state.update_current_position(total_count + 1);
|
||||
|
||||
loop {
|
||||
let total_count = app_terminal.get_adresar_count().await?;
|
||||
app_state.update_total_count(total_count as usize);
|
||||
app_state.update_total_count(total_count);
|
||||
|
||||
app_terminal.draw(|f| {
|
||||
render_ui(
|
||||
|
||||
Reference in New Issue
Block a user