Skip to content

Commit 8fe39e7

Browse files
committed
Merge #126: Add Theme/Configuration Support for UserOutput
2835384 feat: [#124] export Theme in presentation module public API (copilot-swe-agent[bot]) 03bdca4 fix: [#124] address clippy warnings and apply rustfmt (copilot-swe-agent[bot]) e68b452 feat: [#124] add Theme struct with emoji, plain, and ASCII variants (copilot-swe-agent[bot]) 7a27a23 Initial plan (copilot-swe-agent[bot]) Pull request description: Extracts hardcoded emoji symbols from `UserOutput` methods into a configurable `Theme` struct, enabling support for different output styles (emoji, plain text, ASCII) based on environment or user preferences. ## Changes **Theme System** - Added `Theme` struct with three predefined themes: - `emoji()` - Unicode symbols (⏳ ✅ ⚠️ ❌) for interactive terminals (default) - `plain()` - Text labels ([INFO] [OK] [WARN] [ERROR]) for CI/CD pipelines - `ascii()` - ASCII characters (=> [+] [!] [x]) for limited terminal support - Implements `Default` trait returning emoji theme for backward compatibility **UserOutput Integration** - Added `theme: Theme` field to `UserOutput` - Added `UserOutput::with_theme(verbosity, theme)` constructor - Updated all output methods (`progress()`, `success()`, `warn()`, `error()`) to use `self.theme.X_symbol()` - Removed hardcoded symbols from method implementations **Testing** - Added `TestUserOutput::with_theme()` for theme injection in tests - 11 new tests covering theme creation, accessors, and integration ## Usage ```rust use torrust_tracker_deployer_lib::presentation::user_output::{UserOutput, VerbosityLevel, Theme}; // Default emoji theme (existing behavior) let mut output = UserOutput::new(VerbosityLevel::Normal); // Plain text for CI/CD let mut output = UserOutput::with_theme(VerbosityLevel::Normal, Theme::plain()); output.success("Deployment complete"); // [OK] Deployment complete // ASCII for limited terminals let mut output = UserOutput::with_theme(VerbosityLevel::Normal, Theme::ascii()); output.success("Deployment complete"); // [+] Deployment complete ``` All existing code continues to work without modifications. > [!WARNING] > > <details> > <summary>Firewall rules blocked me from connecting to one or more addresses (expand for details)</summary> > > #### I tried to connect to the following addresses, but was blocked by firewall rules: > > - `192.0.2.1` > - Triggering command: `ssh -i /nonexistent/key -p 22 -o ConnectTimeout=5 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no testuser@192.0.2.1 echo &#39;SSH connected&#39;` (packet block) > - Triggering command: `ssh -i /nonexistent/key -p 22 -o UserKnownHostsFile=/dev/null -o ConnectTimeout=5 -o StrictHostKeyChecking=no testuser@192.0.2.1 echo &#39;SSH connected&#39;` (packet block) > - Triggering command: `ssh -i /nonexistent/key -p 22 -o ConnectTimeout=5 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null testuser@192.0.2.1 echo &#39;SSH connected&#39;` (packet block) > > If you need me to access, download, or install something from one of these locations, you can either: > > - Configure [Actions setup steps](https://gh.io/copilot/actions-setup-steps) to set up my environment, which run before the firewall is enabled > - Add the appropriate URLs or hosts to the custom allowlist in this repository's [Copilot coding agent settings](https://github.com/torrust/torrust-tracker-deployer/settings/copilot/coding_agent) (admins only) > > </details> <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Add Theme/Configuration Support for UserOutput</issue_title> > <issue_description>## Overview > > Extract emoji symbols from `UserOutput` methods into a configurable `Theme` struct. This enables support for different output styles (emoji, plain text, ASCII) based on environment or user preferences, making the application more accessible and CI/CD-friendly. > > ## Specification > > See detailed specification: [docs/issues/124-add-theme-configuration-support.md](https://github.com/torrust/torrust-tracker-deployer/blob/main/docs/issues/124-add-theme-configuration-support.md) > > ## 🏗️ Architecture Requirements > > **DDD Layer**: Presentation > **Module Path**: `src/presentation/user_output.rs` > **Pattern**: Configuration/Theme Pattern > > ### Module Structure Requirements > > - [ ] Create `Theme` struct within `user_output.rs` module > - [ ] Implement predefined theme constructors (`emoji()`, `plain()`, `ascii()`) > - [ ] Implement `Default` trait for `Theme` (emoji theme) > - [ ] Update `UserOutput` to use `Theme` for all symbol formatting > - [ ] Follow module organization conventions (see [docs/contributing/module-organization.md](https://github.com/torrust/torrust-tracker-deployer/blob/main/docs/contributing/module-organization.md)) > > ### Architectural Constraints > > - [ ] **No breaking changes**: Existing code using default constructor continues to work > - [ ] **Backward compatibility**: Default theme uses emoji (current behavior) > - [ ] **Extensibility**: Easy to add new themes without modifying output methods > - [ ] **Type safety**: Theme fields are strongly typed > - [ ] **Immutability**: Theme is set at construction, not modified during runtime > > ### Anti-Patterns to Avoid > > - ❌ **Global mutable theme** - Don't use static mutable for theme configuration > - ❌ **Runtime theme switching** - Theme is set at construction, not changed afterward > - ❌ **Hardcoded symbols in methods** - All symbols must come from `Theme` > > ## Implementation Plan > > ### Phase 1: Create Theme Struct (1-2 hours) > > - [ ] Create `Theme` struct with symbol fields > - [ ] Implement `Theme::emoji()`, `Theme::plain()`, `Theme::ascii()` > - [ ] Implement accessor methods and `Default` trait > - [ ] Add comprehensive documentation > > ### Phase 2: Add Unit Tests for Theme (1 hour) > > - [ ] Test all predefined themes > - [ ] Test accessor methods > - [ ] Test theme cloning and equality > > ### Phase 3: Integrate Theme into UserOutput (2-3 hours) > > - [ ] Add `theme: Theme` field to `UserOutput` > - [ ] Create `UserOutput::with_theme()` constructor > - [ ] Update all output methods to use `self.theme.X_symbol()` > - [ ] Remove hardcoded symbols > > ### Phase 4: Update Tests (2-3 hours) > > - [ ] Update test infrastructure to support themes > - [ ] Add tests for each theme variant > - [ ] Verify all existing tests pass > > ### Phase 5: Documentation and Verification (1 hour) > > - [ ] Add module documentation > - [ ] Add usage examples > - [ ] Run pre-commit checks: `./scripts/pre-commit.sh` > > ## Acceptance Criteria > > > **Note for Contributors**: These criteria define what the PR reviewer will check. Use this as your pre-review checklist before submitting the PR to minimize back-and-forth iterations. > > **Quality Checks**: > > - [ ] Pre-commit checks pass: `./scripts/pre-commit.sh` > > **Theme Implementation Checks**: > > - [ ] `Theme` struct exists with all symbol fields > - [ ] All predefined themes implemented: `emoji()`, `plain()`, `ascii()` > - [ ] `Default` trait returns emoji theme > - [ ] All accessor methods implemented > > **Integration Checks**: > > - [ ] `UserOutput` has `theme: Theme` field > - [ ] `UserOutput::with_theme()` constructor exists > - [ ] All output methods use theme symbols (no hardcoded symbols) > > **Testing Checks**: > > - [ ] Theme unit tests cover all variants > - [ ] Test infrastructure supports theme injection > - [ ] All existing tests pass > > **Backward Compatibility Checks**: > > - [ ] Default `UserOutput::new()` uses emoji theme > - [ ] No breaking changes to public API > > **Documentation Checks**: > > - [ ] Theme system fully documented > - [ ] Usage examples for each theme > - [ ] Each theme variant documented with use case > > ## Related > > - Parent: #102 (Epic: User Output Architecture Improvements) > - Roadmap: N/A (Code quality improvement) > - Specification: [docs/issues/124-add-theme-configuration-support.md](https://github.com/torrust/torrust-tracker-deployer/blob/main/docs/issues/124-add-theme-configuration-support.md)</issue_description> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> - Fixes #124 <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). ACKs for top commit: josecelano: ACK 2835384 Tree-SHA512: 46e0fddbf33edc5622ccc01a226d1a44d57fd1b45f9797304a1082f41741bc00dc6ffbd890d96c85ac918de9ac3c4684d89176bd9d49ee81b0088d4e140c286a
2 parents 3d895ff + 2835384 commit 8fe39e7

File tree

2 files changed

+401
-17
lines changed

2 files changed

+401
-17
lines changed

src/presentation/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ pub use commands::destroy::DestroySubcommandError;
5151
pub use commands::{execute, handle_error};
5252
pub use errors::CommandError;
5353
pub use progress::ProgressReporter;
54-
pub use user_output::{UserOutput, VerbosityLevel};
54+
pub use user_output::{Theme, UserOutput, VerbosityLevel};

0 commit comments

Comments
 (0)