PHPackages                             sugarcraft/sugar-boxer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. sugarcraft/sugar-boxer

ActiveLibrary[CLI &amp; Console](/categories/cli)

sugarcraft/sugar-boxer
======================

PHP port of treilik/bubbleboxer — box-drawing layout engine. Compose terminal content into H/V panels with box-drawing borders, padding, and dynamic dimension calculation.

00PHP

Since May 29Pushed 1w agoCompare

[ Source](https://github.com/sugarcraft/sugar-boxer)[ Packagist](https://packagist.org/packages/sugarcraft/sugar-boxer)[ RSS](/packages/sugarcraft-sugar-boxer/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![sugar-boxer](.assets/icon.png)](.assets/icon.png)

[![CI](https://github.com/detain/sugarcraft/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/detain/sugarcraft/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/b9ca27e23e939464bd2806f0881fc93b89ddb5064e57d11531126e8595efc7c6/68747470733a2f2f636f6465636f762e696f2f67682f64657461696e2f737567617263726166742f6272616e63682f6d61737465722f67726170682f62616467652e7376673f666c61673d73756761722d626f786572)](https://app.codecov.io/gh/detain/sugarcraft?flags%5B0%5D=sugar-boxer)[![Packagist Version](https://camo.githubusercontent.com/1d2da1f49a1336f7d49d5d26600a88de09b70660e5a96e2d14f3e320f06d77df/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7375676172636f72652f73756761722d626f7865723f6c6162656c3d7061636b6167697374)](https://packagist.org/packages/sugarcore/sugar-boxer)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP](https://camo.githubusercontent.com/e78ffc83837c0d12647811a7fd1910c3cbeae04988de94bb4fd5b67e0874696a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d254532253839254135382e312d3838393262662e737667)](https://www.php.net/)

SugarBoxer
==========

[](#sugarboxer)

PHP port of [treilik/bubbleboxer](https://github.com/treilik/bubbleboxer) — box-drawing layout engine for composing terminal content into H/V panel layouts with borders and padding.

Features
--------

[](#features)

- **H/V composition** — build arbitrary layouts by nesting `horizontal()` and `vertical()` panels
- **Box-drawing borders** — classic ANSI box characters (╭ ╮ ╰ ╯ │ ─ ├ ┤ ┬ ┴ ┼)
- **No-border mode** — render adjacent panels without separators
- **Per-panel padding** — inner whitespace around content
- **Width/Height hints** — nodes can specify min/max dimensions
- **Dynamic dimension calculation** — boxer computes total viewport from children
- **Leaf content** — any stringable content at leaf nodes
- **Pure renderer** — outputs ANSI box-drawing strings; works with any TUI framework

Install
-------

[](#install)

```
composer require sugarcraft/sugar-boxer
```

Quick Start
-----------

[](#quick-start)

```
use SugarCraft\Boxer\SugarBoxer;

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

Layout API
----------

[](#layout-api)

```
// Leaf node with string content
$boxer->leaf('Hello, World!');

// Horizontal split (side by side)
$boxer->horizontal(Node ...$children): Node

// Vertical split (stacked)
$boxer->vertical(Node ...$children): Node

// Node with explicit dimensions
$node->withMinWidth(20)
     ->withMaxWidth(80)
     ->withMinHeight(5)
     ->withMaxHeight(40)
     ->withPadding(1)           // inner padding
     ->withBorder(true)         // show box border
     ->withSpacing(1);          // gap between children

// No-border (flat) layout
$boxer->noBorder(Node): Node
```

Styling with candy-sprinkles
----------------------------

[](#styling-with-candy-sprinkles)

sugar-boxer composes canonical styling primitives from [`candy-sprinkles`](https://github.com/sugarcraft/candy-sprinkles):

```
use SugarCraft\Sprinkles\{Align, Border, Style, VAlign};

// Set border character set (rounded / sharp / double / ascii / ...)
// Passing null clears the style but preserves border visibility.
$node->withBorderStyle(Border::rounded());  // ╭ ╮ ╰ ╯ │
$node->withBorderStyle(Border::double());    // ╔ ╗ ╚ ╝ ║ ═
$node->withBorderStyle(null);                // clear explicit style

// Apply foreground/background colors and attributes via Style
$node->withStyle(new Style(fg: 'cyan', bg: 'black'));

// Box title text rendered in the top border
$node->withTitle('My Panel');

// Outer spacing (top, right, bottom, left) — sugar-boxer-specific
$node->withMargin(1);                  // all sides
$node->withMargin(1, 2);               // top/bottom=1, left/right=2
$node->withMargin(1, 2, 1, 2);         // explicit all four

// Text alignment within the content area
$node->withAlignH(Align::CENTER);
$node->withAlignH(Align::RIGHT);
$node->withAlignV(VAlign::MIDDLE);
$node->withAlignV(VAlign::BOTTOM);
```

API Reference
-------------

[](#api-reference)

MethodDescription`$boxer->leaf(string)`Leaf node with string content`$boxer->horizontal(Node ...)`Horizontal (row) layout`$boxer->vertical(Node ...)`Vertical (column) layout`$boxer->noBorder(Node)`Flat layout without separators`$boxer->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`->withMinWidth(int)`Minimum width hint`->withMaxWidth(int)`Maximum width hint`->withMinHeight(int)`Minimum height hint`->withMaxHeight(int)`Maximum height hint`->withPadding(int)`Inner padding (cells)`->withBorder(bool)`Show/hide box border`->withSpacing(int)`Gap between children (cells)`->withBorderStyle(?Border)`Border char set from candy-sprinkles`->withStyle(?Style)`Style (color, attributes) from candy-sprinkles`->withTitle(string)`Box title text`->withMargin(int $top, ...)`Outer margin (top/right/bottom/left)`->withAlignH(Align)`Horizontal text alignment`->withAlignV(VAlign)`Vertical text alignmentBorder Characters
-----------------

[](#border-characters)

```
╭────┬────╮   ← top-left, top horiz, top-right, cross
│    │    │   ← vert bar
├────┼────┤   ← left-join, cross, right-join
╰────┴────╯   ← bottom-left, bottom horiz, bottom-right

```

Buffer diffing
--------------

[](#buffer-diffing)

The renderer maintains a `?Buffer $previousFrame` across renders. On each render it builds the current Buffer, computes `current->diff(previous)` (from [candy-buffer](https://github.com/detain/sugarcraft-candy-buffer)), and emits only the delta ANSI ops via `DiffEncoder::encode($ops)`. The current frame then replaces `previousFrame` for the next render.

**SSH bandwidth + flicker win:** a one-character change in an 80×24 viewport produces ~8 bytes of delta ops instead of ~1 940 bytes for a full repaint. Over an SSH session this means far less per-frame data on the wire and eliminates the full-screen flicker of rewrite-based terminals. The first render after startup or a resize still emits a full Buffer (no diff possible), so behaviour is always correct.

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

20

↑

LowBetter than 13% of packages

Maintenance64

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/b1036e0717211b8030b83cbe729e8ba6ba442fdbd5285fb97a39d7dcfe339342?d=identicon)[detain](/maintainers/detain)

---

Top Contributors

[![detain](https://avatars.githubusercontent.com/u/1364504?v=4)](https://github.com/detain "detain (58 commits)")

### Embed Badge

![Health badge](/badges/sugarcraft-sugar-boxer/health.svg)

```
[![Health](https://phpackages.com/badges/sugarcraft-sugar-boxer/health.svg)](https://phpackages.com/packages/sugarcraft-sugar-boxer)
```

###  Alternatives

[seld/cli-prompt

Allows you to prompt for user input on the command line, and optionally hide the characters they type

24726.4M22](/packages/seld-cli-prompt)[illuminate/console

The Illuminate Console package.

13045.3M6.1k](/packages/illuminate-console)[php-tui/php-tui

Comprehensive TUI library heavily influenced by Ratatui

596920.8k12](/packages/php-tui-php-tui)[styleci/cli

The CLI tool for StyleCI

71464.1k9](/packages/styleci-cli)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
