Repository navigation
Description
Overview
Add optional FormatterOverride trait support to enable alternative output formats (JSON, structured logs, colored output) without modifying individual message types. This enhancement preserves the trait-based message design (Proposal 3) while allowing format transformation for machine-readable outputs.
Note: This is an optional enhancement that builds on the existing trait-based design. The current implementation using Theme and OutputMessage trait already provides good separation and flexibility. This proposal is only needed if we require format overrides beyond what themes provide (e.g., JSON output, ANSI color codes, structured logging).
Specification
See detailed specification: docs/issues/133-add-formatter-override-support.md
🏗️ Architecture Requirements
DDD Layer: Presentation
Module Path: src/presentation/user_output.rs
Pattern: Trait-based Extension (Strategy Pattern)
Key Requirements
- Must not break existing
OutputMessagetrait design - Must preserve theme-based formatting as primary mechanism
- Override should be optional (
Option<Box<dyn FormatterOverride>>) - Maintain backward compatibility with existing code
Implementation Plan
Phase 1: Core Trait and Integration (2-3 hours)
- Define
FormatterOverridetrait with comprehensive documentation - Add
formatter_overridefield toUserOutput - Update
write()method to apply override when present - Add new constructors for formatter override support
Phase 2: Example Implementation (1-2 hours)
- Implement
JsonFormatterwithFormatterOverridetrait - Add helper function to extract clean type name
Phase 3: Testing (2-3 hours)
- Add unit tests for
FormatterOverridetrait behavior - Test
JsonFormatteroutput structure - Verify backward compatibility
Phase 4: Documentation (1 hour)
- Document when to use formatter override vs. themes
- Add examples to module documentation
Acceptance Criteria
Quality Checks:
- Pre-commit checks pass:
./scripts/pre-commit.sh
Task-Specific Criteria:
-
FormatterOverridetrait is properly documented -
JsonFormatterproduces valid JSON with all required fields - All existing constructors remain unchanged and working
- Backward compatibility maintained
- Comprehensive unit tests added
Related
- Parent: [EPIC] User Output Architecture Improvements #102 (Epic: User Output Architecture Improvements)
- Specification: docs/issues/133-add-formatter-override-support.md
- Refactoring Plan: Proposal 4
Activity
docs: [#133] add issue specification for Proposal 4 - formatter overr…
feat: [#133] Add FormatterOverride trait and JsonFormatter implementa…
fix: [#133] Fix clippy warnings in formatter override tests
Merge #134: Add FormatterOverride trait for alternative output format…
chore: remove closed issue documentation files