Termwind allows you to build unique and beautiful PHP command-line applications, using the Tailwind CSS API. In short, it's like Tailwind CSS, but for the PHP command-line applications.
Requires PHP 8.0+
Require Termwind using Composer:
composer require nunomaduro/termwind
use function Termwind\{render};
// single line html...
render('<div class="p-1 bg-green-300">Termwind</div>');
// multi-line html...
render(<<<'HTML'
<div>
<div class="p-1 bg-green-300">Termwind</div>
<em class="ml-1">
Give your CLI apps a unique look
</em>
</div>
HTML);
// Laravel or Symfony console commands...
class UsersCommand extends Command
{
public function handle()
{
render(
view('users.index', [
'users' => User::all()
])
);
}
}
The style()
function may be used to add own custom syles.
use function Termwind\{style};
style('btn')->apply('p-4 bg-blue text-color-white');
render('<div class="btn">Click me</div>');
Head over to tailwindcss.com/docs, and choose a class that is not implemented in Termwind. As an example, let's assume you would like to add the lowercase
Tailwind CSS class to Termwind:
- Head over to
src/Components/Element
and add a new method with the namelowercase
:
/**
* Makes the element's content lowercase.
*/
final public function lowercase(): static
{
$content = mb_strtolower($this->content, 'UTF-8');
return new static($this->output, $content, $this->properties);
}
- Next, add a new test in
tests/classes.php
to see if thelowercase
class works as expected:
test('lowercase', function () {
$html = parse('<div class="lowercase">tEXT</div>');
expect($html)->toBe('<bg=default;options=>text</>');
});
- Pull request the code, and that's it.
Termwind is an open-sourced software licensed under the MIT license.