← All libraries

CandyLister

CandyLister

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

port of treilik/bubblelister treelistviewnavigation

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

$model = Model::new();
$model->setWidth(80)->setHeight(24);
$model->addItem(new StringItem('src/main.php'));
$model->addItem(new StringItem('src/Model.php'));
$model->addItem(new StringItem('tests/MainTest.php'));
$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 / filtered).
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 → filtered
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
ModelfilterStateCurrent FilterState (unfiltered / filtering / filtered)
FilterStateunfilteredNo filter active
FilterStatefilteringFilter function set, applying
FilterStatefilteredFiltering complete, results shown
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.