Coder Social home page Coder Social logo

console's Introduction

Console

Beatifies your cli scripts with colors, bolds, loading bars and much more

Get started

Just create an object of Sitnikovik\Console\Console and go on:

$console = new \Sitnikovik\Console\Console();

Input

confirm

\Sitnikovik\Console\Console::confirm(string $question, bool $yesOnDefault = false): void

Make user approve or decline some process with the y/n

prompt

\Sitnikovik\Console\Console::prompt(string $question): string

Asks user input the answer needed to continue the program

Output

println

\Sitnikovik\Console\Console::println(string $text): void

Prints the text console output with new line

separate

\Sitnikovik\Console\Console::separate(int $width = 0): void

Prints a separate bar with provided width or stretched if width is 0

quit

\Sitnikovik\Console\Console::quit(string $message = '')

Exit the program with 0 code and prints message text if not empty

panic

\Sitnikovik\Console\Console::panic(string $message = '', int $code = 1)

Exit the program with provided code signalizing the program failed and prints message in red color if not empty

Colors

If you want to switch color styles you have to provide Sitnikovik\Console\Style\StyleInterface classes for text and background layout to colorize the output.

// set colors
$console->setTextStyle(new Sitnikovik\Console\Style\Text\Bold());
$console->setBackgroundStyle(new Sitnikovik\Console\Style\Background());

// or via constructor
$console = new Console(new Sitnikovik\Console\Style\Text\Regular(), new Sitnikovik\Console\Style\Background());

Customize style colors

Eitherway, you can create custom classes extended by Sitnikovik\Console\Style\AbstractStyle or others implemented Sitnikovik\Console\Style\StyleInterface and modify colors you prefer.

Colorize text

There are at least 8 methods to colorize text implemented by Sitnikovik\Console\Style\AbstractStyle and Sitnikovik\Console\Style\StyleInterface. Class calls the interface methods:

  • black()
  • red()
  • green()
  • yellow()
  • blue()
  • purple()
  • cyan()
  • white()
$text = $console->red('some text'); // colorize text
// or
$text = $console->bgRed('some text'); // set background to text

They return provided text colorized to called color.

Progress bar

If you need to visualize some process progress you can use Sitnikovik\Console\Progressbar\Progressbar

// Create the bar like that
$maxValue = 100;
$progressbar = $console::createProgressbar($maxValue);
// or 
$progressbar = Sitnikovik\Console\Progressbar\Progressbar($maxValue);

// Advancing
for ($current = 0; $current < $maxValue; $current++) {
    $progressbar->advance(); // increment with 1 point of the max value
}

// Or advance it manually
$progressbar->advance(40); // or another value

console's People

Contributors

sitnikovik avatar

Watchers

 avatar

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.