← All 40 libraries

SugarFlexbox

SugarFlexbox

FlexBox layout + simple sort/filter table

inspired by 76creates/stickers flexboxtablelayoutgrid

SugarFlexbox code coverage

FlexBox layout engine for terminal grids — ratio-based item sizing, gap, justify, align. Plus a simple table with sort, filter, cursor nav, and column styling. Viewport and Scrollbar compose the sugar-widgets SSOT.

Install

composer require sugarcraft/sugar-flexbox

Quickstart

use SugarCraft\Flexbox\Flex\{FlexBox, FlexItem};
use SugarCraft\Flexbox\Table\{Table, Column};

$flex = FlexBox::row(
    FlexItem::new('LEFT')->withRatio(1),
    FlexItem::new('RIGHT')->withRatio(2),
)->withGap(2);

$table = (new Table())
    ->addColumn(Column::make('Name', 20))
    ->addRow(['Alice'])
    ->addRow(['Bob'])
    ->sortBy(0, true);

What's in the box

FlexBoxRatio-based row / column layout. Justify: SpaceBetween, Center, Start, End. Align: Center, Start, End, Stretch.
TableSort by column (asc/desc toggle), filter by text, cursor navigation, per-column style.
ViewportScrollable viewport composes sugar-widgets Viewport (SSOT). Keyboard nav, mouse wheel, smooth scroll, scrollbar. Sticky headers/footers deferred.
ScrollbarScrollbar composes sugar-widgets Scrollbar (SSOT). Vertical/horizontal, configurable thumb/track chars.
ImmutabilityAll builders return new instances.

Source & demos

Try the quickstart →

API

ClassMethodDescription
FlexBoxrow(...items)Create horizontal flexbox
FlexBoxcolumn(...items)Create vertical flexbox
FlexBoxwithGap(pixels)Set gap between items
FlexItemnew(content)Create flex item
FlexItemwithRatio(n)Set size ratio
Tablenew()Create table
TableaddColumn(col)Add table column
TableaddRow(cells)Add table row
TablesortBy(col, asc)Sort by column
Viewportnew(w, h)Create viewport (80×24 default)
ViewportwithContent(str, w, h)Create with string content
ViewportwithScrollbar(bool)Toggle scrollbar display
ViewportlineUp/Down(n)Scroll by n lines
ViewportgotoTop/Bottom()Jump to start/end
Scrollbarvertical()Vertical scrollbar
Scrollbarhorizontal()Horizontal scrollbar
Scrollbarview(state, height)Render scrollbar

Demos.

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

FlexBox row + column

FlexBox row + column

Ratio 1:2:1 row + column with gap=1.
Sort + filter table

Sort + filter table

Sortable + filterable table with per-column align.
Static table

Static table

Static table render with zebra rows.