initphp/cli-table

PHP CLI表格生成器

1.0 2022-08-26 21:36 UTC

This package is not auto-updated.

Last update: 2024-09-22 06:02:01 UTC


README

此库允许您使用PHP在CLI界面中创建美观的表格。

注意:不是必需的,但强烈建议安装 MB_String 扩展。

安装

composer require initphp/cli-table

或者包含 src/Table.php

用法

<?php
require_once __DIR__ . "/vendor/autoload.php";
use \InitPHP\CLITable\Table;

$table = new Table();

$table->row([
    'id'        => 1,
    'name'      => 'Matthew S.',
    'surname'   => 'Kramer',
    'email'     => 'matthew@example.com',
    'status'    => true,
]);

$table->row([
    'id'        => 2,
    'name'      => 'Millie J.',
    'surname'   => 'Koenig',
    'email'     => 'millie@example.com',
    'status'    => false,
]);

$table->row([
    'id'        => 3,
    'name'      => 'Regina G.',
    'surname'   => 'Hart',
    'email'     => 'regina@example.com',
    'status'    => true,
]);

echo $table;

输出

basic-cli-table

样式

<?php
declare(strict_types=1);
require_once __DIR__ . '/../vendor/autoload.php';
use InitPHP\CLITable\Table;

$table = new Table();
$table->setBorderStyle(Table::COLOR_BLUE);
$table->setCellStyle(Table::COLOR_GREEN);
$table->setHeaderStyle(Table::COLOR_RED, Table::BOLD);

$table->setColumnCellStyle('id', Table::ITALIC, Table::COLOR_LIGHT_YELLOW);
$table->setColumnCellStyle('email', Table::BOLD, Table::ITALIC);

$table->row([
    'id'        => 1,
    'name'      => 'Matthew S.',
    'surname'   => 'Kramer',
    'email'     => 'matthew@example.com',
    'status'    => true,
]);

$table->row([
    'id'        => 2,
    'name'      => 'Millie J.',
    'surname'   => 'Koenig',
    'email'     => 'millie@example.com',
    'status'    => false,
]);

$table->row([
    'id'        => 3,
    'name'      => 'Regina G.',
    'surname'   => 'Hart',
    'email'     => 'regina@example.com',
    'status'    => true,
]);

echo $table;

输出

styled-cli-table

致谢

许可

版权所有 © 2022 MIT许可