← All 41 libraries

CandyLister

CandyLister

Tree / list view with box-drawing prefixes + cursor nav

port of treilik/bubblelister treelistviewnavigation

CandyLister code coverage

Tree and flat list views with customizable box-drawing prefixes, cursor navigation, and word-wrap. Composeable with any bubbletea model.

Install

composer require sugarcraft/candy-lister

Quickstart

use SugarCraft\Lister\{Model, StringItem, DefaultPrefixer};

// Fluent setters return NEW Models - rebind; instances are immutable.
$model = Model::new()->setWidth(80)->setHeight(24);
$model = $model->addItem(new StringItem('src/main.php'));
$model = $model->addItem(new StringItem('src/Model.php'));
$model = $model->addItem(new StringItem('tests/MainTest.php'));
$model = $model->setPrefixer(new DefaultPrefixer());

echo $model->view();
// Renders the list with ╭ ├ │ prefixes and > cursor marker

What's in the box

Box-drawing prefixesCustomizable prefixers per depth level — lines, bullets, arrows.
Cursor navigationUp / Down / Home / End movement with viewport tracking.
Word-wrapAuto-wrap long items to terminal width.
Filter state machinewithFilterFn() / withoutFilter() with FilterState enum (unfiltered / filtering).
Fuzzy matchingSmith-Waterman local alignment scorer — scores and ranks candidates.

Source & demos

Try the quickstart →

API

ClassMethodDescription
Modelnew()Create model with defaults
ModelwithFilterFn(\Closure)Filter items; returns new Model; filterState → filtering
ModelwithoutFilter()Clear filter; restore original items; filterState → unfiltered
ModeladdItem(\Stringable)Append a list item
ModelsetWidth(int)Set viewport width in cells
ModelsetHeight(int)Set viewport height in lines
ModelsetPrefixer(Prefixer)Attach a prefixer instance
ModelsetSuffixer(Suffixer)Attach a suffixer instance
Modellines()Return visible lines as array
Modelview()Render list as ANSI string
ModelfilterState()Current FilterState (unfiltered / filtering)
FilterStateunfilteredNo filter active
FilterStatefilteringFilter function set and applied
FuzzyMatchscore(query, candidate)Smith-Waterman alignment score (int, higher = better)
FuzzyMatchmatch(query, list<\Stringable>)Filter and rank items by score; returns list of [item, score] pairs
ItemvalueThe underlying \Stringable
StringItemnew(string)Wrap a plain string as a list item

Demos.

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

Cursor + filter

Cursor + filter

Tree/list view with cursor nav and word-wrap.
Custom styling

Custom styling

Per-node colours and box-drawing prefixes.