Skip to content

refactor: apply DRY principle with enhanced logging system and UI improvements - #13

Merged
whooof merged 13 commits into
mainfrom
refactor/dry-principle-logging
Oct 20, 2025
Merged

refactor: apply DRY principle with enhanced logging system and UI improvements#13
whooof merged 13 commits into
mainfrom
refactor/dry-principle-logging

Conversation

@whooof

@whooof whooof commented Oct 19, 2025

Copy link
Copy Markdown
Owner

Summary

This PR implements comprehensive DRY principle refactoring alongside a completely redesigned logging system:

🔄 DRY Principle Refactoring

  • Eliminated code duplication across repository, infrastructure, and presentation layers
  • Consolidated logging logic into unified LogManager with level-based filtering
  • Simplified async task handling with shared patterns
  • Reduced codebase by 314 lines while improving maintainability

📋 Enhanced Logging System

  • Log Level Filtering: Added runtime filtering for Trace, Debug, Info, Warn, and Error levels
  • Settings Controls: New log level toggles in Settings tab for granular control
  • Release Build Optimization: Excluded TRACE logs from release builds for performance
  • Smart Defaults: Info, Warn, and Error visible by default; Debug and Trace hidden

🎨 Terminal-Style Log Tab

  • Black background with green text for authentic terminal appearance
  • Reversed log order (newest at bottom) for terminal-like behavior
  • Auto-scrolling to bottom for seamless log viewing
  • Separate filtering from output panel for independent control

🛠️ Technical Improvements

  • Fixed compilation errors in async task manager
  • Reorganized dev files (.dev/ added to .gitignore)
  • Improved log entry parsing with level extraction
  • Enhanced LogEntry structure with timestamp and level fields

📊 Impact

  • Files Changed: 20
  • Lines Added: 999
  • Lines Removed: 1313
  • Net Change: -314 lines (improved efficiency)

✅ Testing

All changes follow existing code patterns and conventions. Log filtering works across both the output panel and Log tab independently.

- 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
Copilot AI review requested due to automatic review settings October 19, 2025 22:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/presentation/components/log_manager.rs Outdated
Comment thread src/presentation/ui/app.rs Outdated
Comment thread src/infrastructure/brew/repository.rs Outdated
Comment thread src/presentation/services/async_task_manager.rs Outdated
Comment thread src/presentation/ui/app.rs
Comment thread src/presentation/ui/app.rs
whooof and others added 4 commits October 20, 2025 01:44
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.
@whooof
whooof requested a review from Copilot October 20, 2025 00:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/presentation/ui/app.rs Outdated
Comment thread src/presentation/ui/app.rs
Comment thread src/infrastructure/brew/repository.rs Outdated
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.
@whooof
whooof force-pushed the refactor/dry-principle-logging branch from 7fa1a3b to 8e8ec09 Compare October 20, 2025 00:15
@whooof
whooof requested a review from Copilot October 20, 2025 00:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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<()> {

Copilot AI Oct 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread src/infrastructure/brew/repository.rs Outdated
}

if let Some(path_str) = trimmed.strip_prefix("Would remove: ").or_else(|| Some(trimmed)) {
if let Some(path_str) = trimmed.strip_prefix("Would remove: ") {

Copilot AI Oct 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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 {

Copilot uses AI. Check for mistakes.
Comment thread src/presentation/ui/app.rs
Comment thread src/presentation/ui/app.rs
@whooof
whooof force-pushed the refactor/dry-principle-logging branch from 8e8ec09 to 4fa9543 Compare October 20, 2025 00:19
Add explicit return type -> Result<()> to closure so compiler can
infer error type for ? operator.
@whooof
whooof force-pushed the refactor/dry-principle-logging branch from 4fa9543 to 9648ee7 Compare October 20, 2025 00:19
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.
@whooof
whooof merged commit 126296f into main Oct 20, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants