Skip to content

Add Formatter Override Support for Alternative Output Formats #133

Description

@josecelano

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 OutputMessage trait 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 FormatterOverride trait with comprehensive documentation
  • Add formatter_override field to UserOutput
  • Update write() method to apply override when present
  • Add new constructors for formatter override support

Phase 2: Example Implementation (1-2 hours)

  • Implement JsonFormatter with FormatterOverride trait
  • Add helper function to extract clean type name

Phase 3: Testing (2-3 hours)

  • Add unit tests for FormatterOverride trait behavior
  • Test JsonFormatter output 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:

  • FormatterOverride trait is properly documented
  • JsonFormatter produces valid JSON with all required fields
  • All existing constructors remain unchanged and working
  • Backward compatibility maintained
  • Comprehensive unit tests added

Related

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions