News

Build Terminal UIs in PHP With ANSI Kit

Published
Build Terminal UIs in PHP With ANSI Kit image

AnsiKit is a zero-dependency ANSI escape helper for building terminal UIs in PHP. It features a chainable API for styles, color, and cursor control, along with useful components and utilities:

Here's a quick example of using the input component with a confirmation, and rendering a table using the package's table component (the examples folder has more complete examples):

use Ajaxray\AnsiKit\AnsiTerminal;
use Ajaxray\AnsiKit\Components\Table;
use Ajaxray\AnsiKit\Support\Input;
 
$t = new AnsiTerminal();
$t->clearScreen()->cursorHome();
 
// Single-line input
$name = Input::line('What is your name? [Anonymous] ', 'Anonymous');
$t->writeStyled("Hello, {$name}!\n", [AnsiTerminal::TEXT_BOLD, AnsiTerminal::FG_GREEN]);
 
// Confirmation
$proceed = Input::confirm('Do you want to enter a short bio?', true);
if (!$proceed) {
$t->writeStyled("Okay, skipping bio.\n", [AnsiTerminal::FG_YELLOW]);
exit(0);
}
 
// Example of the Table component
(new Table())
->setHeaders('Name','Age')
->addRow('Ada', '36')
->addRow('Linus', '54')
->render();

AnsiKit features the following components and helpers to help you build UIs on the command line:

  • Table component
  • Banner component
  • Progressbar component
  • Spinner component
  • Choice component
  • Keypress helper
  • Input helper
  • And more...

💻 You can get started with AnsiKit on GitHub: ajaxray/AnsiKit

📕 The GitHub repo has an examples folder: examples

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Filed in

Sponsored

masteringlaravel logo
Laravel Code Review

Get expert guidance in a few days with a Laravel code review

Visit Laravel Code Review

The latest

View all →
Image Dominant Color and HEIC Support in Laravel 13.24 image

Image Dominant Color and HEIC Support in Laravel 13.24

Read article
Official Laravel Zed Extension: LSP for PHP & Blade image

Official Laravel Zed Extension: LSP for PHP & Blade

Read article
Laravel Head: Manage Meta Tags, Open Graph, and JSON-LD image

Laravel Head: Manage Meta Tags, Open Graph, and JSON-LD

Read article
PhpStorm 2026.2 Released image

PhpStorm 2026.2 Released

Read article
Laravel Doctor: Diagnose Your App With One Artisan Command image

Laravel Doctor: Diagnose Your App With One Artisan Command

Read article
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article