Termwind, created by nunomaduro, is a unique tool that helps developers build distinctive PHP command-line applications. It borrows from the Tailwind CSS API, bringing into play the aesthetics and usability known in website design to the console. In essence, Termwind is like having Tailwind CSS but in your PHP console applications - think of it as styling for your console commands.
Implementing Termwind in your project is easy and straightforward. First, you need to install the package using Composer with the following command:
composer require nunomaduro/termwind
Please note that Termwind requires PHP 8.0 or higher. Once installed, you can use Termwind by rendering HTML strings in your PHP files:
use function Termwind\{render};
// Rendering a simple single line
render('<div class="px-1 bg-green-300">Termwind</div>');
// Rendering multi-line HTML
render(<<<'HTML'
<div>
<div class="px-1 bg-green-600">Termwind</div>
<em class="ml-1">
Give your CLI apps a unique look
</em>
</div>
HTML);
One of the powerful features of Termwind is its compatibility with typical PHP frameworks like Laravel or Symfony:
class UsersCommand extends Command
{
public function handle()
{
render(
view('users.index', [
'users' => User::all()
])
);
}
}
You're also allowed to prompt users with the help of the ask()
function:
use function Termwind\{ask};
$answer = ask(<<<HTML
<span class="mt-1 ml-2 mr-1 bg-green px-1 text-black">
What is your name?
</span>
HTML);
For more usage examples, functions, and supported HTML elements, please visit the official repository of nunomaduro/termwind on GitHub. All the classes supported follow the same logic that is available on the Tailwind CSS documentation. Furthermore, Termwind also supports Responsive Design just like Tailwind CSS. You can find all of this information and more in the comprehensive guide that has been made available in the repository's README file, accessible via the following URL: https://github.com/nunomaduro/termwind.