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