Skip to content

Commit 99824f1

Browse files
committed
adding feos-tui
1 parent ace1403 commit 99824f1

File tree

18 files changed

+3621
-0
lines changed

18 files changed

+3621
-0
lines changed

src/bin/feos-tui/.cursorrules

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
# FeOS TUI Development Rules
2+
3+
## Project Overview
4+
This is the Terminal User Interface (TUI) for FeOS, built with Rust and ratatui. The TUI provides a comprehensive interface for managing FeOS instances, including VMs, logs, and system monitoring.
5+
6+
## Architecture Guidelines
7+
8+
### Module Structure
9+
- **`main.rs`**: Entry point, argument parsing, and main application loop only
10+
- **`app.rs`**: Application state management and business logic
11+
- **`events.rs`**: Keyboard input handling and navigation logic
12+
- **`terminal.rs`**: Terminal setup/teardown and low-level terminal operations
13+
- **`mock_data.rs`**: Mock data generation and dynamic simulation
14+
- **`ui/`**: All UI rendering logic, organized by concern:
15+
- **`mod.rs`**: Main UI coordination and layout
16+
- **`components.rs`**: Reusable UI components (header, footer, tabs)
17+
- **`dashboard.rs`**: Dashboard view rendering
18+
- **`views.rs`**: Other view implementations (VMs, Logs, etc.)
19+
20+
### Design Principles
21+
1. **Separation of Concerns**: Keep UI rendering, business logic, and data separate
22+
2. **Single Responsibility**: Each module should have one clear purpose
23+
3. **Modular Views**: New views should be easy to add without modifying existing code
24+
4. **Component Reuse**: UI components should be reusable across different views
25+
5. **Error Handling**: Use `color-eyre` for comprehensive error handling
26+
27+
## Coding Standards
28+
29+
### Rust Style
30+
- Follow standard Rust naming conventions (snake_case for functions/variables, PascalCase for types)
31+
- Use `#[derive(Debug, Clone, Copy, PartialEq)]` for enums when appropriate
32+
- Prefer explicit type annotations for public APIs
33+
- Use `pub` visibility only when necessary for module boundaries
34+
35+
### UI Development
36+
- Always use `ratatui` widgets and avoid custom drawing when possible
37+
- Use consistent color schemes:
38+
- **Cyan**: Headers and titles
39+
- **Yellow**: Highlighted/selected items
40+
- **Green**: Success states, RAM usage
41+
- **Blue**: CPU usage, sparklines
42+
- **Red**: Error states, stopped VMs
43+
- **Gray**: Placeholder text, help text
44+
- Maintain consistent spacing and layout constraints
45+
- Use `Block::default().borders(Borders::ALL).title("Title")` for consistent styling
46+
47+
### State Management
48+
- Keep all mutable state in the `App` struct
49+
- Use private fields with public accessors when needed
50+
- Implement `Default` for structs that need initialization
51+
- Use `Instant` for time-based operations, not system time
52+
53+
### Event Handling
54+
- Handle all keyboard events in the `events.rs` module
55+
- Use clear, intuitive key bindings:
56+
- `q`: Quit application
57+
- `d`, `v`, `l`: Direct navigation to Dashboard, VMs, Logs
58+
- `←`, `→`: Tab navigation
59+
- `↑`, `↓`: List navigation (when implemented)
60+
- `Enter`: Primary action
61+
- `Esc`: Cancel/back
62+
63+
## Mock Data Guidelines
64+
65+
### Dynamic Behavior
66+
- Simulate realistic data changes over time
67+
- Use atomic counters for thread-safe state updates
68+
- Implement different update frequencies for different data types:
69+
- **Polling data** (host info, VM status): Every 2 seconds
70+
- **Streaming data** (logs): Every 3 seconds
71+
- Keep log history bounded (max 50 entries) to prevent memory growth
72+
73+
### Data Realism
74+
- VM status transitions should follow realistic patterns
75+
- Resource usage should vary within reasonable bounds
76+
- Log messages should be realistic and varied
77+
- Network interfaces should have valid MAC/PCI addresses
78+
79+
## Testing Requirements
80+
81+
### Unit Tests
82+
- Test all utility functions (formatting, calculations)
83+
- Test mock data generation and validation
84+
- Test state transitions and business logic
85+
- Maintain test coverage for all public APIs
86+
87+
### Integration Testing
88+
- Use `--test` mode for non-interactive testing
89+
- Test dynamic data updates and timing
90+
- Verify UI components render without panics
91+
- Test keyboard navigation and state changes
92+
93+
### CLI Test Views (Automated Testing)
94+
The TUI includes comprehensive CLI testing capabilities to avoid blocking interactive sessions:
95+
96+
#### General Mock Data Testing
97+
```bash
98+
# Run comprehensive mock data tests
99+
cargo run --bin feos-tui -- --test
100+
101+
# Run with verbose output for debugging
102+
cargo run --bin feos-tui -- --test --verbose
103+
```
104+
105+
#### View-Specific Testing
106+
```bash
107+
# Test individual views (default 2 seconds)
108+
cargo run --bin feos-tui -- --test-view dashboard
109+
cargo run --bin feos-tui -- --test-view vms
110+
cargo run --bin feos-tui -- --test-view logs
111+
cargo run --bin feos-tui -- --test-view system
112+
113+
# Test with custom duration and verbose output
114+
cargo run --bin feos-tui -- --test-view dashboard --duration 5 --verbose
115+
cargo run --bin feos-tui -- --test-view vms --duration 1
116+
```
117+
118+
#### Testing Workflow
119+
1. **During Development**: Use view-specific tests to quickly verify changes
120+
```bash
121+
# Quick 1-second test after making dashboard changes
122+
cargo run --bin feos-tui -- --test-view dashboard --duration 1
123+
```
124+
125+
2. **Before Commits**: Run comprehensive test to verify all functionality
126+
```bash
127+
cargo run --bin feos-tui -- --test --verbose
128+
```
129+
130+
3. **Debugging UI Issues**: Use longer durations to observe behavior
131+
```bash
132+
# 10-second test to observe dynamic updates
133+
cargo run --bin feos-tui -- --test-view dashboard --duration 10 --verbose
134+
```
135+
136+
4. **CI/CD Integration**: All test modes exit cleanly for automation
137+
```bash
138+
# Perfect for automated testing pipelines
139+
cargo run --bin feos-tui -- --test-view dashboard --duration 2
140+
```
141+
142+
#### Available CLI Options
143+
- `--test`: Run comprehensive mock data tests and exit
144+
- `--test-view <VIEW>`: Test specific view (dashboard, vms, logs, system)
145+
- `--duration <SECONDS>`: Duration to show test view (default: 2)
146+
- `--verbose`: Enable detailed output for debugging
147+
- `--help`: Show all available options
148+
149+
#### Testing Best Practices
150+
- **Always test views after UI changes** using `--test-view <view> --duration 1`
151+
- **Use verbose mode** when debugging: `--verbose` provides detailed progress
152+
- **Test dynamic behavior** with longer durations (5-10 seconds) to see data changes
153+
- **Verify all views** before major commits using the general `--test` mode
154+
- **Keep tests fast** - use short durations (1-2 seconds) for quick verification
155+
156+
## Error Handling
157+
158+
### Terminal Safety
159+
- Always restore terminal state on panic or error
160+
- Use `color-eyre` for better error messages and stack traces
161+
- Set up panic hooks to ensure terminal cleanup
162+
- Handle all `Result` types explicitly
163+
164+
### Graceful Degradation
165+
- Continue operation when non-critical errors occur
166+
- Log errors appropriately without crashing
167+
- Provide meaningful error messages to users
168+
- Validate input data before processing
169+
170+
## Performance Guidelines
171+
172+
### Rendering Efficiency
173+
- Avoid unnecessary re-renders by checking if data has changed
174+
- Use efficient data structures for large lists
175+
- Minimize string allocations in hot paths
176+
- Cache computed values when appropriate
177+
178+
### Memory Management
179+
- Bound collection sizes (logs, history data)
180+
- Use `Vec::with_capacity()` when size is known
181+
- Prefer borrowing over cloning when possible
182+
- Clean up resources properly
183+
184+
## Future Development
185+
186+
### Adding New Views
187+
1. Create new file in `ui/` directory (e.g., `ui/settings.rs`)
188+
2. Add view enum variant to `app.rs`
189+
3. Add rendering call to `ui/mod.rs`
190+
4. Add keyboard shortcut to `events.rs`
191+
5. Update footer help text in `ui/components.rs`
192+
193+
### Adding New Components
194+
1. Add to `ui/components.rs` if reusable across views
195+
2. Add to specific view file if view-specific
196+
3. Follow consistent styling patterns
197+
4. Include proper error handling
198+
199+
### Mock Data Extensions
200+
1. Add new data types to `mock_data.rs`
201+
2. Implement realistic generation patterns
202+
3. Add appropriate unit tests
203+
4. Update dynamic simulation if needed
204+
205+
## Dependencies
206+
207+
### Core Dependencies
208+
- **`ratatui`**: TUI framework - prefer latest stable version
209+
- **`crossterm`**: Cross-platform terminal manipulation
210+
- **`color-eyre`**: Enhanced error handling and reporting
211+
212+
### Development Dependencies
213+
- **`serial_test`**: For tests that need sequential execution
214+
- Standard Rust testing framework for unit tests
215+
216+
## Documentation
217+
218+
### Code Comments
219+
- Document complex algorithms and business logic
220+
- Explain non-obvious design decisions
221+
- Use doc comments (`///`) for public APIs
222+
- Keep comments up-to-date with code changes
223+
224+
### README Updates
225+
- Keep feature lists current
226+
- Document new keyboard shortcuts
227+
- Update screenshots when UI changes significantly
228+
- Maintain installation and usage instructions
229+
230+
## Git Workflow
231+
232+
### Commit Messages
233+
- Use conventional commit format: `feat:`, `fix:`, `refactor:`, etc.
234+
- Be specific about what changed and why
235+
- Reference issues when applicable
236+
237+
### Branch Strategy
238+
- Create feature branches for new views or major changes
239+
- Keep commits focused and atomic
240+
- Test thoroughly before merging
241+
242+
Remember: The TUI should feel responsive, intuitive, and professional. Always prioritize user experience and code maintainability.

src/bin/feos-tui/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

0 commit comments

Comments
 (0)