PHP's best friend for the terminal.

Related tags

Command Line climate
Overview

CLImate

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

Running PHP from the command line? CLImate is your new best bud.

CLImate allows you to easily output colored text, special formats, and more.

Installation

The recommended method of installing this library is via Composer.

Run the following command from your project root:

$ composer require league/climate

Usage

require_once __DIR__ . "/vendor/autoload.php";

$climate = new \League\CLImate\CLImate;

$climate->red('Whoa now this text is red.');
$climate->blue('Blue? Wow!');

Read more at https://climate.thephpleague.com/

Credits

This library was created by Joe Tannenbaum.
It is currently maintained and developed by Craig Duncan.
Much love to Damian Makki for the logo.

Comments
  • Progress bar rendering on Windows broken

    Progress bar rendering on Windows broken

    I'm using ANSICON (because default terminal don't support ANSI escape codes, in fact ANSICON don't do it well too) on Win8x64, CLImate just renders new line each time it increments, without erasing old one.

    So it looks like this:

    >
    =>
    ==>
    ===>
    ====>
    =====>
    ======>
    =======>
    ========>
    =========>
    ==========>
    ===========>
    ============>
    =============>
    ==============>
    ===============>
    ================>
    =================>
    ==================>
    ===================>
    ====================>
    =====================>
    ======================>
    =======================>
    ========================>
    =========================>
    ==========================>
    ===========================>
    ============================>
    =============================>
    ==============================>
    ===============================>
    ================================>
    =================================>
    ==================================>
    ===================================>
    ====================================>
                             n%
    

    Well, i know that it's a Windows problem, but look at Composer, it renders progress bar fine even on Windows ;)

    opened by thers 21
  • Allow CLImate to be used in a web context

    Allow CLImate to be used in a web context

    Hi.

    I can't get past tis error message. Can't find anything online regarding this for CLImate either. How can I get past this?

    Here's what I did: I went to my project's folder and ran composer require league/climate. After that, I copied-pasted the code under "Usage" in README.md here on GitHub and reloaded the page for my project.

    require_once 'vendor/autoload.php';
    $climate = new \League\CLImate\CLImate;
    
    $climate->red('Whoa now this text is red.');
    $climate->blue('Blue? Wow!');
    
    Warning: Use of undefined constant STDOUT - assumed 'STDOUT' (this will throw an Error in a future version of PHP) in /var/www/html/website/vendor/league/climate/src/Util/System/Linux.php on line 90
    Fatal error: Uncaught Error: Undefined constant 'STDOUT' in /var/www/html/website/vendor/league/climate/src/Util/Writer/StdOut.php:14 Stack trace: #0 /var/www/html/website/vendor/league/climate/src/Util/Output.php(183): League\CLImate\Util\Writer\StdOut->write() #1 /var/www/html/website/vendor/league/climate/src/TerminalObject/Router/BasicRouter.php(37): League\CLImate\Util\Output->write() #2 /var/www/html/website/vendor/league/climate/src/TerminalObject/Router/Router.php(99): League\CLImate\TerminalObject\Router\BasicRouter->execute() #3 /var/www/html/website/vendor/league/climate/src/CLImate.php(384): League\CLImate\TerminalObject\Router\Router->execute() #4 /var/www/html/website/vendor/league/climate/src/CLImate.php(399): League\CLImate\CLImate->buildTerminalObject() #5 /var/www/html/website/vendor/league/climate/src/CLImate.php(435): League\CLImate\CLImate->routeRemainingMethod() #6 /var/www/html/website/vendor/league/climate/src/CLImate.php(440): League\CLImate\CLImate->__call() #7 /va in /var/www/html/website/vendor/league/climate/src/Util/Writer/StdOut.php on line 14
    
    enhancement 
    opened by airikr-e 12
  • Add CLI argument support

    Add CLI argument support

    I've been using CLImate at work lately. I love it, but I hated having to use getopt() or $argv to talk to my command line arguments. I looked into various console libraries, but they also did output in addition to argument processing. I saw in #29 you said you weren't opposed to CLImate doing argument parsing, so I added it. I tried to follow the existing API and internal code conventions as much as I can.

    This change adds an argument manager to the CLImate object. Users can define arguments against the argument manager, parse arguments on the command line into those defined arguments, retrieve CLI argument values, and generate a usage statement based on user defined arguments.

    An argument is defined as something that's passed along to a script, either in a short form ("-a foo"), long form ("--foo bar"), both, or neither to process arguments after the prefixed argument list. Arguments can be:

    • marked as required
    • have default values
    • have their values cast to string, int, float, or boolean data types
    • set true if they're defined on the command line (for cases where a value isn't needed like "-f" to force or "--help" to show a usage statement).
    • have values set in "-key value" or "-key=value" form on the command line.

    Arguments that are required but not defined on the command line generate an exception that's sent back to calling code.

    Here's a simple example. Assume you have a script that pushes a local directory to some SSH server. That script needs a username, a password, a host, maybe an option to print usage, one to overwrite existing files, maybe a verbosity option, and a path to push to my server. I may store the username and hostname internally, but let users enter their own if they like, but they have to provide a password. I'd probably call it by running:

    php ./pusher.php -u myusername -p secret -h hostname --force -v ./push_me
    

    That script would look like:

    <?php
    
    require __DIR__ . '/vendor/autoload.php';
    
    use League\CLImate\CLImate;
    
    $climate = new CLImate;
    $climate->description('Awesome SCP Pusher v0.01');
    $climate->arguments->add([
        'user' => [
            'prefix' => 'u',
            'longPrefix' => 'user',
            'description' => 'SSH Username',
            'defaultValue' => 'myuser',
        ],
        'password' => [
            'prefix' => 'p',
            'longPrefix' => 'password',
            'description' => 'SSH Password',
            'required' => true,
        ],
        'host' => [
            'prefix' => 'H',
            'longPrefix' => 'host',
            'description' => 'SSH Hostname',
            'defaultValue' => 'myhost.local'
        ],
        'force' => [
            'prefix' => 'f',
            'longPrefix' => 'force',
            'description' => 'Overwrite files on copy',
            'definedOnly' => true,
        ],
        'verbose' => [
            'prefix' => 'v',
            'longPrefix' => 'verbose',
            'description' => 'Verbose output',
            'definedOnly' => true,
        ],
        'help' => [
            'prefix' => 'h',
            'longPrefix' => 'help',
            'description' => 'Print a usage statement',
            'definedOnly' => true,
        ],
        'path' => [
            'description' => 'The path to push',
        ],
    ]);
    
    // Print a usage statement on --help
    if ($climate->arguments->defined('help')) {
        $climate->usage();
        exit();
    }
    
    // Parse arguments.
    try {
        $climate->arguments->parse();
    } catch (Exception $e) {
        // Let us know if arguments were missing.
        $climate->error($e->getMessage());
        $climate->br();
        $climate->usage();
        exit();
    }
    
    // Echo instead of push.
    $climate->out('Username: ' . $climate->arguments->get('user'));
    $climate->out('Hostname: ' . $climate->arguments->get('host'));
    
    if ($climate->arguments->get('force')) {
        $climate->out("I'm going to overwrite on copy.");
    }
    

    Here's an execution that echo's the usage statement:

    $ php ./pusher.php -h
    Awesome SCP Pusher v0.01
    
    Usage: ./pusher.php [-f, --force] [-H host, --host host (default: myhost.local)] [-h, --help] [-p password, --password password] [-u user, --user user (default: myuser)] [-v, --verbose] [path]
    
    Required Arguments:
        -p password, --password password
            SSH Password
    
    Optional Arguments:
        -f, --force
            Overwrite files on copy
        -h, --help
            Print a usage statement
        -H host, --host host (default: myhost.local)
            SSH Hostname
        -u user, --user user (default: myuser)
            SSH Username
        -v, --verbose
            Verbose output
    

    And an execution that spits out those debug out()s:

    $ php ./pusher.php -u bob -p secret -f ./my-dir
    Username: bob
    Hostname: myhost.local
    I'm going to overwrite on copy.
    

    The new changes pass all tests with 100% new code coverage, minus one line that needs to talk to the global scope to get $argv. Tests use a mocked $argv.

    Let me know if this looks okay to you. If it does and gets merged I can write public-facing documentation for this too.

    opened by klaude 11
  • Colors are not appearing in log files in 2.6

    Colors are not appearing in log files in 2.6

    Hi,

    Great library!

    Something has changed from 2.5 to 2.6 where colors are no longer being pushed to files. I have cronjob which outputs a lot of information to log files with a lot of color so I can easily see problems. 2.6 no longer appears to send the colors to the files when redirecting to a file.

    opened by terah 10
  • Allow content to be padded

    Allow content to be padded

    Sometimes it can useful to pad content out to a particular length (requested in issue #14)

    $padding = $climate->padding(50);
    $padding->pad("Line one stuff");
    $padding->pad("More stuff on line two");
    $padding->pad("Final content on line three");
    

    Will output:

    Line one stuff....................................
    More stuff on line two............................
    Final content on line three.......................
    

    If no width is passed to the padding method then the full terminal width is used. The length can also be specified using the length() method.

    An alternative character can be specified with the padWidth() method, or as the second parameter to padding(). Multiple characters can also be used

    $padding = $climate->padding(5, ".-");
    $padding->pad("AAA");
    $padding->pad("BB");
    $padding->pad("CCCC");
    

    Will output:

    AAA-.-
    BB.-.-
    CCCC.-
    

    Would you like me to submit a pull request for the documentation to explain all the features?

    opened by duncan3dc 8
  • Package website for CLImate

    Package website for CLImate

    So, the next step is creating a package website for this project. To make this process a little easier, we've created a ready-made theme that's powered by Sculpin.

    You can find the full instructions on how to set this up here. Since you have most of your documentation worked out already this should be pretty straightforward. However, being honest, the process can be a little confusing at first. Do your best, and hit me up if you have any questions!

    opened by reinink 8
  • Some hints / examples for multiple menu handling?

    Some hints / examples for multiple menu handling?

    Hi, I really like this little lib because of its minimalism, very quick to get up! Thank you very much!

    However, after adding some functions to a small tool I need to start thinking about how to organize multiple levels of (mostly radiobutton) menus - do you have some hints or examples for how to handle this? Or is there any other library / extension / addon that helps with that? I really would like to make it a little bit more declarative, so menus could be defined with a config file with the option key as function name to execute when selected, but before I get lost I just wanted to ask if I could learn from someone who has solved that already...?

    Thanks for your attention!

    enhancement 
    opened by wowcut 7
  • Argument issue when no value is provided

    Argument issue when no value is provided

    @joetannenbaum thanks for this great package. I use CLImate over at PHPloy. Lately I've run into an issue. I use this argument:

    phploy --sync
    phploy --sync="hash-goes-here"
    

    The second command works fine, the first one causes this notice and fails:

    PHP Notice:  Undefined offset: 1 in phar:///usr/local/bin/deploy/vendor/league/climate/src/Argument/Parser.php on line 195
    

    Here is the implementation of the argument:

    'sync' => [
        'longPrefix' => 'sync',
        'description' => 'Syncs revision to a given version',
        'defaultValue' => 'LAST',
    ]
    

    What seems to be wrong? Is this a bug in the parser?

    Thanks a lot, Baki

    opened by banago 7
  • Single Array Error within $climate->table($X);

    Single Array Error within $climate->table($X);

    Hi When trying to use $climate->table($X); and the Array of (Associative Arrays) only contains 1 record you get the following error

    PHP Fatal error: Uncaught TypeError: Argument 1 passed to League\CLImate\TerminalObject\Basic\Table::getDefaultColumnWidths() must be of the type array, integer given, called in /scripts/vendor/league/climate/src/TerminalObject/Basic/Table.php on line 206 and defined in /scripts/vendor/league/climate/src/TerminalObject/Basic/Table.php:224 Stack trace: #0 /scripts/vendor/league/climate/src/TerminalObject/Basic/Table.php(206): League\CLImate\TerminalObject\Basic\Table->getDefaultColumnWidths(6311133) #1 /scripts/vendor/league/climate/src/TerminalObject/Basic/Table.php(72): League\CLImate\TerminalObject\Basic\Table->getColumnWidths() #2 /scripts/vendor/league/climate/src/TerminalObject/Router/BasicRouter.php(28): League\CLImate\TerminalObject\Basic\Table->result() #3 /scripts/vendor/league/climate/src/TerminalObject/Router/Router.php(99): League\CLImate\TerminalObject\Router\BasicRouter->execute(Object(League\CLImate\TerminalObject\Basic\Table)) #4 /scripts/vendor/league/climate/src/CLImate.php(381): League\CLImate\TerminalObjec in /scripts/vendor/league/climate/src/TerminalObject/Basic/Table.php on line 224

    opened by TwinMist 6
  • Color support detection is broken on Windows

    Color support detection is broken on Windows

    https://github.com/thephpleague/climate/blob/4d3ddf97b6db22c76efe2340f603c0d9834ddf72/src/Util/System/Windows.php#L72

    ^ getenv() will never return true, this check should probably be !== false.

    bug 
    opened by kelunik 6
  • Allow CLImate to be used as a PSR-3 logger

    Allow CLImate to be used as a PSR-3 logger

    Inspired by #57 I created a simple Logger class that implements the PSR-3 LoggerInterface.

    Including some of the other features from: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md

    • Objects with __toString()
    • Exceptions in context
    • Placeholders in context
    opened by duncan3dc 6
  • Progress precision

    Progress precision

    For long running progress bars, seeing it sit at 1% isn't exciting, so I added the ability to change the precision of the percentage.

    Usage is straightforward:

    $progress = $this->cli->progress(3);
    $progress->precision(3);
    $progress->current(1);
    
    ===>         33.333%
    

    I tried to write a test, but I'm not well versed in unit-testing so this causes an error I'm not sure how to fix:

    vendor/bin/phpunit --filter it_can_output_a_progress_bar_with_precision tests/ProgressTest.php
    PHPUnit 9.5.27 by Sebastian Bergmann and contributors.
    
    E                                                                   1 / 1 (100%)
    
    Time: 00:00.015, Memory: 6.00 MB
    
    There was 1 error:
    
    =======================>                                                33.3%'). Either the method was unexpected or its arguments matched no expected argument list for this method
    Mockery\Exception\NoMatchingExpectationException: No matching handler found for Mockery_2_League_CLImate_Util_Output::write('
    
    
    /var/www/html/climate/vendor/mockery/mockery/library/Mockery/ExpectationDirector.php:92
    /var/www/html/climate/src/TerminalObject/Dynamic/Progress.php:198
    /var/www/html/climate/src/TerminalObject/Dynamic/Progress.php:125
    /var/www/html/climate/tests/ProgressTest.php:104
    
    ERRORS!
    Tests: 1, Assertions: 0, Errors: 1.
    
    opened by quasipickle 0
  • Useless method

    Useless method

    https://github.com/thephpleague/climate/blob/a785a3ac8f584eed4abd45e4e16fe64c46659a28/src/CLImate.php#L143

    There is no encapsulation also property is public.

    opened by eugenebunin 0
  • fwrite(): Write of 1 bytes failed with errno=32

    fwrite(): Write of 1 bytes failed with errno=32

    I've been getting these intermittently and haven't been able to figure out why yet. Any ideas?

    fwrite(): Write of 1 bytes failed with errno=32 Broken pipe {"exception":"[object] (ErrorException(code: 0): fwrite(): Write of 1 bytes failed with errno=32 Broken pipe at /var/www/REMOVED/vendor/league/climate/src/Util/Writer/StdOut.php:14)
    
    opened by Fossil01 0
  • Progress: getCurrent() & getTotal()

    Progress: getCurrent() & getTotal()

    It would be useful to be able to retrieve the current & total values from a progress bar.

    My use case is that I define the progress bar in one method in a class, then use it in other methods. I'd like my label to be updated with the count, ie (23/1176) without having to track those numbers separately.

    I'm happy to do this & submit a PR, but I wonder if this package is actively maintained?

    opened by quasipickle 0
  • [Warning] PHP Deprecated: strlen(): Passing null to parameter #1

    [Warning] PHP Deprecated: strlen(): Passing null to parameter #1

    Hello,

    I am using climate with PHP8.1, and I have this log : PHP Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /Users/Toto/Sites/Sandbox/vendor/league/climate/src/TerminalObject/Basic/BasicTerminalObject.php on line 21

    To fix this warning message, I just add this $value && strlen($value) in https://github.com/thephpleague/climate/blob/637555fdf6285c8077297f326760d9d8a5112f28/src/TerminalObject/Basic/BasicTerminalObject.php#L21

    protected function set($key, $value)
    {
        if ($value && strlen($value)) {
            $this->$key = $value;
        }
    }
    

    Is it possible to include this fix in the next release ?

    Best

    opened by kekefreedog 1
Releases(2.0.0)
Owner
The League of Extraordinary Packages
A group of developers who have banded together to build solid, well tested PHP packages using modern coding standards.
The League of Extraordinary Packages
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
I gues i tried to make a shell that's looks like a terminal in single php file

php-shell-gui Terms of service This tool can only be used for legal purposes. You take full responsibility for any actions performed using this. The o

Squar3 4 Aug 23, 2022
tin is a PHP code highlighter for the terminal.

tin tin is a PHP code highlighter for the terminal. Installation Requires PHP 8.0.0+ You can install the package via composer: composer require felixd

Felix Dorn 15 Oct 7, 2022
Hentai Bash - This is the core of Hentai Terminal, responsible for the basic functions and commands

Hentai Bash - This is the core of Hentai Terminal, responsible for the basic functions and commands. It is mainly used for writing and executing commands.

Hentai Group 1 Jan 26, 2022
Create a simple todo-list application with the basic PHP programming language implemented in the terminal

PHP-DASAR---simple-todo-list-app-with-terminal create a simple todo-list application with the basic PHP programming language implemented in the termin

Ahmad Wali Alchalidi 2 Sep 7, 2022
Rah terminal - A terminal for Textpattern CMS

rah_terminal Twitter | GitHub | Donate Rah_terminal is a plugin for Textpattern CMS. It provides a terminal emulator interface for executing external

Jukka Svahn 2 Apr 17, 2022
A fluent extension to PHPs DateTime class.

Expressive Date A fluent extension to PHPs DateTime class. Table of Contents Installation Composer Manually Laravel 4 Usage Getting Instances Quick He

Jason Lewis 258 Oct 9, 2021
This is a simple php project to help a friend how parse a xml file.

xml-parser-with-laravie Requirements PHP 7.4+ Composer 2+ How to to setup to test? This is very simple, just follow this commands git clone https://gi

Lucas Saraiva 2 Dec 3, 2021
A simple, standalone, modern PHP class inspector and mapper library, wrapping PHPs native reflection in a fluent interface

A simple, standalone, modern PHP class inspector and mapper library, wrapping PHPs native reflection in a fluent interface.

smpl 9 Sep 1, 2022
Php Debugger to run in terminal to debug your code easily.

What is Dephpugger? Dephpugger (read depugger) is an open source lib to make a debug in php direct in terminal, without necessary configure an IDE. Th

Renato Cassino 190 Dec 3, 2022
Render the symfony profiler toolbar in your terminal.

sourceability/console-toolbar-bundle Render the symfony profiler toolbar in your terminal. Each panel links to the corresponding web profiler page.

null 49 Nov 8, 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. ??

Nuno Maduro 32 Dec 26, 2022
Render colored Markdown contents on console terminal

cli-markdown Render colored markdown contents on console terminal Preview run demo by php example/demo.php Features support auto render color on termi

PHPComLab 6 Sep 29, 2022
Highlight PHP code in terminal

PHP Console Highlighter This repository is abandoned. Suggested alternative: https://github.com/php-parallel-lint/PHP-Console-Highlighter Highlight PH

Jakub Onderka 6.2k Dec 22, 2022
Run the following commands in your terminal to setup the project

Run the following commands in your terminal to setup the project You must have the LAMP installed on your system git clone https://github.com/Bashar-A

null 1 Nov 6, 2021
I gues i tried to make a shell that's looks like a terminal in single php file

php-shell-gui Terms of service This tool can only be used for legal purposes. You take full responsibility for any actions performed using this. The o

Squar3 4 Aug 23, 2022
tin is a PHP code highlighter for the terminal.

tin tin is a PHP code highlighter for the terminal. Installation Requires PHP 8.0.0+ You can install the package via composer: composer require felixd

Felix Dorn 15 Oct 7, 2022
Php Debugger to run in terminal to debug your code easily.

What is Dephpugger? Dephpugger (read depugger) is an open source library that allows a developer to debug in php direct in terminal, without necessary

Renato Cassino 190 Dec 3, 2022
Terminal drawing with braille

php-drawille Terminal drawing with braille. Requirements php-drawille requires PHP 5.4.0 or later. Installation The recommended way to install php-dra

Jeff Welch 102 Nov 2, 2022
Hentai Bash - This is the core of Hentai Terminal, responsible for the basic functions and commands

Hentai Bash - This is the core of Hentai Terminal, responsible for the basic functions and commands. It is mainly used for writing and executing commands.

Hentai Group 1 Jan 26, 2022