working multi

This commit is contained in:
filipriec
2025-02-16 21:36:43 +01:00
parent a7d35942a1
commit c4356dcff6
5 changed files with 52 additions and 40 deletions

View File

@@ -1,20 +1,25 @@
// src/client/colors.rs // src/client/colors.rs
use ratatui::style::Color; use ratatui::style::Color;
// Pastel Gray Theme #[derive(Debug, Clone)]
pub struct PastelGrayTheme; pub struct Theme {
pub bg: Color,
impl PastelGrayTheme { pub fg: Color,
// Background colors pub accent: Color,
pub const BG: Color = Color::Rgb(245, 245, 245); // Light gray pub highlight: Color,
pub const BG_DARK: Color = Color::Rgb(220, 220, 220); // Slightly darker gray pub warning: Color,
pub border: Color,
// 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 impl Default for Theme {
fn default() -> Self {
// Accent colors Self {
pub const ACCENT: Color = Color::Rgb(173, 216, 230); // Pastel blue bg: Color::Rgb(245, 245, 245), // Light gray
pub const WARNING: Color = Color::Rgb(255, 182, 193); // Pastel pink fg: Color::Rgb(64, 64, 64), // Dark gray
pub const HIGHLIGHT: Color = Color::Rgb(152, 251, 152); // Pastel green 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
}
}
} }

View File

@@ -5,18 +5,18 @@ use ratatui::{
layout::Rect, layout::Rect,
Frame, 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 prompt = if active { ":" } else { "Press ':' for commands" };
let style = if active { let style = if active {
Style::default().fg(DoomColors::CYAN) Style::default().fg(theme.accent)
} else { } else {
Style::default().fg(DoomColors::HL) Style::default().fg(theme.fg)
}; };
let paragraph = Paragraph::new(format!("{}{}", prompt, input)) 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); .style(style);
f.render_widget(paragraph, area); f.render_widget(paragraph, area);

View File

@@ -6,7 +6,7 @@ use ratatui::{
text::Line, text::Line,
Frame, Frame,
}; };
use crate::client::colors::PastelGrayTheme; use crate::client::colors::Theme;
pub fn render_form( pub fn render_form(
f: &mut Frame, f: &mut Frame,
@@ -14,6 +14,7 @@ pub fn render_form(
fields: &[&str], fields: &[&str],
current_field: &usize, current_field: &usize,
inputs: &[&String], inputs: &[&String],
theme: &Theme,
) { ) {
let form_chunks = Layout::default() let form_chunks = Layout::default()
.direction(Direction::Vertical) .direction(Direction::Vertical)
@@ -34,22 +35,23 @@ pub fn render_form(
let input = inputs[i].clone(); let input = inputs[i].clone();
let is_active = i == *current_field; let is_active = i == *current_field;
// Add this block construction
let block = Block::default() let block = Block::default()
.borders(Borders::ALL) .borders(Borders::ALL)
.border_style(Style::default().fg(if is_active { .border_style(Style::default().fg(if is_active {
PastelGrayTheme::ACCENT theme.accent
} else { } else {
PastelGrayTheme::FG_LIGHT theme.border
})) }))
.title(Line::from(field.to_string())) .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()) let paragraph = Paragraph::new(input.as_str())
.block(block) .block(block) // Now using the defined block
.style(if is_active { .style(if is_active {
Style::default().fg(PastelGrayTheme::HIGHLIGHT) Style::default().fg(theme.highlight)
} else { } else {
Style::default().fg(PastelGrayTheme::FG) Style::default().fg(theme.fg)
}); });
f.render_widget(paragraph, form_blocks[i]); f.render_widget(paragraph, form_blocks[i]);

View File

@@ -1,31 +1,33 @@
// src/client/components/preview_card.rs // src/client/components/preview_card.rs
use ratatui::{ use ratatui::{
widgets::{Block, List, ListItem}, widgets::{Block, Borders, List, ListItem},
layout::Rect, layout::Rect,
style::Style, style::Style,
text::Text, text::Text,
Frame, 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() let card = Block::default()
.borders(ratatui::widgets::Borders::ALL) .borders(Borders::ALL)
.border_style(Style::default().fg(DoomColors::HL)) .border_style(Style::default().fg(theme.border))
.title(" Preview Card ") .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![ let items = vec![
ListItem::new(Text::from(format!("Firma: {}", fields[0]))), ListItem::new(Text::from(format!("Firma: {}", fields[0]))),
ListItem::new(Text::from(format!("Ulica: {}", fields[1]))), 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) let list = List::new(items)
.block(card) .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); f.render_widget(list, area);
} }

View File

@@ -11,7 +11,7 @@ use ratatui::{
}; };
use std::io; use std::io;
use crate::proto::multieko2::{AdresarRequest, adresar_client::AdresarClient}; 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}; use crate::client::components::{form::render_form, preview_card::render_preview_card, command_line::render_command_line};
pub async fn run_client() -> Result<(), Box<dyn std::error::Error>> { pub async fn run_client() -> Result<(), Box<dyn std::error::Error>> {
@@ -48,6 +48,7 @@ pub async fn run_client() -> Result<(), Box<dyn std::error::Error>> {
]; ];
let mut command_mode = false; let mut command_mode = false;
let mut command_input = String::new(); let mut command_input = String::new();
let theme = Theme::default();
loop { loop {
terminal.draw(|f| { terminal.draw(|f| {
@@ -72,6 +73,7 @@ pub async fn run_client() -> Result<(), Box<dyn std::error::Error>> {
&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,
], ],
&theme,
); );
// Right panel - Preview Card // Right panel - Preview Card
@@ -81,10 +83,11 @@ pub async fn run_client() -> Result<(), Box<dyn std::error::Error>> {
&[ &[
&firma, &ulica, &mesto, &psc, &ico, &kontakt, &telefon, &firma, &ulica, &mesto, &psc, &ico, &kontakt, &telefon,
], ],
&theme,
); );
// Command line // 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()? { if let Event::Key(key) = event::read()? {