• Stars
    star
    2,151
  • Rank 20,527 (Top 0.5 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 2 years ago
  • Updated 12 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸƒ In short, it's like Tailwind CSS, but for the PHP command-line applications.

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

Requires PHP 8.0+

Require Termwind using Composer:

composer require nunomaduro/termwind

Usage

use function Termwind\{render};

// single line html...
render('<div class="px-1 bg-green-300">Termwind</div>');

// 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);

// Laravel or Symfony console commands...
class UsersCommand extends Command
{
    public function handle()
    {
        render(
            view('users.index', [
                'users' => User::all()
            ])
        );
    }
}

style()

The style() function may be used to add own custom styles and also update colors.

use function Termwind\{style};

style('green-300')->color('#bada55');
style('btn')->apply('p-4 bg-green-300 text-white');

render('<div class="btn">Click me</div>');

ask()

The ask() function may be used to prompt the user with a question.

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);

The return provided from the ask method will be the answer provided from the user.

terminal()

The terminal() function returns an instance of the Terminal class, with the following methods:

  • ->width(): Returns the full width of the terminal.
  • ->height(): Returns the full height of the terminal.
  • ->clear(): It clears the terminal screen.

Classes Supported

All the classes supported use exactly the same logic that is available on tailwindcss.com/docs.

Responsive Design

Like TailwindCSS we also support Responsive Design media queries and this are the breakpoints supported:

  • sm: 64 spaces (640px)
  • md: 76 spaces (768px)
  • lg: 102 spaces (1024px)
  • xl: 128 spaces (1280px)
  • 2xl: 153 spaces (1536px)
render(<<<'HTML'
    <div class="bg-blue-500 sm:bg-red-600">
        If bg is blue is sm, if red > than sm breakpoint.
    </div>
HTML);

All the sizes for the CLI are based on Font Size 15.

HTML Elements Supported

All the elements have the capability to use the class attribute.

<div>

The <div> element can be used as a block type element.

Default Styles: block

render(<<<'HTML'
    <div>This is a div element.</div>
HTML);

<p>

The <p> element can be used as a paragraph.

Default Styles: block

render(<<<'HTML'
    <p>This is a paragraph.</p>
HTML);

<span>

The <span> element can be used as an inline text container.

render(<<<'HTML'
    <p>
        This is a CLI app built with <span class="text-green-300">Termwind</span>.
    </p>
HTML);

<a>

The <a> element can be used as a hyperlink. It allows to use the href attribute to open the link when clicked.

render(<<<'HTML'
    <p>
        This is a CLI app built with Termwind. <a href="/">Click here to open</a>
    </p>
HTML);

<b> and <strong>

The <b>and <strong> elements can be used to mark the text as bold.

Default Styles: font-bold

render(<<<'HTML'
    <p>
        This is a CLI app built with <b>Termwind</b>.
    </p>
HTML);

<i> and <em>

The <i> and <em> elements can be used to mark the text as italic.

Default Styles: italic

render(<<<'HTML'
    <p>
        This is a CLI app built with <i>Termwind</i>.
    </p>
HTML);

<s>

The <s> element can be used to add a line through the text.

Default Styles: line-through

render(<<<'HTML'
    <p>
        This is a CLI app built with <s>Termwind</s>.
    </p>
HTML);

<br>

The <br> element can be used to do a line break.

render(<<<'HTML'
    <p>
        This is a CLI <br>
        app built with Termwind.
    </p>
HTML);

<ul>

The <ul> element can be used for an unordered list. It can only accept <li> elements as childs, if there is another element provided it will throw an InvalidChild exception.

Default Styles: block, list-disc

render(<<<'HTML'
    <ul>
        <li>Item 1</li>
        <li>Item 2</li>
    </ul>
HTML);

<ol>

The <ol> element can be used for an ordered list. It can only accept <li> elements as childs, if there is another element provided it will throw an InvalidChild exception.

Default Styles: block, list-decimal

render(<<<'HTML'
    <ol>
        <li>Item 1</li>
        <li>Item 2</li>
    </ol>
HTML);

<li>

The <li> element can be used as a list item. It should only be used as a child of <ul> and <ol> elements.

Default Styles: block, list-decimal

render(<<<'HTML'
    <ul>
        <li>Item 1</li>
    </ul>
HTML);

<dl>

The <dl> element can be used for a description list. It can only accept <dt> or <dd> elements as childs, if there is another element provided it will throw an InvalidChild exception.

Default Styles: block

render(<<<'HTML'
    <dl>
        <dt>πŸƒ Termwind</dt>
        <dd>Give your CLI apps a unique look</dd>
    </dl>
HTML);

<dt>

The <dt> element can be used as a description title. It should only be used as a child of <dl> elements.

Default Styles: block, font-bold

render(<<<'HTML'
    <dl>
        <dt>πŸƒ Termwind</dt>
    </dl>
HTML);

<dd>

The <dd> element can be used as a description title. It should only be used as a child of <dl> elements.

Default Styles: block, ml-4

render(<<<'HTML'
    <dl>
        <dd>Give your CLI apps a unique look</dd>
    </dl>
HTML);

<hr>

The <hr> element can be used as a horizontal line.

render(<<<'HTML'
    <div>
        <div>πŸƒ Termwind</div>
        <hr>
        <p>Give your CLI apps a unique look</p>
    </div>
HTML);

<table>

The <table> element can have columns and rows.

render(<<<'HTML'
    <table>
        <thead>
            <tr>
                <th>Task</th>
                <th>Status</th>
            </tr>
        </thead>
        <tr>
            <th>Termwind</th>
            <td>βœ“ Done</td>
        </tr>
    </table>
HTML);

<pre>

