🍃Termwind allows you to build unique and beautiful PHP command-line applications, using the Tailwind CSS API

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 powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast! Condensed in a single ~65KB file

Bong Cosca 2.6k Dec 30, 2022
TrailLamp is a lightweight, easy-to-use Php MVC framework that can be used to build web applications and REST APIs.

TrailLamp Introduction TrailLamp is a lightweight, easy-to-use Php MVC framework that can be used to build web applications and REST APIs. Installatio

Etorojah Okon 14 Jun 10, 2022
A Small modular PHP framework Build for web applications

MagmaCore__ This project is in active development. So is evolving constantly. As soon project gets to stable point. Due notice will be given Composer

Ricardo Miller 10 Sep 2, 2022
Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.

Slim Framework Slim is a PHP micro-framework that helps you quickly write simple yet powerful web applications and APIs. Installation It's recommended

Slim Framework 11.5k Jan 4, 2023
This Slim Framework middleware will compile LESS CSS files on-the-fly using the Assetic library

This Slim Framework middleware will compile LESS CSS files on-the-fly using the Assetic library. It supports minification and caching, also via Asseti

Gerard Sychay 22 Mar 31, 2020
Asynchronous server-side framework for network applications implemented in PHP using libevent

phpDaemon https://github.com/kakserpom/phpdaemon Asynchronous framework in PHP. It has a huge number of features. Designed for highload. Each worker i

Vasily Zorin 1.5k Nov 30, 2022
Silex Skeleton - a fully-functional Silex application that you can use as the skeleton for your new applications

Silex Skeleton - a fully-functional Silex application that you can use as the skeleton for your new applications

Silex 789 Dec 5, 2022
FlyCubePHP is an MVC Web Framework developed in PHP and repeating the ideology and principles of building WEB applications, embedded in Ruby on Rails.

FlyCubePHP FlyCubePHP is an MVC Web Framework developed in PHP and repeating the ideology and principles of building WEB applications, embedded in Rub

Anton 1 Dec 21, 2021
A sample CakePHP api application using CakeDC/cakephp-api and swoole as server

CakePHP Application Skeleton composer create-project --prefer-dist cakephp/app Added sample data using https://github.com/annexare/Countries Created m

Marcelo Rocha 3 Jul 28, 2022
PPM is a process manager, supercharger and load balancer for modern PHP applications.

PPM - PHP Process Manager PHP-PM is a process manager, supercharger and load balancer for PHP applications. It's based on ReactPHP and works best with

PPM - PHP Process Manager 6.5k Dec 27, 2022
Mind is the PHP code framework designed for developers. It offers a variety of solutions for creating design patterns, applications and code frameworks.

Mind Mind is the PHP code framework designed for developers. It offers a variety of solutions for creating design patterns, applications and code fram

null 0 Dec 13, 2021
Woski is a fast and simple lightweight PHP Framework for building applications in the realm of the web.

Woski is a simple fast PHP framework for the Realm The Project Installation Clone the repository $ composer create-project clintonnzedimma/woski myApp

Clinton Nzedimma 19 Aug 15, 2022
This component may look complex, weird and full of hacks but it is a game changer for how we run PHP applications.

PHP Runtimes In early 2021, Symfony created a "Runtime component". This component may look complex, weird and full of hacks but it is a game changer f

Runtime 321 Dec 25, 2022
Simple and universal connection pool for ReactPHP applications.

szado/reactphp-connection-pool Async and flexible pool for any type of connections built on top of ReactPHP. Connection pooling allows you to easily m

shado 2 Apr 30, 2022
Framework X – the simple and fast micro framework for building reactive web applications that run anywhere.

Framework X Framework X – the simple and fast micro framework for building reactive web applications that run anywhere. Quickstart Documentation Tests

Christian Lück 620 Jan 7, 2023
LODSPeaKr is a framework for creating Linked Data applications in a simple and easy way

LODSPeaKr is a framework for creating Linked Data applications in a simple and easy way. You can see several applications created using LODSPeaKr.

Alvaro Graves 31 Jun 23, 2020
Asynchronous & Fault-tolerant PHP Framework for Distributed Applications.

Kraken PHP Framework ~ Release the Kraken! Note: This repository contains the core of the Kraken Framework. If you want to start developing new applic

Kraken 1.1k Dec 27, 2022
Biny is a tiny, high-performance PHP framework for web applications

Biny is high performance. Framework comes default with response time of less than 1ms. Stand-alone QPS easily up to 3000.

Tencent 1.7k Dec 9, 2022