Skip to content

refactor: split UI device renderers into modular components#44

Merged
inureyes merged 3 commits into
mainfrom
refactor/split-ui-device-renders
Aug 11, 2025
Merged

refactor: split UI device renderers into modular components#44
inureyes merged 3 commits into
mainfrom
refactor/split-ui-device-renders

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

  • Split monolithic 998-line device_renderers.rs into focused, modular components
  • Created separate renderer modules for GPU, CPU, Memory, and Storage (200-585 lines each)
  • Extracted reusable widget functions into dedicated modules

Changes

File Structure Reorganization

  • Before: Single src/ui/device_renderers.rs file (998 lines)
  • After: Modular structure under src/ui/renderers/
    • gpu_renderer.rs (~250 lines) - GPU-specific rendering
    • cpu_renderer.rs (~585 lines) - CPU rendering with visualization
    • memory_renderer.rs (~157 lines) - Memory rendering with multi-segment bars
    • storage_renderer.rs (~140 lines) - Storage/disk rendering
    • widgets/ - Reusable UI components
      • tables.rs - Common table rendering functions
      • gauges.rs - Gauge rendering utilities

Code Quality Improvements

  • Followed Single Responsibility Principle (SRP)
  • Eliminated code duplication through shared widget modules
  • Added proper module structure with clear public interfaces
  • Resolved all compiler warnings and clippy lints
  • Maintained backward compatibility through re-exports

Benefits

  • Reduced cognitive load: Each file focuses on a single device type
  • Better maintainability: Changes to one renderer don't affect others
  • Improved testability: Smaller, focused modules are easier to test
  • Future extensibility: Easy to add new device types or modify existing ones

Test Plan

  • All existing tests pass (79 tests)
  • cargo build --release builds without warnings
  • cargo clippy reports no issues
  • cargo fmt --check passes
  • Mock server builds and runs correctly
  • TUI view mode works for all tabs (GPU, CPU, Memory, Storage)

@inureyes inureyes added the type:refactor Code refactoring label Aug 11, 2025
@inureyes inureyes self-assigned this Aug 11, 2025
- Added tests for format_hostname_with_scroll function in gpu_renderer
- Added tests for get_utilization_block and render_gauge in gauges widget
- Added tests for TableRow creation and rendering functions in tables widget
- Created test_utils module with MockWriter for testing I/O operations
@inureyes inureyes requested a review from Copilot August 11, 2025 15:01

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

This PR refactors the monolithic 998-line device_renderers.rs file into modular, focused components following the Single Responsibility Principle. The refactoring splits rendering logic into separate modules for each device type (GPU, CPU, Memory, Storage) and extracts reusable UI components into dedicated widget modules.

Key changes:

  • Split single file into 4 device-specific renderers (~140-585 lines each)
  • Created reusable widget modules for tables and gauges
  • Added test utilities and helper macros for better test organization
  • Updated documentation with comprehensive testing guidelines

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tasks/REFACTOR_TODO.md Marks device renderer refactoring tasks as completed
src/utils/test_helpers.rs Adds test helper macros for sudo and CI environment handling
src/utils/system.rs Adds #[ignore] annotations to sudo-requiring tests
src/ui/renderers/ New modular renderer structure with device-specific files
src/ui/renderers/widgets/ Extracted reusable UI components for tables and gauges
src/ui/renderer.rs Updates imports to use new modular structure
TESTING.md Comprehensive testing documentation
README.md Updates with testing section and quick commands
Comments suppressed due to low confidence (1)

src/ui/renderers/cpu_renderer.rs:15

  • The removed imports (GpuInfo, MemoryInfo, StorageInfo) suggest that this file previously contained multiple device renderers. Consider verifying that all GPU, memory, and storage rendering functions have been properly moved to their respective new files.
use std::io::Write;

Comment thread src/utils/test_helpers.rs
Comment thread src/ui/renderers/widgets/mod.rs
Comment thread src/ui/renderers/widgets/tables.rs
Comment thread src/ui/renderers/mod.rs
@inureyes inureyes merged commit dbbf0e7 into main Aug 11, 2025
3 checks passed
@inureyes inureyes added priority:medium Medium priority issue status:done Completed feature labels Sep 10, 2025
@inureyes inureyes added type:enhancement New feature or request and removed feature labels Oct 28, 2025
@inureyes inureyes deleted the refactor/split-ui-device-renders branch December 23, 2025 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:medium Medium priority issue status:done Completed type:enhancement New feature or request type:refactor Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants