Box-drawing layout engine for terminal UIs
Compose terminal layouts with horizontal and vertical panels. Attach borders, set individual widths/heights, and nest arbitrarily deep.
composer require sugarcraft/sugar-boxer
use SugarCraft\Boxer\SugarBoxer;
use SugarCraft\Sprinkles\{Align, Border};
$boxer = SugarBoxer::new();
$layout = $boxer->vertical(
$boxer->horizontal(
$boxer->leaf('Left panel'),
$boxer->leaf('Right panel'),
),
$boxer->leaf('Bottom bar'),
);
echo $boxer->render($layout, 60, 20);
| Class | Method | Description |
|---|---|---|
| SugarBoxer | new() | Create a boxer instance |
| SugarBoxer | leaf(string) | Leaf node with string content |
| SugarBoxer | horizontal(Node ...) | Horizontal (row) layout |
| SugarBoxer | vertical(Node ...) | Vertical (column) layout |
| SugarBoxer | noBorder(Node) | Flat layout without separators |
| SugarBoxer | render(Node, int $width, int $height) | Render to ANSI string |
| Node | leaf(string) | Static leaf constructor |
| Node | horizontal(Node ...) | Static horizontal constructor |
| Node | vertical(Node ...) | Static vertical constructor |
| Node | noBorder(Node) | Static no-border constructor |
| Node | withMinWidth(int) | Minimum width hint |
| Node | withMaxWidth(int) | Maximum width hint |
| Node | withMinHeight(int) | Minimum height hint |
| Node | withMaxHeight(int) | Maximum height hint |
| Node | withPadding(int) | Inner padding (cells) |
| Node | withBorder(bool) | Show/hide box border |
| Node | withSpacing(int) | Gap between children (cells) |
| Node | withBorderStyle(?Border) | Border char set from candy-sprinkles |
| Node | withStyle(?Style) | Style (color, attributes) from candy-sprinkles |
| Node | withTitle(string) | Box title text |
| Node | withMargin(int $top, ...) | Outer margin (top/right/bottom/left) |
| Node | withAlignH(Align) | Horizontal text alignment |
| Node | withAlignV(VAlign) | Vertical text alignment |
VHS-recorded GIFs of every example shipped with the library. Regenerated automatically on every push that touches the source.