🍃 In short, it's like Tailwind CSS, but for the PHP command-line applications.

Last update: May 27, 2022

Termwind logo

Termwind

TailCli example

GitHub Workflow Status (master) Total Downloads Latest Version License


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.

Installation & Usage

Requires PHP 8.0+

Require Termwind using Composer:

composer require nunomaduro/termwind --dev

Get Started

use function Termwind\{line, render};

// Render one line...
line($message)->uppercase()->pl2()->pr2()->fontBold()->textColor('white')->bg('blue')->render();

// Render multiple lines...
render([
    line(),
    line()->width(20)->bg('red'),
    line(),
]);

TODO...

Termwind is an open-sourced software licensed under the MIT license.

GitHub

https://github.com/nunomaduro/termwind
Comments
  • 1. Add support for table tags

    render(<<<'HTML'
    <table style="box-double">
        <thead title="Books" class="bg-red text-color-white px-10">
            <tr>
                <th align="right">ISBN</th>
                <th>Title</th>
                <th>Author</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <th align="right">99921-58-10-7</th>
                <td>Divine Comedy</td>
                <td align="right">Dante Alighieri</td>
            </tr>
            <tr border="1">
                <th class="bg-blue text-color-red" align="right">9971-5-0210-0</th>
                <td>A Tale of Two Cities</td>
                <td align="right">Charles Dickens</td>
            </tr>
            <tr>
                <th align="right">960-425-059-0</th>
                <td>The Lord of the Rings</td>
                <td align="right">J. R. R. Tolkien</td>
            </tr>
            <tr>
                <th align="right">80-902734-1-6</th>
                <td>And Then There Were None</td>
                <td rowspan="2" align="right">Dante Alighieri\nspans multiple rows</td>
            </tr>
            <tr>
                <th align="right">978-052156781</th>
                <td>De Monarchia</td>
            </tr>
        </tbody>
        <tfoot title="Page 1/2" class="mx-5 bg-blue">
            <tr>
                <th colspan="3">This value spans 3 columns.</th>
            </tr>
        </tfoot>
    </table>
    HTML);
    

    Will render table

    Reviewed by butschster at 2021-10-13 20:12
  • 2. feat: Add `setColors`

    This PR adds the capability to overwrite existent colors or create new colors.

    Usage:

    use function Termwind\{render, setColors};
    
    setColors([
        'blue-300' => '#0133dc',
        'badass' => '#bada55',
    ]);
    
    render(<<<'HTML'
        <div class="my-1">
            <div class="bg-blue-300">
                Termwind now supports <b>`setColors()`</b>
            </div>
            <div class="mt-1 bg-badass text-black">
                Can be used like this: <b>`setColors(['badass' => '#bada55'])`</b>
            </div>
        </div>
    HTML);
    
    Reviewed by xiCO2k at 2021-11-10 13:32
  • 3. Added code element with code highlighter.

    I decided not to use code from nunomaduro/collision package and copied Code Highlighter with some modifications.

    1. I got rid of ConsoleColor class and used css classes for syntax highlighting
    2. Replaced $linesBefore, $linesAfter with $startLine
    <code line="20" start-line="14">
        &lt;?php
    
        /** @test */
        function sentryReport()
        {
            try {
                throw new \Exception('Something went wrong');
            } catch (\Throwable $e) {
                report($e);
            }
        }
    </code>
    

    !!! Users have to convert all applicable characters to HTML entities inside code element !!!

    Will render

    image

    fixes #82

    Reviewed by butschster at 2021-10-26 18:32
  • 4. Add a `div` to render Inline type components

    After checking on possible features to add, figured that would be awesome to have the capability to style multiple parts of the same span like its possible to do in HTML with multiple <span> inside of each other.

    From this code:

    
    use function Termwind\{span,a};
    
    span([
        span('Termind', 'ml-3 px-1 font-bold text-color-white bg-red'),
        span('it\'s like Tailwind CSS, but for the PHP command-line applications.', 'px-1'),
        a('Check it out on GitHub', 'mr-3 text-color-blue')->href('https://github.com/nunomaduro/termwind'),
    ])->render();
    
    

    Output

    image

    There is some edge cases still need to be handle. but want to know what do you think about this.

    Reviewed by xiCO2k at 2021-10-04 23:25
  • 5. Color is not applied on windows terminal with wsl.

    Default colors are not being applied to html element on windows terminal (using windows sub system for linux). Also the parser trying to parse special characters as html, in this case <== gives an warning.

    require __DIR__ . '/vendor/autoload.php';
    
    use function Termwind\{render};
    
    // single line html...
    render('<div class="p-1 bg-green-300">Termwind</div><span class="text-red-200"><== this was supposed to be green.<span>');
    

    Output

    image

    Reviewed by opuu at 2021-12-09 16:46
  • 6. Gets rid of default tags from console output

    One of the reason I decided to get rid of default tags is in this example

    <div class="bg-red">Hello <strong>world></div>
    

    When it parsed it looks like

    <bg=red;options=>Hello <bg=default;options=bold>world</></>
    

    As you noticed the word world has default background because of bg=default instead of red background.

    There are a lot of unnecessary style tags in output :)

    <br/> => <bg=default;options=></>\n
    <a>link text</a> => <bg=default;options=>link text</>
    <ol><li>list text 1</li></ol> => <bg=default;options=><bg=default;options=>1. list text 1</></>
    
    Reviewed by butschster at 2021-10-15 08:23
  • 7. Add display `block` Method

    This pull request will fix #58 and add a new display: block option to add to any component.

    Also by default div, ul and li elements will have block as default.

    Reviewed by xiCO2k at 2021-10-14 23:30
  • 8. Add text decoration hidden method

    This PR adds hidden method for text decoration. It will make the text invisible when applied.

    span('i am invisible with blue background color', 'hidden bg-blue')->render();
    

    I do not know if this will be useful or not, but it is part of ANSI Escape Codes. Also there are reverse, dim and blink which is not yet added to this package.

    Feel free to drop or accept this, cheers :beers:


    Apart from this PR, i also have some idea about this package:

    1. What if there is helper function called console which return the current renderer of termwind. It will be useful when we need the symfony console output directly.
    // print an error
    console()->writeln('<error>An error occured</error>');
    
    1. What if there is conditional rendering, using something like:
    span('i am on linux machine')->renderWhen(PHP_OS_FAMILY  == 'Linux');
    span('i am on macos machine')->renderWhen(PHP_OS_FAMILY  == 'Darwin');
    span('i am on windows machine')->renderWhen(PHP_OS_FAMILY  == 'Windows');
    
    1. Does this package going to achieve same goal as rich python package? link: https://github.com/willmcgugan/rich

    What do you think @nunomaduro ?

    Reviewed by lakuapik at 2021-10-08 13:13
  • 9. [Feature] Style inheritance

    I split Element class into Element and Styles

    Now Styles object is responsible for the element styles. It accumulates rules, text modifiers and style modifiers, then Element passes a text string into this object and it applies at first text modifiers, then style modifiers and finally adds style tags.

    This PR fixes #53 issue

    Reviewed by butschster at 2021-11-19 00:10
  • 10. Refactor font-bold and underline

    To avoid interfering with the prepend(), changed the classes font-bold and underline

    Code

    render(<<<'HTML'
        <div class="my-1">
            <span>For text on 🍃 Termwind we support:</span>
            <ul class="mt-2">
                <li class="font-bold text-color-white">
                    Font Bold
                </li>
                <li class="italic text-color-white">
                    Italic
                </li>
                <li class="underline text-color-white">
                    Underline
                </li>
                <li class="line-through text-color-white">
                    Line Through
                </li>
                <li class="font-bold italic text-color-white underline line-through">
                    All Together
                </li>
            </ul>
        </div>
    HTML);
    

    Before

    image

    After

    image

    Reviewed by xiCO2k at 2021-10-13 14:10
  • 11. feat: Adds ability to use styles for pre element

    We can try to add styles for every line inside pre element

    <pre class="bg-blue text-red font-bold">
        <h1>Introduction</h1>
    
        <div>The body of your message.</div>
    
        Thanks,
        Laravel
    
        © 2021 Laravel. All rights reserved.
    </pre>
    

    There is a problem with line width. If I didn't pay attention to the line width, I got something like this

    image

    Then I decided to get width for the longest line in a html and apply str_pad function to every line.

    image

    fixed #91

    Reviewed by butschster at 2021-10-30 21:20
  • 12. feat: adds `live` function to create dynamic console applications

    This pull request allows to make a particular section of the console dynamic. Here is an example:

    use function Termwind\{live};
    
    live(function () {
        static $counter = 0;
    
        $counter++;
    
        return '<div class="m-1">
            <span class="pl-1 pr-2 bg-blue-300">My counter</span>
            <span class="ml-1">' . $counter . '</span>
        </div>';
    })->refreshEvery(seconds: 1);
    

    Will render the following: live

    In addition, you may control when the refresh should stop, by calling the RefreshEvent::stop method.

    live(function (RefreshEvent $event) {
        return $event->stop();
    })->refreshEvery(seconds: 1);
    

    Finally, if you wish to control, when to render, clear, or refresh, you may control the flow using these methods:

    use function Termwind\{live};
    
    $live = live(fn () => 'html');
    
    $live->render(); // Re-runs the given closure, and renders its output.
    $live->clear(); // Removes all previous rendered html.
    $live->refresh(); // Refreshes the previous rendered html.
    $live->refreshEvery($seconds); // Refreshes the previous rendered html, every X amount of seconds.
    
    Reviewed by nunomaduro at 2021-12-04 01:52
  • 13. If there is an `\e` modifier inside a `` it closes the background color

    Code:

    render(<<<'HTML'
        <div class="my-1 ml-3 px-2 bg-green-300 text-black">
            🍃 Termwind now have the capability to <b>extend</b> colors!
        </div>
    HTML);
    

    Result:

    image

    Posible Solution:

    • Change <bg> to and \e code
    • Or, find if there is any way to only remove the escape code added from <b>.
    Reviewed by xiCO2k at 2021-11-15 12:15
  • 14. [Feature] Ability to extend HTML renderer

    There is only one way to increase amount of elements in termwind - Add PRs with new features.

    But sometimes requires an ability to extend HtmlRenderer for specific project.

    Something like this

    HtmlRenderer::extend('code', static function(\DOMNode $node): Raw {
        $highlighter = new Highlighter();
    
        $line = (int) $node->getAttribute('line');
    
        $html = array_reduce(
            iterator_to_array($node->childNodes),
            static fn(string $html, \DOMNode $child) => $html .= $child->ownerDocument->saveXML($child),
            ''
        );
    
        $html = html_entity_decode($html);
    
        return Termwind::raw(
            $highlighter->highlight(html_entity_decode($html), $line)
        );
    });
    

    As you understood, this package fits me on 100%. I have a pet project where one of the features is rendering debug output into a terminal and I have a lot of legacy code I'm trying to move to this package.

    Reviewed by butschster at 2021-10-25 17:54
