Giter Club home page Giter Club logo

laravel-fancy-console's Introduction

Fancy Console for Laravel

Author Packagist Version Software License

Fancy Console for Laravel provides a FancyConsole trait that gives you a few extra fancy styled console outputs to compliment the already useful default Laravel ones.

Requirements

  • PHP >= 7.2
  • Laravel 5.8 and up

Installation

Install the package via composer:

composer require kielabokkie/laravel-fancy-console

Usage

Firstly you'll have to add the FancyConsole trait to your command:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Kielabokkie\FancyConsole\Traits\FancyConsole;

class MyCommand extends Command
{
    use FancyConsole;
}

Success and fail messages

To make it easier to style success and fail messages you will have access to the following methods:

$this->success('Yes, it worked!');
$this->success('Yes, it worked!', 'OK');

$this->fail('Oh no, it did not work.');
$this->fail('Oh no, it did not work.', 'BUMMER');

$this->successBlock('This is a great success');

$this->errorBlock('This is a serious error');

Which gives you the following output:

screenshot

Loading indicator

Laravel already comes with an easy progress bar but if you want to show progress in a different way you can use the dot loading indicator:

for ($i = 0; $i < 100; $i++) {
    $this->dot();
}

The code above will output 100 dots on the same line. If you want to restrict the number of dots on a line you can set the dot width:

$this->setDotWidth(40);

for ($i = 0; $i < 100; $i++) {
    $this->dot();
}

Now it will jump to the next line once the number of dots reach a multiple of 40.

If you know the total number of loading dots your command will be outputting you can set the total dots and the output will show you the current progress and total per line.

$dotTotal = 100;

$this->setDotTotal($dotTotal);
$this->setDotWidth(40);

for ($i = 0; $i < $dotTotal; $i++) {
    $this->dot();
}

Lastly, if you would like to use a different character instead of a dot, you can pass it as a parameter:

$this->dot('-');

laravel-fancy-console's People

Contributors

kielabokkie avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

laravel-fancy-console's Issues

Add inline dot loading indicator

Make it easy to add to add a dot loading indicator, the one that keeps on adding dots on the same line. Could be something like $this->dot() to add a dot. Would be nice to be able to set a maximum number of dots until it breaks to the next line, e.g. $this->dotWidth(80).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.