CandyTop
Terminal system monitor
candy-top is a full-screen terminal system monitor in pure PHP, in the tradition of btop. It draws cpu, memory and disks, network, processes, containers and VMs, GPU and NPU boxes, and a server BMC band, with braille, block and sextant graphs and gradient meters. It reads Linux /proc and /sys or FreeBSD sysctl, and it runs on the sugar-core Model/Cmd runtime. It reads btop's config format, so a copied btop.conf loads unchanged.
Install
composer require sugarcraft/candy-top
Add :@dev (composer require sugarcraft/candy-top:@dev) while your project's minimum-stability is stable and you want a commit newer than the newest candy-top/v* tag. Composer installs the launcher as vendor/bin/candy-top. For a global tool, use composer global require sugarcraft/candy-top.
Requires PHP 8.3 or newer on Linux or FreeBSD. The host needs an interactive terminal on both stdin and stdout, and a UTF-8 locale codeset. ext-posix, ext-pcntl and ext-sodium are optional, and nvidia-smi and ipmitool enable the NVIDIA and BMC readings.
Quickstart
Start it on the live host, or on deterministic fake data that never reads your processes:
vendor/bin/candy-top # the live host
vendor/bin/candy-top --config ~/top.conf # another config file (also the save target)
vendor/bin/candy-top --fake # deterministic demo data, never the real host
vendor/bin/candy-top --help # options plus the full key list
vendor/bin/candy-top --version # version line, no tty needed
Four boxes appear on first run: cpu, memory, network and processes. Press 1 to 4 to toggle them, F1 or h for the help overlay, and q to quit. The layout is saved on the way out, as btop does.
Concepts
App is the program's Model. init() returns the startup batch: the clock, the first collection and the data tick. update(Msg) folds each message into the state and returns [Model, ?Cmd]. view() returns the frame. Sampling and config saves run as commands, so the drawing never waits on the host.
Data comes from one of two sources. The live source reads the host through the collectors in Collect\*. With --fake, the same interface is served by Source\Fake\*, whose waves and process lists are seeded, so a demo or a bug report needs no host state. Each box is a panel in Panel\*, and View\FrameBuilder lays the boxes out and works out the smallest terminal that fits them.
Configuration is declared once. Config\Schema lists the options with their types, defaults and bounds. Config\ConfigFile reads the btop-format file, and a save writes it atomically, so a crash never leaves a half-written file.
Tasks
Look at the layout without touching the host
--fake still needs a terminal, because the tty gate runs before the fake source starts. Outside a terminal, run it under a pseudo-terminal, or record the VHS tape in .vhs/top.tape.
script -qec 'vendor/bin/candy-top --fake' /dev/null
Try a preset or a theme for one session
-p N applies layout preset N from the presets option, and -t name applies a theme. Both last for this session only, and the config file keeps its value.
vendor/bin/candy-top -p 2 -t tokyo-night
Make a theme or an option permanent
Set the value in the config file, or change it in the options menu (F2 or o), which saves on exit.
color_theme = "tokyo-night"
update_ms = 1000
shown_boxes = "cpu mem net proc"
Add your own theme
Drop any btop-format .theme file into ~/.config/candy-top/themes/, or point --themes-dir <path> at a directory for one run. The file is then selectable by its name.
Act on a process
Select a row in the process box with the arrow keys. t asks to send SIGTERM and k asks to send SIGKILL; both open a Yes/No box before anything is sent. s opens the signal chooser, and N sets a new nice value. With vim_keys on, kill is K, because k moves the selection up. Renicing needs ext-pcntl, and names need ext-posix.
Keep the tree collapse state between runs
Set proc_tree_persist_state = true. The collapsed and expanded branches are stored in $XDG_STATE_HOME/candy-top/tree-state.json, not in the config, so the config stays btop-compatible.
Update a phar install
The released candy-top.phar updates itself. Check first, and install only when you choose to. self-update answers before the terminal check, so it works over ssh and in cron.
php candy-top.phar self-update --check
php candy-top.phar self-update
php candy-top.phar self-update --rollback
API reference
The surface has about 280 classes. The table lists the entry points and the largest classes, which carry most of the behavior. Each class lives under SugarCraft\Top\ with the namespace shown.
| Class | Method | Description |
|---|---|---|
App | static start(Config, Palette, HostInfo, array $panels, …), init(), update(Msg), view() | The Model: builds the program, then folds messages into state and draws the frame. programOptions() maps the config to the terminal options. |
Config\Schema | options(), option(name), persistedNames(), defaults() | The declared options, with types, defaults and bounds. |
Config\ConfigFile | new(?path), defaultPath(), load(), write(Config) | Reads and atomically writes the btop-format config file. |
Theme\ThemeRegistry | fromDirs(...$dirs), names(), find(theme), load(theme) | Lists the theme files and loads a palette by name. |
View\FrameBuilder | layout(cols, rows, Config, coreCount), minSize(boxes) | Computes the box positions and the smallest terminal that fits the layout. |
Panel\ProcPanel | new(Source, ?ProcessControl), withGpu(?Source), box() | The process list: sorting, the tree view, filtering and the GPU columns. |
Panel\Cpu\CpuView | paint(Region, PanelFrame, CpuPanel) | Draws the cpu box: graphs, per-core grid, frequency and temperatures. |
Panel\Proc\ProcView | sizes(width, graphs), paint(Region, PanelFrame, rows, ProcSelection) | Draws the process table and its detail view. |
Panel\Ipmi\IpmiView | paint(Region, PanelFrame, IpmiData) | Draws the BMC band: power, PSUs, temperatures, fans and the event log. |
Collect\Gpu | new(), candidates(), sample(), sampleAsync() | Reads NVIDIA through nvidia-smi, and AMD, Intel and NPU devices through sysfs. |
Collect\Process\AsyncCommand | run(argv, timeout, maxBytes), launch(argv, loop) | Runs an external command with a timeout and an output cap, without blocking the loop. |
Overlay\OptionsMenu | new(), choices(option, OverlayContext), update(Msg, OverlayContext) | The tabbed options menu, with live preview. |
Cli\SelfUpdate | run() | The self-update verb for phar installs: check, update and roll back. |
Cli\Help | version(), versionString() | The version line printed by --version. |
Input\KeyTable | rows(), keyRows(), bindings() | The key table. The help overlay and --help both read it. |
Configuration
The config file is $XDG_CONFIG_HOME/candy-top/config.conf, or ~/.config/candy-top/config.conf when XDG_CONFIG_HOME is unset or not absolute. --config <path> reads another file and makes it the save target. The format is btop's: # comments and name = value lines, with strings in double quotes. Unknown keys are skipped, and a value that fails validation is dropped with a warning on stderr, while the option keeps its previous value.
The schema declares 115 options, and 105 of them persist to the file. The table lists the options most people change, with the defaults from Config\Schema. examples/config-defaults.php prints the same defaults from the code.
| Option | Type | Default | Effect |
|---|---|---|---|
color_theme | string | "pastel" | The theme: a .theme file name, or Default or TTY. |
update_ms | integer | 2000 | Frame update period in milliseconds. The + and - keys change it by 100. |
shown_boxes | string | "cpu mem net proc" | The boxes shown at start, in order. |
graph_symbol | string | "braille" | The graph glyphs: braille, block, block2 or tty. |
truecolor | boolean | true | Set false to map colors to the 256-color cube. |
theme_background | boolean | true | Paint the theme's background. false uses the terminal's own background. |
tty_mode | boolean | false | Runtime only, so a config file cannot set it. It turns on by itself on a real console, giving the 16-color look with stepped gradients and tty glyphs. Use force_tty to turn it on anywhere. |
force_tty | boolean | false | Turn TTY mode on even when the terminal is not a console. |
vim_keys | boolean | false | Add h, j, k, l movement in lists, and g/G for first and last. Kill moves to K and help moves to H. |
proc_sorting | string | "cpu lazy" | The process sort column, with its mode. |
proc_tree | boolean | false | Start the process list in tree view. |
proc_tree_persist_state | boolean | false | Remember collapsed and expanded branches in the XDG state directory. |
net_auto | boolean | true | Auto-scale the network graphs. |
save_config_on_exit | boolean | true | Write changed options back to the config on every quit path. |
ipmi_update_ms | integer | 10000 | How often the BMC band is sampled, in milliseconds. |
The file is rewritten on exit when save_config_on_exit is on and something persisted has changed. That includes a file that did not exist yet. A value that fails validation is dropped with a warning, and the warning names the value.
Keys
candy-top --help prints the full table, generated from the same Input\KeyTable the help overlay uses. The most used keys are below. The README key bindings section has the complete list, including the mouse actions.
| Key | Action |
|---|---|
Esc, m | Main menu |
F2, o | Options menu |
F1, ?, h (H with vim_keys) | Help overlay |
1 to 4 | Toggle the cpu, mem, net and proc boxes |
5 to 0 | Toggle the GPU boxes |
x, [, ] | Toggle the containers box, and select the previous or next container |
v, s, S | Toggle the VM dashboard, and step its card order |
Shift+I | Toggle the ipmi box |
p, Shift+P | Next and previous layout preset |
+, -, = | Add or subtract 100 ms from the update period |
f or / | Filter the process list. Start with ! for a regex. |
e, E, c, r | Tree view, collapse all, per-core process usage, reverse the sort |
Enter, F, u | Detailed view of the selected process, follow it, pause the list |
t, k (K with vim_keys), s, N | Terminate, kill, signal or renice the selected process. Terminate and kill ask for confirmation first. |
Ctrl+R | Reload the config file from disk |
q, Ctrl+C | Quit, saving the config |
Theming and TTY mode
The default theme is pastel, candy-top's own palette on a deep plum background, with box outlines that flow from one color to the next. The 43 bundled theme files are the btop theme set plus pastel, and Default and TTY are built in. The themes example lists them.
Themes are read from the user directory first ($XDG_CONFIG_HOME/candy-top/themes, or ~/.config/candy-top/themes), then from the bundled themes/ directory. When both hold the same file name, the user copy wins every lookup by name. --themes-dir puts a directory above both for one run.
TTY mode is btop's console look: the 16-color TTY theme, stepped gradients and the tty glyph set. It turns on by itself on a real Linux console, and force_tty = true turns it on anywhere. NO_COLOR removes color entirely, and the numbers stay readable without it. Every threshold reading carries its value, so no information depends on hue alone.
Examples
examples/top.php is the VHS demo. It starts candy-top on fake data with a throwaway config path, so your own config cannot change the recording. It needs a terminal on both ends, and it exits 0 when you press q.
php examples/top.php
examples/themes.php lists the theme names candy-top can select, followed by the count. It reads only the bundled directory, so it exits 0 with the same output on every machine.
php examples/themes.php
examples/config-defaults.php prints the number of options and the defaults of a few of them. It reads the schema and never a config file.
php examples/config-defaults.php
Testing
cd candy-top && composer install && vendor/bin/phpunit
The suite drives the model with scripted messages and checks the rendered frames. Tests that need a real terminal run the binary on a pseudo-terminal, through a helper built on sugar-pty, and the bootstrap loads the sugar-testing helpers. The shipped phpunit.xml treats warnings as failures.
Troubleshooting and FAQ
"Terminal size too small"
The notice names the width and height the current layout needs. Resize the terminal, or shrink the layout: 1 to 4 hide boxes and 5 to 0 hide the GPU slots. Hiding a box also lowers the minimum.
The colors look wrong, or the graphs are plain
The terminal is being stepped down. force_tty = true selects the 16-color palette, truecolor = true asks for 24-bit color, and NO_COLOR in the environment removes color. TERM=dumb drops every color escape and the full-screen modes.
A field reads n/a
Nothing was measured yet, or the source cannot be read on this host. It is not a zero. A GPU row shows n/a when the card stops answering, and it never invents a value.
It refuses to start
candy-top --version proves that the binary runs. The startup refusals (no terminal, a non-UTF-8 locale, an unusable config path, a bad option value) all print the reason on stderr and exit non-zero before anything is drawn. A non-UTF-8 codeset is refused like btop does, and --utf-force starts anyway on a terminal that misreports its encoding.
Something btop shows is missing
Check the deliberate differences first. The README section on differences from btop lists what is not implemented yet, including the macOS and OpenBSD collectors and CPU package watts.
Where the files live
The config is in $XDG_CONFIG_HOME/candy-top/config.conf, the themes beside it, and the tree-collapse state in $XDG_STATE_HOME/candy-top/tree-state.json. candy-top keeps no log file, and log_level is accepted for btop compatibility and ignored.
Upstream mapping
candy-top follows the feature set of btop v1.4.7, plus a set of upstream pull requests that btop adopted. The README lists each adopted change. The table maps the btop parts to the classes that carry them.
| btop part | SugarCraft class |
|---|---|
| cpu box and per-core grid | Panel\Cpu\CpuView, Collect\Cpu |
| proc box, tree view and detail view | Panel\ProcPanel, Panel\Proc\ProcView, Collect\Process\* |
| GPU and NPU boxes | Collect\Gpu, Panel\Gpu\* |
| BMC (ipmi) band | Panel\Ipmi\IpmiView, Collect\Ipmi\* |
| Options and main menus | Overlay\OptionsMenu, Overlay\* |
| Config file and options | Config\ConfigFile, Config\Schema |
| Themes | Theme\ThemeRegistry, Theme\ThemeFile, Theme\Palette |
| Key bindings and help | Input\KeyTable |
Architecture
Five layers sit under the Model. Collect\* reads the host (Linux /proc and /sys, FreeBSD sysctl) and Source\* presents either the live readers or the seeded fakes. Panel\* and View\* turn samples into boxes and frames, Overlay\* draws the menus over a dimmed backdrop, and Config\*, Theme\*, State\* and Input\* hold the settings, palettes, saved state and key table. bin/candy-top parses the flags, and Cli\Help, Cli\Reporter and Cli\SelfUpdate answer the ones that run before the terminal starts, such as --help, --version and self-update.
Changelog and versioning
Releases are tagged candy-top/v*, for example candy-top/v0.1.0. Changes merged after the newest tag are dev-only until the next tag. A tagged phar stamps its tag into --version, and self-update follows the release channel the build was made for, or the one you pass with --channel. The commit history on GitHub is the change record.
Source and demos
- Source on GitHub
- Full README with the key, config and theme tables
- Runnable examples
- Test suite
- Originally inspired by btop (C++); SugarCraft is developed as a native PHP project.
Demos.
VHS-recorded GIF of the bundled demo (examples/top.php). Regenerated automatically on every push that touches the source.