Rust widget
Module Documentation
Text Widget System
Module Overview
Provides functionalities for creating and composing text widgets to build character-based terminal interface elements.
Core Function Functions
1. create
- Functionality: Create a text widget with a border.
- Parameters:
create title content width height
title
: Title displayed on the top border (string).content
: Text content within the widget (string).width
: Width of the widget (integer > 4).height
: Height of the widget (integer ≥ 3).
- Return Value: Formatted string widget.
- Errors:
- Parameter type/quantity mismatch.
- Width < Title length.
- Width ≤ 4 or Height < 3.
- Design Features:
- Automatic text wrapping (using
textwrap
library). - Centered title display.
- Adaptive border length.
- Automatic text wrapping (using
2. joinx
- Functionality: Horizontally concatenate multiple widgets.
- Parameters:
joinx widget1 widget2 ...
- At least 2 string-type widgets.
- Return Value: Horizontally concatenated string.
- Errors:
- Parameter count < 2.
- Non-string parameters.
- Inconsistent widget heights.
- Processing Steps:
- Validate all widgets are strings.
- Check that all widgets have the same number of lines.
- Concatenate horizontally line by line.
3. joiny
- Functionality: Vertically concatenate multiple widgets.
- Parameters:
joiny widget1 widget2 ...
- At least 2 string-type widgets.
- Return Value: Vertically concatenated string.
- Errors:
- Parameter count < 2.
- Non-string parameters.
- Inconsistent widget widths.
- Processing Steps:
- Validate all widgets are strings.
- Check that the first line widths are consistent.
- Vertically concatenate and remove newline characters.
Usage Examples
Create Widget
widget.create "System Information" "CPU: 80%\nMemory: 4.2/8GB" 30 5
Output:
┌────── System Information ──────┐ |
Horizontal Concatenation
widget.joinx widget1 widget2
Vertical Concatenation
widget.joiny widgetA widgetB
Design Constraints
- Size Limitations:
- Minimum width: 5 characters (including borders).
- Minimum height: 3 lines (including borders).
- Encoding Requirements:
- Only supports UTF-8 characters.
- Automatically filters out
\r
carriage return characters.
- Performance Considerations:
- Avoid unnecessary string copying.
- Use iterators to handle large texts.
- Error Handling:
- Provide detailed parameter error messages.