From c4356dcff60ae11e5c5ecdab049a16e22cda40f2 Mon Sep 17 00:00:00 2001 From: filipriec Date: Sun, 16 Feb 2025 21:36:43 +0100 Subject: [PATCH] working multi --- src/client/colors.rs | 37 +++++++++++++++------------ src/client/components/command_line.rs | 10 ++++---- src/client/components/form.rs | 16 +++++++----- src/client/components/preview_card.rs | 22 ++++++++-------- src/client/ui.rs | 7 +++-- 5 files changed, 52 insertions(+), 40 deletions(-) diff --git a/src/client/colors.rs b/src/client/colors.rs index ec40f30..c02d8b6 100644 --- a/src/client/colors.rs +++ b/src/client/colors.rs @@ -1,20 +1,25 @@ // src/client/colors.rs use ratatui::style::Color; -// Pastel Gray Theme -pub struct PastelGrayTheme; - -impl PastelGrayTheme { - // Background colors - pub const BG: Color = Color::Rgb(245, 245, 245); // Light gray - pub const BG_DARK: Color = Color::Rgb(220, 220, 220); // Slightly darker gray - - // Text colors - pub const FG: Color = Color::Rgb(64, 64, 64); // Dark gray - pub const FG_LIGHT: Color = Color::Rgb(128, 128, 128); // Medium gray - - // Accent colors - pub const ACCENT: Color = Color::Rgb(173, 216, 230); // Pastel blue - pub const WARNING: Color = Color::Rgb(255, 182, 193); // Pastel pink - pub const HIGHLIGHT: Color = Color::Rgb(152, 251, 152); // Pastel green +#[derive(Debug, Clone)] +pub struct Theme { + pub bg: Color, + pub fg: Color, + pub accent: Color, + pub highlight: Color, + pub warning: Color, + pub border: Color, +} + +impl Default for Theme { + fn default() -> Self { + Self { + bg: Color::Rgb(245, 245, 245), // Light gray + fg: Color::Rgb(64, 64, 64), // Dark gray + accent: Color::Rgb(173, 216, 230), // Pastel blue + highlight: Color::Rgb(152, 251, 152), // Pastel green + warning: Color::Rgb(255, 182, 193), // Pastel pink + border: Color::Rgb(220, 220, 220), // Light gray border + } + } } diff --git a/src/client/components/command_line.rs b/src/client/components/command_line.rs index 0accaea..1d8b100 100644 --- a/src/client/components/command_line.rs +++ b/src/client/components/command_line.rs @@ -5,18 +5,18 @@ use ratatui::{ layout::Rect, Frame, }; -use crate::client::colors::PastelGrayTheme; +use crate::client::colors::Theme; -pub fn render_command_line(f: &mut Frame, area: Rect, input: &str, active: bool) { +pub fn render_command_line(f: &mut Frame, area: Rect, input: &str, active: bool, theme: &Theme) { let prompt = if active { ":" } else { "Press ':' for commands" }; let style = if active { - Style::default().fg(DoomColors::CYAN) + Style::default().fg(theme.accent) } else { - Style::default().fg(DoomColors::HL) + Style::default().fg(theme.fg) }; let paragraph = Paragraph::new(format!("{}{}", prompt, input)) - .block(Block::default().style(Style::default().bg(DoomColors::BG))) + .block(Block::default().style(Style::default().bg(theme.bg))) .style(style); f.render_widget(paragraph, area); diff --git a/src/client/components/form.rs b/src/client/components/form.rs index 0f8f195..75495b1 100644 --- a/src/client/components/form.rs +++ b/src/client/components/form.rs @@ -6,7 +6,7 @@ use ratatui::{ text::Line, Frame, }; -use crate::client::colors::PastelGrayTheme; +use crate::client::colors::Theme; pub fn render_form( f: &mut Frame, @@ -14,6 +14,7 @@ pub fn render_form( fields: &[&str], current_field: &usize, inputs: &[&String], + theme: &Theme, ) { let form_chunks = Layout::default() .direction(Direction::Vertical) @@ -34,22 +35,23 @@ pub fn render_form( let input = inputs[i].clone(); let is_active = i == *current_field; + // Add this block construction let block = Block::default() .borders(Borders::ALL) .border_style(Style::default().fg(if is_active { - PastelGrayTheme::ACCENT + theme.accent } else { - PastelGrayTheme::FG_LIGHT + theme.border })) .title(Line::from(field.to_string())) - .style(Style::default().bg(PastelGrayTheme::BG).fg(PastelGrayTheme::FG)); + .style(Style::default().bg(theme.bg).fg(theme.fg)); let paragraph = Paragraph::new(input.as_str()) - .block(block) + .block(block) // Now using the defined block .style(if is_active { - Style::default().fg(PastelGrayTheme::HIGHLIGHT) + Style::default().fg(theme.highlight) } else { - Style::default().fg(PastelGrayTheme::FG) + Style::default().fg(theme.fg) }); f.render_widget(paragraph, form_blocks[i]); diff --git a/src/client/components/preview_card.rs b/src/client/components/preview_card.rs index a6709c6..7dbed02 100644 --- a/src/client/components/preview_card.rs +++ b/src/client/components/preview_card.rs @@ -1,31 +1,33 @@ // src/client/components/preview_card.rs use ratatui::{ - widgets::{Block, List, ListItem}, + widgets::{Block, Borders, List, ListItem}, layout::Rect, style::Style, text::Text, Frame, }; -use crate::client::colors::PastelGrayTheme; +use crate::client::colors::Theme; -pub fn render_preview_card(f: &mut Frame, area: Rect, fields: &[&String]) { +pub fn render_preview_card(f: &mut Frame, area: Rect, fields: &[&String], theme: &Theme) { let card = Block::default() - .borders(ratatui::widgets::Borders::ALL) - .border_style(Style::default().fg(DoomColors::HL)) + .borders(Borders::ALL) + .border_style(Style::default().fg(theme.border)) .title(" Preview Card ") - .style(Style::default().bg(DoomColors::BG)); + .style(Style::default().bg(theme.bg).fg(theme.fg)); - let _inner_area = card.inner(area); // Prefix with underscore to indicate intentional unused - let items = vec![ ListItem::new(Text::from(format!("Firma: {}", fields[0]))), ListItem::new(Text::from(format!("Ulica: {}", fields[1]))), - // ... other fields ... + ListItem::new(Text::from(format!("Mesto: {}", fields[2]))), + ListItem::new(Text::from(format!("PSC: {}", fields[3]))), + ListItem::new(Text::from(format!("ICO: {}", fields[4]))), + ListItem::new(Text::from(format!("Kontakt: {}", fields[5]))), + ListItem::new(Text::from(format!("Telefon: {}", fields[6]))), ]; let list = List::new(items) .block(card) - .style(Style::default().bg(DoomColors::BG).fg(DoomColors::FG)); + .style(Style::default().bg(theme.bg).fg(theme.fg)); f.render_widget(list, area); } diff --git a/src/client/ui.rs b/src/client/ui.rs index 424779e..44a1e8c 100644 --- a/src/client/ui.rs +++ b/src/client/ui.rs @@ -11,7 +11,7 @@ use ratatui::{ }; use std::io; use crate::proto::multieko2::{AdresarRequest, adresar_client::AdresarClient}; -use crate::client::colors::DoomColors; +use crate::client::colors::Theme; use crate::client::components::{form::render_form, preview_card::render_preview_card, command_line::render_command_line}; pub async fn run_client() -> Result<(), Box> { @@ -48,6 +48,7 @@ pub async fn run_client() -> Result<(), Box> { ]; let mut command_mode = false; let mut command_input = String::new(); + let theme = Theme::default(); loop { terminal.draw(|f| { @@ -72,6 +73,7 @@ pub async fn run_client() -> Result<(), Box> { &firma, &kz, &drc, &ulica, &psc, &mesto, &stat, &banka, &ucet, &skladm, &ico, &kontakt, &telefon, &skladu, &fax, ], + &theme, ); // Right panel - Preview Card @@ -81,10 +83,11 @@ pub async fn run_client() -> Result<(), Box> { &[ &firma, &ulica, &mesto, &psc, &ico, &kontakt, &telefon, ], + &theme, ); // Command line - render_command_line(f, root[1], &command_input, command_mode); + render_command_line(f, root[1], &command_input, command_mode, &theme); })?; if let Event::Key(key) = event::read()? {