承接 molovo/graphite 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

molovo/graphite

Composer 安装命令:

composer require molovo/graphite

包简介

A collection of helpers for building pretty command-line tools.

README 文档

README

A collection of helpers for building pretty command-line tools.

$graphite = new Molovo\Graphite\Graphite;

echo $graphite->green->underline('I believe in unicorns!');

Installation

Install using composer:

composer require molovo/graphite

Basic Usage

Once instantiated, the Graphite class becomes a re-usable string rendering tool. It comes with a number of methods for styling the foreground color, background color and style of a string using ANSI escape codes.

echo $graphite->red('A string');
// "\033[0;31mA string\033[0;m"

When accessed as a property, or as a method without arguments, these methods allow chaining of styles. When a string is passed as the first argument, it is returned with all the chained styles applied.

echo $graphite->red->yellowbg()->underline('A string');
// "\033[4;31;43mA string\033[0;m"

Global indentation can be set with the setGlobalIndentation() method. Once defined, when the render() method is invoked, the string passed to it is output with the defined indentation prepended to it, and with a newline appended.

$graphite->setGlobalIndentation(2);
echo $graphite->yellow->render('A string');
// "  \033[0;33mA string\033[0;m\n"

Available styling methods

  • black
  • blackbg
  • red
  • redbg
  • green
  • greenbg
  • yellow
  • yellowbg
  • blue
  • bluebg
  • magenta
  • magentabg
  • cyan
  • cyanbg
  • white
  • whitebg
  • gray
  • graybg
  • bold
  • italic
  • underline
  • inverse
  • strikethrough

Additional Methods

As well as the styling methods above, the following helper methods are available.

strip(string $str)

The strip() method strips all ANSI escape codes from the passed string and returns it.

$str = "\033[0;31mA string with ANSI escaping\033[0;m"
echo $graphite->strip($str);
// "A string with ANSI escaping"

repeat(string $character, int $length)

The repeat() method returns a string consisting of the defined $character, repeated $length times.

echo $graphite->repeat('+', 5);
// "+++++"

Boxes

The Box class adds a border around a string (or an array of strings, where each item is a line).

$box = new Molovo\Graphite\Box('Rainbows!');
echo $box;
// ┌─────────┐
// │Rainbows!│
// └─────────┘

Boxes can be styled in a number of ways, by passing an array of styles as a second parameter.

$box = new Box('Unicorns!', [
  'borderColor' => Graphite::WHITE, // The color of the border (and title)
  'borderStyle' => Box::SINGLE,    // The border style
  'marginX'     => 0,               // The number of characters to add to left and right
  'marginY'     => 0,               // The number of lines to add above and below
  'paddingX'    => 0,               // The number of characters to add as left and right padding
  'paddingY'    => 0,               The number of lines to add as top and bottom padding
]);

The following styles are available:

Box::SINGLE
┌──────────┐
│The string│
└──────────┘

Box::DOUBLE
╔══════════╗
║The string║
╚══════════╝

Box::ROUNDED
╭──────────╮
│The string│
╰──────────╯

Box::SINGLE_DOUBLE
╓──────────╖
║The string║
╙──────────╜

Box::DOUBLE_SINGLE
╒══════════╕
│The string│
╘══════════╛

Box::CLASSIC
+----------+
|The string|
+----------+

You can also use the Box::NO_BORDER to add margin and padding to a string without a border.

$box = new Box("Unicorns and\nrainbows", [
  'borderStyle' => Box::NO_BORDER,
  'paddingX' => 2,
  'paddingY' => 1
]);
echo $box;
//
//   Unicorns and
//   rainbows
//

You can also add titles to boxes. These are rendered within the border, in the same color.

$box = new Box('The string', ['paddingX' => 1]);
$box->setTitle('My Box');
echo $box;
// ┌ My Box ────┐
// │ The string │
// └────────────┘

Tables

$data = [
    ['First', 'Second', 'Third'],
    [1, 2, 3],
    [11, 22, 33],
];

$table = new Table($data, [
    'cellPadding'     => 1,
    'columnSeparator' => '',
    'headerColor'     => Graphite::WHITE,
    'headerSeparator' => '',
    'marginX'         => 0,
    'marginY'         => 0,
    'separatorColor'  => Graphite::WHITE,
]);
echo $table;

// First │ Second │ Third
// ══════════════════════════
// 1     │ 2      │ 3
// 11    │ 22     │ 33

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-03-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固