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
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
}
}
}

View File

@@ -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);

View File

@@ -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]);

View File

@@ -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));
let _inner_area = card.inner(area); // Prefix with underscore to indicate intentional unused
.style(Style::default().bg(theme.bg).fg(theme.fg));
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);
}

View File

@@ -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<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_input = String::new();
let theme = Theme::default();
loop {
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,
&ucet, &skladm, &ico, &kontakt, &telefon, &skladu, &fax,
],
&theme,
);
// 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,
],
&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()? {