Skeleton repo for bootstrapping a SugarCraft TUI app. Pour your model into the mold and you've got a working app.
composer create-project sugarcraft/candy-mold my-app
cd my-app
./bin/startand you'll see a working counter. Replace src/Counter.php with your own Model, keep editing.
my-app/
βββ composer.json # requires candy-core + candy-sprinkles
βββ phpunit.xml
βββ bin/start # entry point β runs Program(new Counter())
βββ src/
β βββ Counter.php # demo Model with up/down/quit, styled border
βββ tests/
βββ CounterTest.php
bin/start is just three meaningful lines: load the autoloader, instantiate your Model, hand it to Program::run(). The Program harness owns the event loop, render tick, signal handling, raw-mode setup, and alt-screen lifecycle β you only write Models.
A Model is three pure methods:
public function init(): ?\Closure; // optional startup Cmd (timers, fetch...)
public function update(Msg $msg): array; // [nextModel, ?Cmd]
public function view(): string; // current frameThe shape is borrowed verbatim from Bubble Tea / The Elm Architecture. State lives on the value object, transitions are pure functions, side effects (timers, HTTP, file I/O) get scheduled as Cmds rather than executed inline.
update() always returns a new Model rather than mutating $this. That's why the demo declares public readonly int $n β the only way to "change" the count is to construct a fresh Counter with the new value.
| Want to⦠| Reach for⦠|
|---|---|
| Add a text input | sugarcraft/sugar-bits β TextInput |
| Show a spinner while loading | sugarcraft/sugar-bits β Spinner |
| Render Markdown help text | sugarcraft/candy-shine β Renderer |
| Tail a log into a scrollable pane | sugarcraft/sugar-bits β Viewport |
| Build a multi-page wizard | sugarcraft/sugar-prompt β Group |
| Plot a sparkline | sugarcraft/sugar-charts β Sparkline |
Make it ssh-accessible |
sugarcraft/candy-wish |
Add the dep, import its classes, return them from view(). They're all pure renderers on the same Style-based vocabulary.
composer install
vendor/bin/phpunitThe included tests/CounterTest.php shows how to test update() deterministically by constructing Msg objects directly. No event loop, no terminal, no mocking β just call methods and assert the returned tuple.
MIT.
