Packages
Multi-surface application runtime for Elixir. One TEA module renders to terminal, browser (LiveView), SSH, and MCP (agents). 30+ widgets, flexbox + CSS grid, AI agent runtime, distributed swarm with CRDTs, time-travel debugging, session recording, sandboxed REPL, and agentic commerce.
Current section
Files
Jump to
Current section
Files
lib/raxol/terminal/commands/REFACTORING.md
# CommandExecutor Refactoring Summary
This document summarizes the refactoring of the `Raxol.Terminal.CommandExecutor` module, which was part of the larger Raxol codebase reorganization effort.
## Original Issues
The original `command_executor.ex` file:
- Was excessively large (1243 lines)
- Mixed multiple responsibilities
- Had poor maintainability due to size and complexity
- Made it difficult to test individual components
## Refactoring Approach
We applied the following refactoring strategies:
1. **Separation of Concerns**: Split the module based on logical functionality
2. **Interface Preservation**: Maintained backward compatibility through delegation
3. **Deprecation Path**: Added clear warnings and migration guidance
4. **Comprehensive Testing**: Added tests for the new modular components
## New Structure
The refactored structure consists of these modules:
### 1. Raxol.Terminal.Commands.Parser
- Handles parsing of command parameters
- Extracts parameter parsing logic from the original module
- Provides utility functions for parameter manipulation
- Examples:
- `parse_params/1` - Parses parameter strings like "5;10;15"
- `get_param/3` - Safely gets a parameter with default value
### 2. Raxol.Terminal.Commands.Modes
- Handles terminal mode setting and resetting operations
- Manages both DEC private modes and standard ANSI modes
- Examples:
- `handle_dec_private_mode/3` - Sets/resets DEC modes (e.g., cursor visibility)
- `handle_ansi_mode/3` - Sets/resets ANSI modes (e.g., insert mode)
### 3. Raxol.Terminal.Commands.Screen
- Handles screen manipulation commands
- Manages operations like clearing, scrolling, and line manipulation
- Examples:
- `clear_screen/2` - Clears screen based on different modes
- `clear_line/2` - Clears line based on different modes
- `insert_lines/2` - Inserts blank lines at cursor position
- `delete_lines/2` - Deletes lines at cursor position
### 4. Raxol.Terminal.Commands.Executor
- Main entry point that coordinates other modules
- Dispatches commands to appropriate handlers
- Handles commands not covered by specialized modules
- Primary function: `execute_csi_command/4`
## Backward Compatibility
The original `Raxol.Terminal.CommandExecutor` module was updated to:
- Add documentation about the refactoring
- Add `@deprecated` module attribute
- Add explicit function-level deprecation warnings
- Delegate all calls to the new modules
## Testing
Added comprehensive tests for the new modules:
- `ParserTest` - Tests parameter parsing and utility functions
- `ScreenTest` - Tests screen manipulation operations
## Future Work
Future improvements could include:
1. Additional test coverage for `Modes` and `Executor` modules
2. Further refactoring of the `Executor` module to extract more functionality
3. Move SGR (Select Graphic Rendition) handling to a separate module
4. Add benchmarks to ensure performance is maintained or improved
## Benefits Achieved
This refactoring has:
1. Reduced individual file sizes to manageable levels
2. Increased code clarity by separating different concerns
3. Improved testability of individual components
4. Made the codebase more maintainable
5. Provided a clear migration path for users
6. Followed the principles outlined in the Raxol Repository Reorganization Plan