refactor: split UI device renderers into modular components#44
Merged
Conversation
- 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
Contributor
There was a problem hiding this comment.
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;
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
device_renderers.rsinto focused, modular componentsChanges
File Structure Reorganization
src/ui/device_renderers.rsfile (998 lines)src/ui/renderers/gpu_renderer.rs(~250 lines) - GPU-specific renderingcpu_renderer.rs(~585 lines) - CPU rendering with visualizationmemory_renderer.rs(~157 lines) - Memory rendering with multi-segment barsstorage_renderer.rs(~140 lines) - Storage/disk renderingwidgets/- Reusable UI componentstables.rs- Common table rendering functionsgauges.rs- Gauge rendering utilitiesCode Quality Improvements
Benefits
Test Plan
cargo build --releasebuilds without warningscargo clippyreports no issuescargo fmt --checkpasses