<?php declare(strict_types=1);
namespace Inhere\Console\Component\Formatter;
use Inhere\Console\Component\MessageFormatter;
use Inhere\Console\Console;
use Inhere\Console\Util\FormatUtil;
use Toolkit\Cli\ColorTag;
use function array_merge;
use function trim;
use function ucwords;
use const PHP_EOL;
class SingleList extends MessageFormatter
{
public static function show($data, string $title = 'Information', array $opts = [])
{
$string = '';
$opts = array_merge([
'leftChar' => ' ',
'keyStyle' => 'info',
'keyMinWidth' => 8,
'titleStyle' => 'comment',
'returned' => false,
'lastNewline' => true,
], $opts);
if ($title) {
$title = ucwords(trim($title));
$string .= ColorTag::wrap($title, $opts['titleStyle']) . PHP_EOL;
}
$string .= FormatUtil::spliceKeyValue((array)$data, $opts);
if ($opts['returned']) {
return $string;
}
return Console::write($string, $opts['lastNewline']);
}
}