A powerful command line application framework for PHP. It's an extensible, flexible component, You can build your command-based application in seconds!
A powerful command line application framework for PHP. It's an extensible, flexible component, You can build your command-based application in seconds!

CLIFramework CLIFramework is a command-line application framework, for building flexiable, simple command-line applications. Commands and Subcommands

May 17, 2022
A PHP Command Line tool that makes it easy to compile, concat, and minify front-end Javascript and CSS/SCSS dependencies.

Front End Compiler A PHP Command Line tool that makes it easy to compile, concat, and minify front-end Javascript and CSS/SCSS dependencies. The minif

Nov 12, 2021
BetterWPCLI - a small, zero-dependencies, PHP library that helps you build enterprise WordPress command-line applications.
BetterWPCLI - a small, zero-dependencies, PHP library that helps you build enterprise WordPress command-line applications.

BetterWPCLI - a small, zero-dependencies, PHP library that helps you build enterprise WordPress command-line applications.

May 3, 2022
💥 Collision is a beautiful error reporting tool for command-line applications
💥 Collision is a beautiful error reporting tool for command-line applications

Collision was created by, and is maintained by Nuno Maduro, and is a package designed to give you beautiful error reporting when interacting with your

May 26, 2022
PHP Interminal is a command-line tool that gives you access to PHP Internals discussions in your terminal.
PHP Interminal is a command-line tool that gives you access to PHP Internals discussions in your terminal.

