martin-pettersson/chalk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

martin-pettersson/chalk

最新稳定版本:0.1.3

Composer 安装命令:

composer require martin-pettersson/chalk

包简介

A tool to style terminal output

README 文档

README

Inspired by Chalk this is a tool for PHP to style terminal output.

Installation

Through composer
Require chalk as a dependency: composer require martin-pettersson/chalk
Include the composer autoload file: require_once 'vendor/autoload.php'
Manually
Download/clone the repo
Chalk is PSR-4 compliant so any PSR-4 autoloader will do, just add the Chalk namespace "Chalk" and point it to the Chalk/src directory.

Usage

Quick Examples

You can copy this into a .php file and test it out.

<?php

require_once 'vendor/autoload.php';

use Chalk\Chalk;
use Chalk\Style;
use Chalk\Color;
use Chalk\BackgroundColor;

// use the style method to style the text
echo Chalk::style('This text is green', Color::GREEN) . PHP_EOL;

// convenience methods are available for colors (case insensitive)
echo Chalk::green('This text is also green') . PHP_EOL;
echo Chalk::Red('This text is red') . PHP_EOL;

// use a style object to compose styles
$style = new Style([Color::RED, BackgroundColor::GREEN, Style::UNDERLINED]);
echo Chalk::style('This text is red with green background', $style) . PHP_EOL;

// use the parse method for more advanced compositions
echo Chalk::parse('This text is {green}, {yellow}, {red}, {blue} and {something else}', [
  Color::GREEN,
  Color::YELLOW,
  Color::RED,
  Color::BLUE,
  $style
]) . PHP_EOL;

// you can nest styles
// note that the text at the end of the string is still green even after the background styling is reset
echo Chalk::Green('This text has some ' . Chalk::style('nested', BackgroundColor::WHITE) . ' styling') . PHP_EOL;

Example output:

example

Methods

Chalk::style(string $string, mixed $style)
Style the string by passing in either a Color/BackgroundColor/Style or a composed style object.

Chalk::parse(string $string, array $styles)
For more advanced styling use the parse method to style specific parts of the string. Use "{}" tags to target part of the string and pass in an array of styles. The styles matches the index of the found tags.

Convenience methods
If you use Chalk::{COLOR}($string) with any available color (case insensitive) it will conveniently map to Chalk::style($string, {COLOR}), eg. Chalk::Red($string) === Chalk::style($string, Color::RED)

Available Styles

Colors

  • Color::NONE (default)
  • Color::BLACK
  • Color::RED
  • Color::GREEN
  • Color::YELLOW
  • Color::BLUE
  • Color::MAGENTA
  • Color::CYAN
  • Color::LIGHT_GRAY
  • Color::DARK_GRAY
  • Color::LIGHT_RED
  • Color::LIGHT_GREEN
  • Color::LIGHT_YELLOW
  • Color::LIGHT_BLUE
  • Color::LIGHT_MAGENTA
  • Color::LIGHT_CYAN
  • Color::WHITE

Background Colors

  • BackgroundColor::NONE (default)
  • BackgroundColor::BLACK
  • BackgroundColor::RED
  • BackgroundColor::GREEN
  • BackgroundColor::YELLOW
  • BackgroundColor::BLUE
  • BackgroundColor::MAGENTA
  • BackgroundColor::CYAN
  • BackgroundColor::LIGHT_GRAY
  • BackgroundColor::DARK_GRAY
  • BackgroundColor::LIGHT_RED
  • BackgroundColor::LIGHT_GREEN
  • BackgroundColor::LIGHT_YELLOW
  • BackgroundColor::LIGHT_BLUE
  • BackgroundColor::LIGHT_MAGENTA
  • BackgroundColor::LIGHT_CYAN
  • BackgroundColor::WHITE

Styles

  • Style::BOLD
  • Style::DIM
  • Style::UNDERLINED
  • Style::BLINK
  • Style::INVERTED
  • Style::HIDDEN

martin-pettersson/chalk 适用场景与选型建议

martin-pettersson/chalk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.02k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2015 年 10 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「color」 「style」 「chalk」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 martin-pettersson/chalk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 martin-pettersson/chalk 我们能提供哪些服务?
定制开发 / 二次开发

基于 martin-pettersson/chalk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 9
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-01