refactor: apply DRY principle with enhanced logging system and UI improvements - #13
Conversation
- Remove unused methods and fix duplicate closing delimiter in async_task_manager - Add log level filtering to suppress TRACE logs in release builds while keeping them in debug builds
Keep .dev directory locally for development planning but exclude from repository
- Display logs in reverse order (newest at bottom) - Apply black background with green text for terminal-like appearance
- Reverse log order (newest at bottom) in Log tab - Add black background with green text for terminal-like appearance in Log tab - Revert bottom output panel to original styling
There was a problem hiding this comment.
Pull Request Overview
Refactors async/task orchestration and Homebrew command handling to reduce duplication, and introduces a level-aware logging system with UI controls and a terminal-style log view.
- Centralizes brew command logic and parsing; switches installed listing to plain-text parsing
- Adds LogManager with level filtering and new UI controls; integrates tracing and log capture
- Improves AsyncTaskManager to support multiple concurrent tasks and de-duplicate by task kind
Reviewed Changes
Copilot reviewed 18 out of 20 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/presentation/ui/app.rs | Integrates new LogManager APIs, adds log-level UI toggles, improves tracing, and tweaks log rendering/copying. |
| src/presentation/services/log_capture.rs | Adds LevelFilter and broadens target filtering for captured logs. |
| src/presentation/services/async_task_manager.rs | Switches from single active task to a vector; de-duplicates by task type and updates poll logic. |
| src/presentation/components/package_list.rs | Minor UI/layout refinements and guards. |
| src/presentation/components/mod.rs | Reorders exports and exposes LogLevel. |
| src/presentation/components/log_manager.rs | Introduces LogLevel, level parsing, visible-level filtering, and reversed iteration helpers. |
| src/presentation/components/cleanup_modal.rs | UI formatting improvements only. |
| src/main.rs | Minor init/reordering cleanup. |
| src/infrastructure/brew/repository.rs | Refactors parsing: plain-text for installed, JSON for outdated; logging/tracing added; command calls unified. |
| src/infrastructure/brew/command.rs | Consolidates brew commands (list/search/install/uninstall/info/etc.) behind generic helpers. |
| src/domain/repositories/package_repository.rs | Formatting change only. |
| src/domain/entities/package.rs | Simplifies constructor signature formatting. |
| src/domain/entities/mod.rs | Export order normalization. |
| src/application/use_cases/package_operations.rs | DRY refactor via RepositoryUseCase wrapper across use cases. |
| src/application/mod.rs | Module export reordering. |
| Cargo.toml | Bumps version and adjusts profiles. |
| .dev/PROJECT_OVERVIEW.md | Removed developer documentation file. |
| .dev/IMPROVEMENT_PLAN.md | Removed developer documentation file. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Replace brittle string-based task type detection with a TaskKind enum and helper method on AsyncTask. This improves type safety, eliminates typo risks, and makes the code more maintainable.
Remove .or_else(|| Some(trimmed)) fallback that was treating every non-empty line as a file path, causing unnecessary filesystem checks and inflated preview results. Now only lines with 'Would remove: ' prefix are processed.
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 18 out of 20 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Count lines during single parse pass instead of separate count pass, reducing unnecessary iteration on large outputs and combining log messages for clarity.
Let user control scroll position freely in Log tab instead of auto-pinning to bottom. With filtered_logs_reversed(), newest entries appear at top naturally.
Add explicit return type -> anyhow::Result<()> to closure so compiler can infer error type for ? operator and Ok(()) returns.
7fa1a3b to
8e8ec09
Compare
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 18 out of 20 changed files in this pull request and generated 4 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| let msg = format!("Error loading outdated formulae: {}", e); | ||
| logs.push(msg.clone()); | ||
| tracing::error!("{}", msg); | ||
| if let Err(e) = (|| -> Result<()> { |
There was a problem hiding this comment.
This closure uses Result<()> without an in-scope type alias, causing a compile error. Either import anyhow::Result or fully qualify the return type as anyhow::Result<()> to match the usage of anyhow::anyhow(...) inside the block.
| } | ||
|
|
||
| if let Some(path_str) = trimmed.strip_prefix("Would remove: ").or_else(|| Some(trimmed)) { | ||
| if let Some(path_str) = trimmed.strip_prefix("Would remove: ") { |
There was a problem hiding this comment.
The fallback that treated non-prefixed lines as paths was removed, which can drop valid entries from 'brew cleanup' dry-run output. Restore the fallback to handle both prefixed and plain path lines so items aren't missed.
| if let Some(path_str) = trimmed.strip_prefix("Would remove: ") { | |
| // Handle lines with "Would remove: " prefix | |
| let path_str_opt = if let Some(path_str) = trimmed.strip_prefix("Would remove: ") { | |
| Some(path_str) | |
| } else if !trimmed.is_empty() | |
| // Exclude lines that are not likely to be paths (already handled above) | |
| && !trimmed.starts_with("Would remove:") | |
| && !trimmed.starts_with("Removing:") | |
| && !trimmed.starts_with("==>") | |
| { | |
| // Fallback: treat as plain path | |
| Some(trimmed) | |
| } else { | |
| None | |
| }; | |
| if let Some(path_str) = path_str_opt { |
8e8ec09 to
4fa9543
Compare
Add explicit return type -> Result<()> to closure so compiler can infer error type for ? operator.
4fa9543 to
9648ee7
Compare
Handle both 'Would remove: ' prefixed lines and plain paths to avoid missing entries from brew cleanup dry-run output. Exclude headers and markers explicitly to stay safe.
Summary
This PR implements comprehensive DRY principle refactoring alongside a completely redesigned logging system:
🔄 DRY Principle Refactoring
LogManagerwith level-based filtering📋 Enhanced Logging System
🎨 Terminal-Style Log Tab
🛠️ Technical Improvements
📊 Impact
✅ Testing
All changes follow existing code patterns and conventions. Log filtering works across both the output panel and Log tab independently.