Coder Social home page Coder Social logo

colorful-php's Introduction

Colorful-PHP

Preface

在写Nold文档示例生成小工具的时候,想要加入Console用于界面友好的命令行输出展示,其中需要Console需要对输出的文档进行适当美化。考虑到这个可集成到目前自己所写绝大部分的工具或者框架(譬如现在正在写的Nold文档生成小工具以及Zaor),所以便单独抽出来,便于今后其他工具或者框架可以使用.虽然网上类似的小插件也不少,不过想到这个轮子还是比较小的,所以干脆自己花点业余时间写一个好了.

Application

Let console to be Colorful~😆

Install

composer require yinggaozhen/colorful-php dev-master

Usage

大体用法是通过Cololrful::apply传入要渲染的文本以及主题,其中主题包括内置基础主题和装饰主题(可通过参数进一步调节).当然也可以通过Cololrful::import导入主题.


// 基础主题
Colorful::apply('Hi~ Success', 'success');
Colorful::apply('PHP Warning: file_get_contents failed to open stream: no suitable wrapper could be found.', 'warn');
Colorful::apply('PHP Fatal error: Call to undefined function mb_detect_encoding() ', 'fatal');
Colorful::apply('https://github.com/yinggaozhen/colorful-php', 'hyperlink');

// 装饰主题
$longtext = "message\n\n    The exception message\ncode\n\n    The exception code\nfile\n\n    The filename where the exception was created\nline\n\n    The line where the exception was created";
$frame = new \colorful\decorator\Frame([
    'spec' => '',
    'decorate' => '='
]);
echo colorful\Colorful::apply($longtext, ['yellow', null, []], $frame) . PHP_EOL;

stdoutput

Theme List

Theme List Type Params
success Base /
warn Base /
fatal Base /
hyperlink Base /
frame Decoretor php ['decorate' => 装饰符,默认*, 'spec' => 占位符,默认为'']

colorful-php's People

Contributors

yinggaozhen 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.