定制 sitnikovik/clipher 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sitnikovik/clipher

最新稳定版本:v1.0.0

Composer 安装命令:

composer require sitnikovik/clipher

包简介

CLI tool to beatify your scripts with colors, bolds, loading bars and much more

README 文档

README

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

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-24