PHP code example of caufab / omniterm
1. Go to this page and download the library: Download caufab/omniterm library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
caufab / omniterm example snippets
use OmniTerm\HasOmniTerm;
class MyCommand extends Command
{
use HasOmniTerm;
public function handle()
{
$this->omni->success('Ready');
}
}
$this->omni->success('Task completed'); // Green GOOD badge
$this->omni->error('Something went wrong'); // Red FAIL badge
$this->omni->warning('Check your config'); // Amber WARN badge
$this->omni->info('Processing...'); // Blue INFO badge
$this->omni->disabled('Feature off'); // Gray OFF badge
$this->omni->statusSuccess('Migration Complete', 'All 42 records processed', ['Run cache:clear']);
$this->omni->statusError('Connection Failed', 'Could not reach database', ['Check .env', 'Ensure MySQL is running']);
$this->omni->tableHeader('Setting', 'Value', 'Notes');
$this->omni->tableRow('Database', 'mysql', 'Production server');
$this->omni->tableRowSuccess('Connection', 'Active');
$this->omni->tableRowError('SSL Certificate', 'Expired');
$this->omni->tableRowWarning('Memory', '85% used');
$this->omni->titleBar('My Application', 'sky');
$this->omni->roundedBox('Welcome', 'text-cyan-500', 'text-white');
$this->omni->hr();
$this->omni->hrSuccess();
$bar = $this->omni->progressBar(100)->framed()->steps();
$bar->start();
foreach ($items as $item) {
// work...
$bar->advance();
}
$bar->finish();
$this->omni->progressBar(50); // Simple bar (sky)
$this->omni->progressBar(50)->steps(); // Simple with color steps
$this->omni->progressBar(50)->framed()->color('indigo'); // Framed with custom color
$this->omni->progressBar(50)->gradient(); // Gradient (amber → emerald)
$this->omni->progressBar(50)->framed()->gradient('rose', 'sky'); // Custom gradient
use OmniTerm\Async\Spinner;
$this->omni->newLoader(Spinner::Sand);
$result = $this->omni->runTask('Processing data...', function () {
sleep(3);
return ['state' => 'success', 'message' => 'Done'];
});
$this->omni->task('Processing batch job', function () {
sleep(3);
return ['state' => 'success', 'message' => 'Batch complete', 'details' => '500 records'];
}, Spinner::DotsCircle, ['text-indigo-500', 'text-violet-500']);
$task = $this->omni->liveTask('Processing records', spinner: Spinner::Dots3)
->row('Created', 0, 'text-sky-500')
->row('Updated', 0, 'text-emerald-500')
->row('Skipped', 0, 'text-amber-500')
->row('Failed', 0, 'text-rose-500');
// Simulate 5 chunked batches
for ($batch = 0; $batch < 5; $batch++) {
$result = $task->run(function () {
usleep(800000);
return [
'created' => rand(10, 50),
'updated' => rand(5, 20),
'skipped' => rand(0, 5),
'failed' => rand(0, 2),
];
});
$task->increment('Created', $result['created']);
$task->increment('Updated', $result['updated']);
$task->increment('Skipped', $result['skipped']);
$task->increment('Failed', $result['failed']);
}
$task->finish('Processing complete');
use OmniTerm\OmniTerm;
$selected = $this->omni->browse('Server Dashboard', [
'web-01' => function (OmniTerm $omni) {
$omni->statusSuccess('Healthy', 'All checks passing');
$omni->tableHeader('Metric', 'Value');
$omni->tableRowSuccess('CPU', '23%');
$omni->tableRow('Memory', '4.2 GB / 8 GB');
},
'db-primary' => ['status' => 'running', 'cpu' => '45%', 'memory' => '28 GB / 32 GB'],
]);
// Returns selected key, or null on Esc
$name = $this->omni->ask('What is your name?');
$color = $this->omni->ask('Choose a color:', ['red', 'green', 'blue']);
$this->omni->render('<div class="flex">
<span class="bg-emerald-600 text-white font-bold px-1">PASS</span>
<span class="flex-1 text-zinc-400 px-1">Database connection verified</span>
<span class="text-zinc-600 text-right w-12">12ms</span>
</div>');
$live = $this->omni->liveView('<div>Starting...</div>');
for ($i = 1; $i <= 100; $i++) {
$live->reRender("<div>Progress: {$i}%</div>");
usleep(50000);
}
$this->omni->endLiveView();
$ansi = $this->omni->parse('<span class="text-sky-500">Hello</span>');
$width = $this->omni->terminal()->getWidth();
$height = $this->omni->terminal()->getHeight();
$this->omni->render('<div class="flex">
<span class="flex-1 bg-gradient-to-r from-indigo-800 via-purple-500 to-pink-400 text-white text-center">
Smooth gradient
</span>
</div>');
// resources/views/cli/deploy-status.blade.php
<div class="flex">
<span class="bg-{{ $color }}-600 text-white font-bold px-1">{{ $badge }}</span>
<span class="flex-1 text-zinc-400 px-1">{{ $message }}</span>
</div>
// In your command
$this->omni->view('cli.deploy-status', [
'badge' => 'DEPLOY',
'color' => 'emerald',
'message' => 'Production updated',
]);