← All libraries

SugarBoxer

SugarBoxer

Box-drawing layout engine for terminal UIs

port of treilik/bubbleboxer layoutboxborderui

Compose terminal layouts with horizontal and vertical panels. Attach borders, set individual widths/heights, and nest arbitrarily deep.

Install

composer require sugarcraft/sugar-boxer

Quickstart

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);

What's in the box

H/V panelsRow and column composition with weighted sizing.
BordersPre-attached or custom borders per panel.
Nested layoutsArbitrarily deep nesting — grids within grids.
Word-wrapContent-aware panel sizing.

Source & demos

Try the quickstart →

API

ClassMethodDescription
SugarBoxernew()Create a boxer instance
SugarBoxerleaf(string)Leaf node with string content
SugarBoxerhorizontal(Node ...)Horizontal (row) layout
SugarBoxervertical(Node ...)Vertical (column) layout
SugarBoxernoBorder(Node)Flat layout without separators
SugarBoxerrender(Node, int $width, int $height)Render to ANSI string
Nodeleaf(string)Static leaf constructor
Nodehorizontal(Node ...)Static horizontal constructor
Nodevertical(Node ...)Static vertical constructor
NodenoBorder(Node)Static no-border constructor
NodewithMinWidth(int)Minimum width hint
NodewithMaxWidth(int)Maximum width hint
NodewithMinHeight(int)Minimum height hint
NodewithMaxHeight(int)Maximum height hint
NodewithPadding(int)Inner padding (cells)
NodewithBorder(bool)Show/hide box border
NodewithSpacing(int)Gap between children (cells)
NodewithBorderStyle(?Border)Border char set from candy-sprinkles
NodewithStyle(?Style)Style (color, attributes) from candy-sprinkles
NodewithTitle(string)Box title text
NodewithMargin(int $top, ...)Outer margin (top/right/bottom/left)
NodewithAlignH(Align)Horizontal text alignment
NodewithAlignV(VAlign)Vertical text alignment

Demos.

VHS-recorded GIFs of every example shipped with the library. Regenerated automatically on every push that touches the source.

Border styles

Border styles

No-border, padded, single-line, double-line layouts.
Basic compose

Basic compose

Horizontal + vertical panels with weighted sizing.
Nested grids

Nested grids

A grid-of-grids — header / body / footer with sidebars.