Lumesh Widget Module

wiki libs

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.

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:
    1. Validate all widgets are strings.
    2. Check that all widgets have the same number of lines.
    3. 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:
    1. Validate all widgets are strings.
    2. Check that the first line widths are consistent.
    3. 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 ──────┐
│ CPU: 80% │
│ Memory: 4.2/8GB │
│ │
└────────────────────────────────┘

Horizontal Concatenation

widget.joinx widget1 widget2

Vertical Concatenation

widget.joiny widgetA widgetB


Design Constraints

  1. Size Limitations:
    • Minimum width: 5 characters (including borders).
    • Minimum height: 3 lines (including borders).
  2. Encoding Requirements:
    • Only supports UTF-8 characters.
    • Automatically filters out \r carriage return characters.
  3. Performance Considerations:
    • Avoid unnecessary string copying.
    • Use iterators to handle large texts.
  4. Error Handling:
    • Provide detailed parameter error messages.