The <pre> element can be used as preformatted text.

render(<<<'HTML'
    <pre>
        Text in a pre element
        it preserves
        both      spaces and
        line breaks
    </pre>
HTML);

<code>

The <code> element can be used as code highlighter. It accepts line and start-line attributes.

render(<<<'HTML'
    <code line="22" start-line="20">
        try {
            throw new \Exception('Something went wrong');
        } catch (\Throwable $e) {
            report($e);
        }
    </code>
HTML);

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

More Repositories

1

phpinsights

πŸ”° Instant PHP quality checks from your console
PHP
5,176
star
2

larastan

βš—οΈ Adds code analysis to Laravel improving developer productivity and code quality.
PHP
4,882
star
3

collision

πŸ’₯ Collision is a beautiful error reporting tool for command-line applications
PHP
4,408
star
4

laravel-console-menu

πŸ”˜ Beautiful PHP CLI menus. Is a php-school/cli-menu wrapper for Laravel/Artisan Console Commands
PHP
794
star
5

skeleton-php

⚑️ This package provides a wonderful PHP skeleton to start building your next package idea.
PHP
647
star
6

laravel-desktop-notifier

πŸ’» Send notifications to your desktop from your Laravel Artisan Commands. An JoliNotif wrapper for Laravel.
PHP
415
star
7

laravel-mojito

🍹 A lightweight package for testing Laravel views in isolation
PHP
372
star
8

pest

This repository contains an old version of PEST. A new and better version is being coded in private and will be out soon: https://github.com/pestphp/pest.
342
star
9

patrol

Patrol is an elegant command-line tool that keeps your PHP Project's dependencies in check.
PHP
256
star
10

laravel-console-task

βœ… Laravel Console Task is a output method for Laravel Console Commands.
PHP
252
star
11

awesome-php-src

πŸš€ A curated list of awesome resources related to PHP source code
224
star
12

curryable

An elegant and simple curry(f) implementation in PHP.
PHP
175
star
13

dd

✨ The most popular way of debugging in PHP is now available in JavaScript.
JavaScript
159
star
14

yorn

βš—οΈ Modules in PHP with the `import` and `export` syntax
PHP
146
star
15

laravel-console-dusk

Laravel Console Dusk allows the usage of Laravel Dusk in Laravel/Laravel Zero artisan commands.
PHP
144
star
16

laracon-schedule

πŸ‘¨πŸ»β€πŸš€ A command-line tool that gives you the @LaraconOnline schedule in your timezone. πŸš€
PHP
101
star
17

laravel-pot

Provides Artisan commands to inspect Laravel Application's container. πŸͺ΄
PHP
88
star
18

mock-final-classes

πŸ„β€β™‚οΈ Allows mocking final classes in PHP.
PHP
83
star
19

awesome-laravel-vapor

πŸš€ A curated list of awesome resources related to Laravel Vapor.
80
star
20

laravel-console-summary

πŸ“– Beautiful Laravel Console Summary for Artisan or Laravel Zero.
PHP
62
star
21

collision-adapter-symfony

Collision's adapter for Symfony applications. Error Reporting for console/command-line PHP applications.
PHP
45
star
22

dig

πŸ‘¨πŸ»β€πŸŽ¨ A beautiful debug tool for the command line.
PHP
40
star
23

laravel-any

πŸ“ Laravel collection macro that determine if `any` item from the collection passes the given truth test.
PHP
38
star
24

nunomaduro.com

Rust
34
star
25

skeleton-c

⚑️ This package provides a wonderful C skeleton to start building your next package idea.
Makefile
33
star
26

php-interminal

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

bombe

Bombe is a tool for benchmarking the given url response status and response time.
C
23
star
28

skeleton-js

πŸ‘¨πŸ»β€πŸ’» A skeleton repository for my open source JavaScript packages
JavaScript
21
star
29

elegant-sublime

πŸ‘”An collection of sublime text preferences
17
star
30

alpine-day-schedule

πŸ‘¨πŸ»β€πŸš€ A command-line tool that gives you the Alpine Day 2021 schedule in your timezone. πŸš€
PHP
11
star
31

pint-strict-preset

Pint strict preset is an insanely defensive coding style preset for those who demand meticulous precision in their projects.
11
star
32

talks

🎀 My talks about PHP, Laravel or side projects of mine
10
star
33

laravel-meetups

πŸ•It's Meetup time! Find out Laravel Meetups near you!
PHP
8
star
34

laravel-console-spinner

❃ A spinning activity indicator for Laravel/Laravel Zero artisan commands.
7
star
35

laravel-9-test

PHP
5
star
36

forge-octane

PHP
5
star
37

scout-extended-demo

PHP
3
star
38

skeleton-typescript

βš—οΈ The perfect starting for typescript libraries.
3
star
39

laravel-zero-weather

PHP
3
star
40

nextjs-blog-wqdqwdqwd

JavaScript
2
star
41

dotfiles

2
star
42

twitter-stream

An demo application of Laravel Zero that works with the Twitter Streaming API
PHP
2
star
43

learn-javascript

2
star
44

my-site

HTML
1
star
45

vapor-github-test

PHP
1
star
46

qwdpowkqdopwqkd

JavaScript
1
star
47

skeleton-php-1

My PHP Package Skeleton
PHP
1
star
48

exclude-dev-files-bug

PHP
1
star
49

kpop-stack

TypeScript
1
star
50

nunomaduro

1
star
51

helpers-tap

🚰 Tap that method
TypeScript
1
star
52

test

HTML
1
star
53

perna

πŸ›‹ Optimises the workflow around managing multi-package repositories.
1
star
54

laravel-collections-examples

PHP
1
star
55

demo-p

PHP
1
star