compiled examples

This commit is contained in:
Priec
2025-08-11 22:50:28 +02:00
parent 280f314100
commit 082093ea17
4 changed files with 79 additions and 83 deletions

View File

@@ -34,7 +34,6 @@ use ratatui::{
widgets::{Block, Borders, Paragraph, Wrap}, widgets::{Block, Borders, Paragraph, Wrap},
Frame, Terminal, Frame, Terminal,
}; };
use canvas::{ use canvas::{
canvas::{ canvas::{
gui::render_canvas_default, gui::render_canvas_default,
@@ -62,10 +61,8 @@ struct ValidationFormEditor<D: DataProvider> {
impl<D: DataProvider> ValidationFormEditor<D> { impl<D: DataProvider> ValidationFormEditor<D> {
fn new(data_provider: D) -> Self { fn new(data_provider: D) -> Self {
let mut editor = FormEditor::new(data_provider); let mut editor = FormEditor::new(data_provider);
// Enable validation by default // Enable validation by default
editor.set_validation_enabled(true); editor.set_validation_enabled(true);
Self { Self {
editor, editor,
has_unsaved_changes: false, has_unsaved_changes: false,
@@ -98,7 +95,6 @@ impl<D: DataProvider> ValidationFormEditor<D> {
fn toggle_validation(&mut self) { fn toggle_validation(&mut self) {
self.validation_enabled = !self.validation_enabled; self.validation_enabled = !self.validation_enabled;
self.editor.set_validation_enabled(self.validation_enabled); self.editor.set_validation_enabled(self.validation_enabled);
if self.validation_enabled { if self.validation_enabled {
self.debug_message = "✅ Validation ENABLED - Try exceeding limits!".to_string(); self.debug_message = "✅ Validation ENABLED - Try exceeding limits!".to_string();
} else { } else {
@@ -110,14 +106,12 @@ impl<D: DataProvider> ValidationFormEditor<D> {
if !self.validation_enabled { if !self.validation_enabled {
return (true, None); return (true, None);
} }
let can_switch = self.editor.can_switch_fields(); let can_switch = self.editor.can_switch_fields();
let reason = if !can_switch { let reason = if !can_switch {
self.editor.field_switch_block_reason() self.editor.field_switch_block_reason()
} else { } else {
None None
}; };
(can_switch, reason) (can_switch, reason)
} }
@@ -125,11 +119,9 @@ impl<D: DataProvider> ValidationFormEditor<D> {
if !self.validation_enabled { if !self.validation_enabled {
return "❌ DISABLED".to_string(); return "❌ DISABLED".to_string();
} }
if self.field_switch_blocked { if self.field_switch_blocked {
return "🚫 SWITCH BLOCKED".to_string(); return "🚫 SWITCH BLOCKED".to_string();
} }
let summary = self.editor.validation_summary(); let summary = self.editor.validation_summary();
if summary.has_errors() { if summary.has_errors() {
format!("{} ERRORS", summary.error_fields) format!("{} ERRORS", summary.error_fields)
@@ -162,7 +154,6 @@ impl<D: DataProvider> ValidationFormEditor<D> {
for i in 0..field_count { for i in 0..field_count {
self.editor.validate_field(i); self.editor.validate_field(i);
} }
let summary = self.editor.validation_summary(); let summary = self.editor.validation_summary();
self.debug_message = format!( self.debug_message = format!(
"🔍 Validated all fields: {} valid, {} warnings, {} errors", "🔍 Validated all fields: {} valid, {} warnings, {} errors",
@@ -250,7 +241,6 @@ impl<D: DataProvider> ValidationFormEditor<D> {
if !self.validation_enabled { if !self.validation_enabled {
return; return;
} }
if let Some(result) = self.editor.current_field_validation() { if let Some(result) = self.editor.current_field_validation() {
match result { match result {
ValidationResult::Valid => { ValidationResult::Valid => {
@@ -298,7 +288,10 @@ impl<D: DataProvider> ValidationFormEditor<D> {
ValidationResult::Valid => { ValidationResult::Valid => {
// Don't spam with valid messages, just show character count if applicable // Don't spam with valid messages, just show character count if applicable
if let Some(limits) = self.get_current_field_limits() { if let Some(limits) = self.get_current_field_limits() {
if let Some(status) = limits.status_text(self.editor.current_text()) { let field_index = self.editor.current_field();
if let Some(status) = limits.status_text(
self.editor.data_provider().field_value(field_index)
) {
self.debug_message = format!("✏️ {}", status); self.debug_message = format!("✏️ {}", status);
} }
} }
@@ -537,7 +530,6 @@ fn handle_key_press(
editor.enter_edit_mode(); editor.enter_edit_mode();
editor.clear_command_buffer(); editor.clear_command_buffer();
} }
// Escape: Exit edit mode // Escape: Exit edit mode
(_, KeyCode::Esc, _) => { (_, KeyCode::Esc, _) => {
if mode == AppMode::Edit { if mode == AppMode::Edit {
@@ -630,7 +622,6 @@ fn handle_key_press(
summary.validated_fields summary.validated_fields
)); ));
} }
_ => { _ => {
if editor.has_pending_command() { if editor.has_pending_command() {
editor.clear_command_buffer(); editor.clear_command_buffer();
@@ -662,7 +653,6 @@ fn run_app<B: Backend>(
} }
} }
} }
Ok(()) Ok(())
} }
@@ -706,6 +696,7 @@ fn render_validation_status(
}; };
let validation_status = editor.get_validation_status(); let validation_status = editor.get_validation_status();
let status_text = if editor.has_pending_command() { let status_text = if editor.has_pending_command() {
format!("-- {} -- {} [{}] | Validation: {}", format!("-- {} -- {} [{}] | Validation: {}",
mode_text, editor.debug_message(), editor.get_command_buffer(), validation_status) mode_text, editor.debug_message(), editor.get_command_buffer(), validation_status)
@@ -719,7 +710,6 @@ fn render_validation_status(
let status = Paragraph::new(Line::from(Span::raw(status_text))) let status = Paragraph::new(Line::from(Span::raw(status_text)))
.block(Block::default().borders(Borders::ALL).title("🔍 Validation Status")); .block(Block::default().borders(Borders::ALL).title("🔍 Validation Status"));
f.render_widget(status, chunks[0]); f.render_widget(status, chunks[0]);
// Validation summary with field switching info // Validation summary with field switching info
@@ -765,7 +755,6 @@ fn render_validation_status(
.block(Block::default().borders(Borders::ALL).title("📈 Validation Overview")) .block(Block::default().borders(Borders::ALL).title("📈 Validation Overview"))
.style(summary_style) .style(summary_style)
.wrap(Wrap { trim: true }); .wrap(Wrap { trim: true });
f.render_widget(validation_summary, chunks[1]); f.render_widget(validation_summary, chunks[1]);
// Enhanced help text // Enhanced help text
@@ -792,7 +781,6 @@ fn render_validation_status(
.block(Block::default().borders(Borders::ALL).title("🚀 Validation Commands")) .block(Block::default().borders(Borders::ALL).title("🚀 Validation Commands"))
.style(Style::default().fg(Color::Gray)) .style(Style::default().fg(Color::Gray))
.wrap(Wrap { trim: true }); .wrap(Wrap { trim: true });
f.render_widget(help, chunks[2]); f.render_widget(help, chunks[2]);
} }

View File

@@ -156,7 +156,10 @@ impl<D: DataProvider> AdvancedPatternFormEditor<D> {
fn current_field(&self) -> usize { self.editor.current_field() } fn current_field(&self) -> usize { self.editor.current_field() }
fn cursor_position(&self) -> usize { self.editor.cursor_position() } fn cursor_position(&self) -> usize { self.editor.cursor_position() }
fn mode(&self) -> AppMode { self.editor.mode() } fn mode(&self) -> AppMode { self.editor.mode() }
fn current_text(&self) -> &str { self.editor.current_text() } fn current_text(&self) -> &str {
let field_index = self.editor.current_field();
self.editor.data_provider().field_value(field_index)
}
fn data_provider(&self) -> &D { self.editor.data_provider() } fn data_provider(&self) -> &D { self.editor.data_provider() }
fn ui_state(&self) -> &canvas::EditorState { self.editor.ui_state() } fn ui_state(&self) -> &canvas::EditorState { self.editor.ui_state() }
fn set_mode(&mut self, mode: AppMode) { self.editor.set_mode(mode); } fn set_mode(&mut self, mode: AppMode) { self.editor.set_mode(mode); }

View File

@@ -108,7 +108,7 @@ impl<D: DataProvider> MaskDemoFormEditor<D> {
fn get_current_field_info(&self) -> (String, String, String) { fn get_current_field_info(&self) -> (String, String, String) {
let field_index = self.editor.current_field(); let field_index = self.editor.current_field();
let raw_data = self.editor.current_text(); let raw_data = self.editor.data_provider().field_value(field_index);
let display_data = if self.validation_enabled { let display_data = if self.validation_enabled {
self.editor.current_display_text() self.editor.current_display_text()
} else { } else {
@@ -237,7 +237,10 @@ impl<D: DataProvider> MaskDemoFormEditor<D> {
fn current_field(&self) -> usize { self.editor.current_field() } fn current_field(&self) -> usize { self.editor.current_field() }
fn cursor_position(&self) -> usize { self.editor.cursor_position() } fn cursor_position(&self) -> usize { self.editor.cursor_position() }
fn mode(&self) -> AppMode { self.editor.mode() } fn mode(&self) -> AppMode { self.editor.mode() }
fn current_text(&self) -> &str { self.editor.current_text() } fn current_text(&self) -> &str {
let field_index = self.editor.current_field();
self.editor.data_provider().field_value(field_index)
}
fn data_provider(&self) -> &D { self.editor.data_provider() } fn data_provider(&self) -> &D { self.editor.data_provider() }
fn ui_state(&self) -> &canvas::EditorState { self.editor.ui_state() } fn ui_state(&self) -> &canvas::EditorState { self.editor.ui_state() }
fn set_mode(&mut self, mode: AppMode) { fn set_mode(&mut self, mode: AppMode) {
@@ -648,7 +651,7 @@ fn render_mask_status(
• Dynamic vs Template modes • Custom separators • Different input chars\n\ • Dynamic vs Template modes • Custom separators • Different input chars\n\
\n\ \n\
Commands: i/a=insert, m=mask details, r=toggle raw/display view\n\ Commands: i/a=insert, m=mask details, r=toggle raw/display view\n\
Movement: hjkl/arrows=move, 0=$=line start/end, Tab=next field, F1=toggle masks\n\ Movement: hjkl/arrows=move, 0/$=line start/end, Tab=next field, F1=toggle masks\n\
?=detailed info, Ctrl+C=quit" ?=detailed info, Ctrl+C=quit"
} }
AppMode::Edit => { AppMode::Edit => {

View File

@@ -364,7 +364,8 @@ impl<D: DataProvider> EnhancedDemoEditor<D> {
} }
fn get_current_field_analysis(&self) -> (String, String, String, Option<String>) { fn get_current_field_analysis(&self) -> (String, String, String, Option<String>) {
let raw = self.editor.current_text(); let field_index = self.editor.current_field();
let raw = self.editor.data_provider().field_value(field_index);
let display = self.editor.current_display_text(); let display = self.editor.current_display_text();
let status = if raw == display { let status = if raw == display {
@@ -445,7 +446,8 @@ impl<D: DataProvider> EnhancedDemoEditor<D> {
let raw_pos = self.editor.cursor_position(); let raw_pos = self.editor.cursor_position();
let display_pos = self.editor.display_cursor_position(); let display_pos = self.editor.display_cursor_position();
let raw = self.editor.current_text(); let field_index = self.editor.current_field();
let raw = self.editor.data_provider().field_value(field_index);
let display = self.editor.current_display_text(); let display = self.editor.current_display_text();
if raw_pos != display_pos { if raw_pos != display_pos {