Skip to content

Commit 2405df4

Browse files
committed
update some func use
1 parent 0898e8b commit 2405df4

File tree

7 files changed

+36
-38
lines changed

7 files changed

+36
-38
lines changed

src/Component/Style/Style.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
namespace Inhere\Console\Component\Style;
1212

13-
use Inhere\Console\Util\Helper;
1413
use Toolkit\Cli\Cli;
1514

1615
/**
@@ -75,7 +74,7 @@ class Style
7574
/**
7675
* @return Style
7776
*/
78-
public static function create(): Style
77+
public static function instance(): Style
7978
{
8079
if (!self::$instance) {
8180
self::$instance = new self();
@@ -153,7 +152,7 @@ protected function loadDefaultStyles(): void
153152
*/
154153
public function apply(string $style, $text): string
155154
{
156-
return $this->format(Helper::wrapTag($text, $style));
155+
return $this->format(self::wrap($text, $style));
157156
}
158157

159158
/**
@@ -332,6 +331,21 @@ public function hasStyle($name): bool
332331
return isset($this->styles[$name]);
333332
}
334333

334+
/**
335+
* wrap a color style tag
336+
* @param string $text
337+
* @param string $tag
338+
* @return string
339+
*/
340+
public static function wrap(string $text, string $tag): string
341+
{
342+
if (!$text || !$tag) {
343+
return $text;
344+
}
345+
346+
return "<$tag>$text</$tag>";
347+
}
348+
335349
/**
336350
* Method to get property NoColor
337351
*/

src/Component/Symbol/ArtFont.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Inhere\Console\Util\Helper;
1212
use Inhere\Console\Util\Show;
13+
use Toolkit\Cli\ColorTag;
1314

1415
/**
1516
* Class ArtFont art fonts Manager
@@ -151,7 +152,7 @@ public function show(string $name, string $group = null, array $opts = []): int
151152

152153
// var_dump($txt, $this);
153154
if ($txt) {
154-
return Show::write(Helper::wrapTag($txt, $opts['style']));
155+
return Show::write(ColorTag::wrap($txt, $opts['style']));
155156
}
156157

157158
return 0;

src/Controller.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Inhere\Console\IO\Output;
1414
use Inhere\Console\Util\FormatUtil;
1515
use Inhere\Console\Util\Helper;
16+
use Toolkit\Cli\ColorTag;
1617
use Toolkit\PhpUtil\PhpDoc;
1718
use Toolkit\StrUtil\Str;
1819

@@ -265,7 +266,7 @@ final public function showCommandList(): void
265266
}
266267

267268
$aliases = self::getCommandAliases($cmd);
268-
$desc .= $aliases ? Helper::wrapTag(' [alias: ' . \implode(',', $aliases) . ']', 'info') : '';
269+
$desc .= $aliases ? ColorTag::wrap(' [alias: ' . \implode(',', $aliases) . ']', 'info') : '';
269270
$commands[$cmd] = $desc;
270271
}
271272

src/Traits/ApplicationHelpTrait.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Inhere\Console\Component\Style\Style;
1212
use Inhere\Console\Face\CommandInterface;
1313
use Inhere\Console\Util\FormatUtil;
14-
use Inhere\Console\Util\Helper;
14+
use Toolkit\Cli\ColorTag;
1515

1616
/**
1717
* Trait ApplicationHelpTrait
@@ -34,7 +34,7 @@ public function showVersionInfo(): void
3434
$phpVersion = \PHP_VERSION;
3535

3636
if ($logoTxt = $this->getLogoText()) {
37-
$logo = Helper::wrapTag($logoTxt, $this->getLogoStyle());
37+
$logo = ColorTag::wrap($logoTxt, $this->getLogoStyle());
3838
}
3939

4040
/** @var \Inhere\Console\IO\Output $out */
@@ -135,7 +135,7 @@ public function showCommandList(): void
135135
/** @var \Inhere\Console\AbstractCommand $controller */
136136
$desc = $controller::getDescription() ?: $placeholder;
137137
$aliases = $this->getCommandAliases($name);
138-
$extra = $aliases ? Helper::wrapTag(
138+
$extra = $aliases ? ColorTag::wrap(
139139
' [alias: ' . \implode(',', $aliases) . ']',
140140
'info'
141141
) : '';
@@ -163,7 +163,7 @@ public function showCommandList(): void
163163
}
164164

165165
$aliases = $this->getCommandAliases($name);
166-
$extra = $aliases ? Helper::wrapTag(' [alias: ' . \implode(',', $aliases) . ']', 'info') : '';
166+
$extra = $aliases ? ColorTag::wrap(' [alias: ' . \implode(',', $aliases) . ']', 'info') : '';
167167
$commandArr[$name] = $desc . $extra;
168168
}
169169

src/Util/FormatUtil.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Inhere\Console\Util;
1010

11+
use Toolkit\Cli\ColorTag;
1112
use Toolkit\Sys\Sys;
1213

1314
/**
@@ -239,7 +240,7 @@ public static function spliceKeyValue(array $data, array $opts = []): string
239240

240241
if ($hasKey && $opts['keyMaxWidth']) {
241242
$key = \str_pad($key, $opts['keyMaxWidth'], ' ');
242-
$text .= Helper::wrapTag($key, $keyStyle) . $opts['sepChar'];
243+
$text .= ColorTag::wrap($key, $keyStyle) . $opts['sepChar'];
243244
}
244245

245246
// if value is array, translate array to string
@@ -265,7 +266,7 @@ public static function spliceKeyValue(array $data, array $opts = []): string
265266
}
266267

267268
$value = $hasKey && $opts['ucFirst'] ? \ucfirst($value) : $value;
268-
$text .= Helper::wrapTag($value, $opts['valStyle']) . "\n";
269+
$text .= ColorTag::wrap($value, $opts['valStyle']) . "\n";
269270
}
270271

271272
return $text;

src/Util/Helper.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,25 +93,6 @@ public static function commandSearch(string $command, array $map): void
9393

9494
}
9595

96-
/**
97-
* wrap a style tag
98-
* @param string $string
99-
* @param string $tag
100-
* @return string
101-
*/
102-
public static function wrapTag(string $string, string $tag): string
103-
{
104-
if (!$string) {
105-
return '';
106-
}
107-
108-
if (!$tag) {
109-
return $string;
110-
}
111-
112-
return "<$tag>$string</$tag>";
113-
}
114-
11596
/**
11697
* @param string $string
11798
* @param int $indent
@@ -184,7 +165,6 @@ public static function throwInvalidArgument(string $format, ...$args): void
184165
throw new \InvalidArgumentException(\sprintf($format, ...$args));
185166
}
186167

187-
188168
/**
189169
* @param string $optsStr
190170
*/

src/Util/Show.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Inhere\Console\Component\Style\Style;
1212
use Toolkit\Cli\Cli;
13+
use Toolkit\Cli\ColorTag;
1314
use Toolkit\StrUtil\Str;
1415
use Toolkit\StrUtil\StrBuffer;
1516
use Toolkit\Sys\Sys;
@@ -331,7 +332,7 @@ public static function padding(array $data, string $title = null, array $opts =
331332
return;
332333
}
333334

334-
$string = $title ? Helper::wrapTag(ucfirst($title), 'comment') . ":\n" : '';
335+
$string = $title ? ColorTag::wrap(ucfirst($title), 'comment') . ":\n" : '';
335336
$opts = array_merge([
336337
'char' => '.',
337338
'indent' => ' ',
@@ -343,7 +344,7 @@ public static function padding(array $data, string $title = null, array $opts =
343344
$paddingLen = $keyMaxLen > $opts['padding'] ? $keyMaxLen : $opts['padding'];
344345

345346
foreach ($data as $label => $value) {
346-
$value = Helper::wrapTag((string)$value, $opts['valueStyle']);
347+
$value = ColorTag::wrap((string)$value, $opts['valueStyle']);
347348
$string .= $opts['indent'] . str_pad($label, $paddingLen, $opts['char']) . " $value\n";
348349
}
349350

@@ -380,7 +381,7 @@ public static function aList($data, string $title = null, array $opts = [])
380381
// title
381382
if ($title) {
382383
$title = ucwords(trim($title));
383-
$string .= Helper::wrapTag($title, $opts['titleStyle']) . PHP_EOL;
384+
$string .= ColorTag::wrap($title, $opts['titleStyle']) . PHP_EOL;
384385
}
385386

386387
// handle item list
@@ -843,7 +844,7 @@ public static function table(array $data, string $title = 'Data Table', array $o
843844
foreach ($head as $index => $name) {
844845
$colMaxWidth = $info['columnMaxWidth'][$index];
845846
$name = \str_pad($name, $colMaxWidth, ' ');
846-
$name = Helper::wrapTag($name, $opts['headStyle']);
847+
$name = ColorTag::wrap($name, $opts['headStyle']);
847848
$headStr .= " {$name} {$colBorderChar}";
848849
}
849850

@@ -867,7 +868,7 @@ public static function table(array $data, string $title = 'Data Table', array $o
867868
foreach ((array)$row as $value) {
868869
$colMaxWidth = $info['columnMaxWidth'][$colIndex];
869870
$value = \str_pad($value, $colMaxWidth, ' ');
870-
$value = Helper::wrapTag($value, $opts['bodyStyle']);
871+
$value = ColorTag::wrap($value, $opts['bodyStyle']);
871872
$rowStr .= " {$value} {$colBorderChar}";
872873
$colIndex++;
873874
}
@@ -1452,7 +1453,7 @@ public static function color($message, string $style = 'info', $nl = true, array
14521453
{
14531454
$quit = isset($opts['quit']) ? (bool)$opts['quit'] : false;
14541455

1455-
return self::write(Helper::wrapTag($message, $style), $nl, $quit, $opts);
1456+
return self::write(ColorTag::wrap($message, $style), $nl, $quit, $opts);
14561457
}
14571458

14581459
/**
@@ -1493,6 +1494,6 @@ public static function getBlockMethods($onlyKey = true): array
14931494
*/
14941495
public static function getStyle(): Style
14951496
{
1496-
return Style::create();
1497+
return Style::instance();
14971498
}
14981499
}

0 commit comments

Comments
 (0)