PHP Interminal is a command-line tool that gives you access to PHP Internals discussions in your terminal. ??

Dec 12, 2021
Lovely PHP wrapper for using the command-line

ShellWrap What is it? It's a beautiful way to use powerful Linux/Unix tools in PHP. Easily and logically pipe commands together, capture errors as PHP

May 3, 2022
A PHP library for command-line argument processing

GetOpt.PHP GetOpt.PHP is a library for command-line argument processing. It supports PHP version 5.4 and above. Releases For an overview of the releas

May 24, 2022
Patrol is an elegant command-line tool that keeps your PHP Project's dependencies in check.
Patrol is an elegant command-line tool that keeps your PHP Project's dependencies in check.

Patrol is an elegant command-line tool that keeps your PHP Project's dependencies in check. Installation / Usage Requires PHP 8.0+ First, install Patr

May 6, 2022
Twitter raffles in the command line, with PHP and minicli
Twitter raffles in the command line, with PHP and minicli

Rafflebird Rafflebird is a highly experimental CLI application for giveaways / raffles on Twitter, built in PHP with Minicli. Disclaimer: The recent s

May 14, 2022
A PHP command line tool used to install shlink
A PHP command line tool used to install shlink

Shlink installer A PHP command line tool used to install shlink. Installation Install this tool using composer.

