At 8:07, the morning import has accepted 214 information and rejected three. The month-to-month report remains to be working. The e-mail job has failed after a second try. All three updates are within the terminal, someplace between connection messages and debug output. The developer on name has one query: what wants consideration now?
Logs can let you know what occurred and in what order. Answering the developer’s query requires a distinct view of the identical work. An import that completed with rejected information may have a follow-up. A report that has been working for 2 minutes could also be high quality. An e-mail job that simply failed could matter greater than both. A helpful dashboard places these states collectively and lets the operator resolve the place to look first.
That’s the drawback we’re taking to PHP TUI within the first installment of PHP Venture Radar. The undertaking grew out of a PHP port of Ratatui, a Rust library for terminal interfaces. It offers widgets for tables, lists, gauges, charts, and tabs, plus structure instruments for becoming these items right into a terminal window. If the appliance and its operational instructions already reside in PHP, the dashboard can use the identical language and software companies.
Resolve what the primary display screen must say
Begin with a listing of jobs and the most recent significant state for every one. The display screen ought to let you know which job failed, which one remains to be working, and what a accomplished job truly achieved. The distinction between DONE and 214 accepted, 3 rejected issues. The primary describes the execution. The second tells the operator that three information should want consideration.
The identical distinction applies to progress. A gauge is smart when the appliance is aware of how a lot work there’s and the way a lot it has accomplished. If the reporting job has no dependable whole, present its present section or the time of its final replace. A progress bar that sits at 80 % whereas the method waits on a distant service offers the operator little or no to behave on.
Draw a dashboard with three pattern jobs
Set up the package deal with Composer in a brand new listing. The primary model attracts a single body utilizing mounted knowledge. That retains the structure straightforward to alter when you work out what belongs on display screen.
composer require php-tui/php-tui
Save the next as jobs.php and run php jobs.php in a terminal. DisplayBuilder creates the show, and ParagraphWidget renders the textual content we cross to it.
<?php
declare(strict_types=1);
use PhpTuiTuiDisplayBuilder;
use PhpTuiTuiExtensionCoreWidgetParagraphWidget;
use PhpTuiTuiTextText;
require __DIR__ . '/vendor/autoload.php';
$jobs = [
['Import', 'DONE', '214 accepted, 3 rejected'],
['Report', 'RUNNING', 'Rendering monthly summary'],
['Email', 'FAILED', 'Provider timed out on attempt 2'],
];
$strains = ['JOB STATUS', ''];
foreach ($jobs as [$name, $status, $detail]) {
$strains[] = sprintf('%-8s %-8s %s', $identify, $standing, $element);
}
$show = DisplayBuilder::default()->construct();
$display->clear();
$display->draw(
ParagraphWidget::fromText(
Textual content::fromString(implode("n", $strains))
)
);
The instance retains the three rows in a single widget. That is sufficient to reply a number of design questions. Are you able to learn the standing at a look? Does the display screen nonetheless make sense with out colour? What will get minimize off once you cut up the terminal window? The padded strings even have a restrict. If job names can include accented textual content, extensive characters, or user-supplied labels, take a look at how these names align on display screen earlier than counting on fixed-width formatting.
Give the overview and the small print completely different jobs
The overview ought to keep brief even when the final error is lengthy. In a wider terminal, put the job listing on the left and the chosen job on the suitable. The element panel can present the final try, the time it began, and a brief rationalization of the failure. In a slim terminal, hold the listing seen and let the operator open the element view with Enter.
PHP TUI’s occasion information exhibits easy methods to learn key occasions by way of the PHP-Time period terminal object. For a primary interactive model, up and down can transfer the choice, Enter can open the small print, and Escape can return to the overview. Retailer the chosen job’s ID. If a brand new failure strikes to the highest throughout a refresh, the operator ought to hold wanting on the job they selected. If that job has disappeared, return to the listing and clarify what modified.
Make stale knowledge seen
As soon as the dashboard begins studying reside knowledge, an important timestamp stands out as the time of the final profitable refresh. Think about the report remains to be labelled RUNNING when the connection to the database drops. The appliance might need completed the report, however the dashboard has misplaced the power to inform. Hold the final good snapshot seen, mark it as stale, and present when it was collected. The operator can then distinguish an outdated statement from a present state.
Hold the information fetch separate from rendering. A key press ought to transfer the choice with out asking the database for an additional snapshot. Begin with a guide refresh and a timestamp. If operators want automated updates, add polling on a separate interval and put a timeout on every request. Check what occurs when the database is gradual, unavailable, or quickly returns an empty listing. Every situation tells the operator one thing completely different.
An inspection instrument can earn its place earlier than it might retry a job
An e-mail timeout is an effective instance of why inspection comes first. The supplier could have accepted the e-mail earlier than the connection timed out. From the employee’s perspective, the end result is unsure. A retry button would flip that uncertainty into an operational resolution. If you happen to add one, present the job ID and the final recognized consequence, then name the identical retry service your software already makes use of. The dashboard can show whether or not the service accepted the request and refresh when the subsequent try turns into seen.
There may be additionally a smaller element that impacts whether or not folks belief the instrument. If an interactive model adjustments terminal settings or switches to an alternate display screen, restore the unique settings on exit. Check the traditional stop key, Ctrl+C, and a failed refresh. A helpful dashboard ought to depart the shell prepared for the operator’s subsequent command.
The Radar verdict
I might attempt PHP TUI on a workflow that already has an operator within the terminal. Import monitoring, a queue inspector, and a deployment guidelines are good candidates as a result of every offers the individual watching a subsequent motion. For a scheduled job or a command utilized in shell pipelines, I might hold the prevailing textual content or JSON output obtainable. For a shared instrument, I might examine the terminal environments the group makes use of, particularly on Home windows, which the undertaking README flags as a limitation.
Give somebody the dashboard whereas an import is working and ask them to seek out the primary job that wants consideration. Then ask them to seek out the identical info within the logs. Watch the place they hesitate and what they open subsequent. That may let you know whether or not the subsequent characteristic must be a element panel, a greater standing label, or just a hyperlink again to the related log entry.
PHP TUI on GitHub · Documentation and official demo · Keyboard and terminal occasions · Composer package deal


