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
blackblackbgredredbggreengreenbgyellowyellowbgbluebluebgmagentamagentabgcyancyanbgwhitewhitebggraygraybgbolditalicunderlineinversestrikethrough
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
molovo/graphite 适用场景与选型建议
molovo/graphite 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 819 次下载、GitHub Stars 达 2, 最近一次更新时间为 2016 年 03 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cli」 「graphite」 「ansi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 molovo/graphite 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 molovo/graphite 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 molovo/graphite 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Genetaror for ANSI color escape sequences.
A PHP library for working with statsd
Collections of statsd collectors with templated metric names
ConsoleDisplayLib is a simple library for CLI apps to output to the console
A PHP client for Carbon (Graphite's backend) using the plaintext protocol.
PHP Terminal emulator controller utilizing ANSI escape sequence coding.
统计信息
- 总下载量: 819
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 9
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-03-08