Jan 10, 2022
Command-line control panel for Nginx Server to manage WordPress sites running on Nginx, PHP, MySQL, and Let's Encrypt
Command-line control panel for Nginx Server to manage WordPress sites running on Nginx, PHP, MySQL, and Let's Encrypt

EasyEngine v4 EasyEngine makes it greatly easy to manage nginx, a fast web-server software that consumes little memory when handling increasing volume

May 22, 2022
Generic PHP command line flags parse library
Generic PHP command line flags parse library

PHP Flag Generic PHP command line flags parse library Features Generic CLI options and arguments parser. Support set value data type(int,string,bool,a

Mar 2, 2022
A simple command-line tool whose aim is to facilitate the continous delivery of PHP apps
A simple command-line tool whose aim is to facilitate the continous delivery of PHP apps

Deployer Simple command-line tool that aims to facilitate the continous delivery of PHP apps, particularly Laravel apps. Imagine you want to update yo

Sep 8, 2021
php command line script to DCA crypto from Coinbase Pro

dca.php A simple php script designed to be run via the command line via a cron job. This will connect to coinbase pro and buy the crypto coins specifi

Oct 22, 2021
A PHP library for command-line argument processing

GetOpt.PHP GetOpt.PHP is a library for command-line argument processing. It supports PHP version 7.1 and above. Releases For an overview of the releas

May 20, 2022
Command-Line Interface tools

Aura.Cli Provides the equivalent of request ( Context ) and response ( Stdio ) objects for the command line interface, including Getopt support, and a

May 6, 2022
Another Command Line Argument Parser

Optparse — Another Command Line Argument Parser Install 1. Get composer. 2. Put this into your local composer.json: { "require": { "chh/optparse

Nov 1, 2019
👨🏻‍🚀 A command-line tool that gives you the Alpine Day 2021 schedule in your timezone. 🚀
👨🏻‍🚀 A command-line tool that gives you the Alpine Day 2021 schedule in your timezone. 🚀

Alpine Day Schedule a command-line tool that gives you the Alpine Day 2021 schedule in your timezone. ?? Quick start Requires PHP 7.4+ # First, instal

Jun 10, 2021
A command line code generator for Drupal.

Drupal Code Generator A command line code generator for Drupal. Installation Download the latest stable release of the code generator.

May 20, 2022