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

Overview

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.

Comments
  • [feat] autocomplete for questions

    [feat] autocomplete for questions

    This PR will add autocomplete feature for ask/Question

    here's the resulting prompt:

    https://user-images.githubusercontent.com/8792274/188404964-8d521a32-3a3d-4a7d-8e54-2e99d5c886da.mp4

    opened by fabio-ivona 14
  • Add support for table tags

    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

    opened by butschster 13
  • feat: Add `setColors`

    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);
    
    opened by xiCO2k 12
  • feat: adds `live` function to create dynamic console applications

    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.
    
    opened by nunomaduro 11
  • Added code element with code highlighter.

    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

    opened by butschster 10
  • Add a `div` to render Inline type components

    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.

    opened by xiCO2k 10
  • Color is not applied on windows terminal with wsl.

    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

    opened by opuu 9
  • If there is an `\e` modifier inside a `<bg=#bada55>` it closes the background color

    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>.
    bug 
    opened by xiCO2k 9
  • Gets rid of default tags <bg=default;options=> from console output

    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</></>
    
    opened by butschster 9
  • Add display `block` Method

    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.

    opened by xiCO2k 7
  • Add text decoration hidden method

    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 ?

    opened by lakuapik 7
Releases(v1.15.0)
  • v1.15.0(Dec 20, 2022)

    What's Changed

    • [fix] Types by @fabio-ivona in https://github.com/nunomaduro/termwind/pull/158
    • [feat] autocomplete for questions by @fabio-ivona in https://github.com/nunomaduro/termwind/pull/153

    New Contributors

    • @fabio-ivona made their first contribution in https://github.com/nunomaduro/termwind/pull/158

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.14.2...v1.15.0

    Source code(tar.gz)
    Source code(zip)
  • v1.14.2(Oct 28, 2022)

    What's Changed

    • feat: Allow to use SymfonyStyle ask method if exists. by @xiCO2k in https://github.com/nunomaduro/termwind/pull/156

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.14.1...v1.14.2

    Source code(tar.gz)
    Source code(zip)
  • v1.14.1(Oct 17, 2022)

    What's Changed

    • Fix typos by @krsriq in https://github.com/nunomaduro/termwind/pull/152
    • fix: Truncate to work well with w-full or w-division. by @xiCO2k in https://github.com/nunomaduro/termwind/pull/155

    New Contributors

    • @krsriq made their first contribution in https://github.com/nunomaduro/termwind/pull/152

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.14.0...v1.14.1

    Source code(tar.gz)
    Source code(zip)
  • v1.14.0(Aug 1, 2022)

    What's Changed

    • feat: Add support for w-auto. by @xiCO2k in https://github.com/nunomaduro/termwind/pull/148
    • Remove 'orange' color by @AdamGaskins in https://github.com/nunomaduro/termwind/pull/146
    • Add full ANSI color support by @AdamGaskins in https://github.com/nunomaduro/termwind/pull/147
    • Fixes bug when using truncate with paddings by @xiCO2k in https://github.com/nunomaduro/termwind/pull/149

    New Contributors

    • @AdamGaskins made their first contribution in https://github.com/nunomaduro/termwind/pull/146

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.13.0...v1.14.0

    Source code(tar.gz)
    Source code(zip)
  • v1.13.0(Jul 1, 2022)

    What's Changed

    • fix: flex-1 with over COLUMN size content. by @xiCO2k in https://github.com/nunomaduro/termwind/pull/142
    • feat: Add min-w-{width} class. by @xiCO2k in https://github.com/nunomaduro/termwind/pull/143

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.12.0...v1.13.0

    Source code(tar.gz)
    Source code(zip)
  • v1.12.0(Jun 27, 2022)

  • v1.11.1(Jun 17, 2022)

    Fixed

    • truncate only truncates text and not the styling by @xiCO2k in (https://github.com/nunomaduro/termwind/commit/840a9e9d8809603f11d19fe5336270eb96a8d3a8)

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.11.0...v1.11.1

    Source code(tar.gz)
    Source code(zip)
  • v1.11.0(Jun 17, 2022)

    What's Changed

    • feat: Allow truncate to be used without params. by @xiCO2k in https://github.com/nunomaduro/termwind/pull/139

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.10.1...v1.11.0

    Source code(tar.gz)
    Source code(zip)
  • v1.10.1(May 12, 2022)

  • v1.10.0(May 11, 2022)

    What's Changed

    • feat: Add flex and flex-1 classes. by @xiCO2k in https://github.com/nunomaduro/termwind/pull/137
    • Add .content-repeat class by @xiCO2k in https://github.com/nunomaduro/termwind/pull/138

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.9.0...v1.10.0

    Source code(tar.gz)
    Source code(zip)
  • v1.9.0(May 3, 2022)

    Added

    • Add hidden class by @xiCO2k in https://github.com/nunomaduro/termwind/pull/134
    • Add justify-center class by @xiCO2k in https://github.com/nunomaduro/termwind/pull/135

    Fixed

    • Fixed justify-* round calculations by @xiCO2k in https://github.com/nunomaduro/termwind/pull/136
    • Fixed <br> with classes in eb2132f
    • Fixed inheritance issues on justify-* classes d050cba

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.8.0...v1.9.0

    Source code(tar.gz)
    Source code(zip)
  • v1.8.0(Apr 22, 2022)

    What's Changed

    • Feet: Add justify-around and justify-evenly classes by @xiCO2k in https://github.com/nunomaduro/termwind/pull/133

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.7.0...v1.8.0

    Source code(tar.gz)
    Source code(zip)
  • v1.7.0(Mar 30, 2022)

    What's Changed

    • fix: <hr /> width not respecting parent width. by @xiCO2k in https://github.com/nunomaduro/termwind/pull/130
    • feat: Add justify-between class. by @xiCO2k in https://github.com/nunomaduro/termwind/pull/129

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.6.2...v1.7.0

    Source code(tar.gz)
    Source code(zip)
  • v1.6.2(Mar 18, 2022)

    What's Changed

    • fix: Fixes support for HTML tags on TableCells by @xiCO2k in https://github.com/nunomaduro/termwind/pull/128

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.6.1...v1.6.2

    Source code(tar.gz)
    Source code(zip)
  • v1.6.1(Mar 17, 2022)

  • v1.6.0(Feb 24, 2022)

    What's Changed

    • Fix typo by @marcreichel in https://github.com/nunomaduro/termwind/pull/125
    • feat: Upgrade PHPStan to v1.0. by @xiCO2k in https://github.com/nunomaduro/termwind/pull/127
    • feat: Add MediaQuery Support. by @xiCO2k in https://github.com/nunomaduro/termwind/pull/126

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.5.0...v1.6.0

    Source code(tar.gz)
    Source code(zip)
  • v1.5.0(Feb 14, 2022)

    What's Changed

    • Adds Laravel TermwindServiceProvider by @xiCO2k in https://github.com/nunomaduro/termwind/pull/123

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.4.3...v1.5.0

    Source code(tar.gz)
    Source code(zip)
  • v1.4.3(Feb 3, 2022)

    What's Changed

    • fix: Fixes bug having multiple margins while using width with my by @xiCO2k in https://github.com/nunomaduro/termwind/pull/120

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.4.2...v1.4.3

    Source code(tar.gz)
    Source code(zip)
  • v1.4.2(Jan 29, 2022)

    What's Changed

    • fix: max-wwith w-{fraction} childs. by @xiCO2k in https://github.com/nunomaduro/termwind/pull/118

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.4.1...v1.4.2

    Source code(tar.gz)
    Source code(zip)
  • v1.4.1(Jan 29, 2022)

    What's Changed

    • Fixed <href> with more width that the parent element by @xiCO2k in https://github.com/nunomaduro/termwind/pull/117

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.4.0...v1.4.1

    Source code(tar.gz)
    Source code(zip)
  • v1.4.0(Jan 26, 2022)

    What's Changed

    • feat: Add support for space-y and space-x by @xiCO2k in https://github.com/nunomaduro/termwind/pull/115

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.3.0...v1.4.0

    Source code(tar.gz)
    Source code(zip)
  • v1.3.0(Jan 12, 2022)

    What's Changed

    • feat: Adds ask() method. by @xiCO2k in https://github.com/nunomaduro/termwind/pull/112
    • feat: Add max-w-{width} class. by @xiCO2k in https://github.com/nunomaduro/termwind/pull/111
    • feat: Add support for py, pt and pb. by @xiCO2k in https://github.com/nunomaduro/termwind/pull/113

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.2.0...v1.3.0

    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Dec 16, 2021)

    What's Changed

    • Fix typo in README.md by @marcreichel in https://github.com/nunomaduro/termwind/pull/106
    • feat: Add terminal()->clear() method. by @xiCO2k in https://github.com/nunomaduro/termwind/pull/107
    • Fix function_exists() checks by @mabar in https://github.com/nunomaduro/termwind/pull/108
    • Added support for HTML5 tags by @opuu in https://github.com/nunomaduro/termwind/pull/110
    • Fix bug when using emojis with w-full. (f2f426)

    New Contributors

    • @marcreichel made their first contribution in https://github.com/nunomaduro/termwind/pull/106
    • @mabar made their first contribution in https://github.com/nunomaduro/termwind/pull/108
    • @opuu made their first contribution in https://github.com/nunomaduro/termwind/pull/110

    Full Changelog: https://github.com/nunomaduro/termwind/compare/v1.1.0...v1.2.0

    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Dec 6, 2021)

  • v1.0.0(Dec 2, 2021)

Owner
Nuno Maduro
Software engineer at @laravel — working on Laravel, Forge, and Vapor. Created @pestphp, @laravel-zero, collision, larastan, php insights, and more.
Nuno Maduro
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

Happy Medium 2 Nov 12, 2021
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

Yo-An Lin 428 Dec 13, 2022
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.

Snicco 5 Oct 7, 2022
💥 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

Nuno Maduro 4.2k Jan 5, 2023
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. ??

Nuno Maduro 32 Dec 26, 2022
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

James Hall 745 Dec 30, 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

null 324 Dec 8, 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. Installation / Usage Requires PHP 8.0+ First, install Patr

Nuno Maduro 237 Nov 14, 2022
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

Erika Heidi 33 Nov 16, 2022
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.

null 8 Nov 3, 2022
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

EasyEngine 2k Jan 4, 2023
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

PHP Toolkit 23 Nov 13, 2022
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

Fernando Bevilacqua 4 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

Ben Suffolk 2 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

null 324 Dec 8, 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

Aura for PHP 102 Dec 31, 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

Christoph Hochstrasser 18 Nov 1, 2019
👨🏻‍🚀 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

Nuno Maduro 11 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.

Ivan 227 Dec 14, 2022