1111use Inhere \Console \Component \MessageFormatter ;
1212use Inhere \Console \Console ;
1313use Inhere \Console \Util \FormatUtil ;
14+ use Toolkit \Stdlib \Str ;
1415use Toolkit \Stdlib \Str \StrBuffer ;
1516use function array_filter ;
1617use function array_merge ;
2021use function is_numeric ;
2122use function mb_strlen ;
2223use function rtrim ;
23- use function str_pad ;
2424use function strip_tags ;
2525use function trim ;
2626use function ucwords ;
@@ -117,7 +117,8 @@ public static function show($data, string $title = 'Information Panel', array $o
117117 foreach ($ data as $ label => $ value ) {
118118 // label exists
119119 if (!is_numeric ($ label )) {
120- $ width = mb_strlen ($ label , 'UTF-8 ' );
120+ $ width = Str::len2 ($ label , 'UTF-8 ' );
121+
121122 $ labelMaxWidth = $ width > $ labelMaxWidth ? $ width : $ labelMaxWidth ;
122123 }
123124
@@ -158,16 +159,17 @@ public static function show($data, string $title = 'Information Panel', array $o
158159
159160 // output title
160161 if ($ title ) {
161- $ title = ucwords ($ title );
162+ $ title = ucwords ($ title );
163+
162164 $ titleLength = mb_strlen ($ title , 'UTF-8 ' );
163165 $ panelWidth = $ panelWidth > $ titleLength ? $ panelWidth : $ titleLength ;
164- $ indentSpace = str_pad (' ' , ceil ($ panelWidth / 2 ) - ceil ($ titleLength / 2 ) + 2 * 2 , ' ' );
166+ $ indentSpace = Str:: pad (' ' , ceil ($ panelWidth / 2 ) - ceil ($ titleLength / 2 ) + 2 * 2 , ' ' );
165167 Console::write (" {$ indentSpace }<bold> {$ title }</bold> " );
166168 }
167169
168170 // output panel top border
169171 if ($ borderChar ) {
170- $ border = str_pad ($ borderChar , $ panelWidth + (3 * 3 ), $ borderChar );
172+ $ border = Str:: pad ($ borderChar , $ panelWidth + (3 * 3 ), $ borderChar );
171173 Console::write (' ' . $ border );
172174 }
173175
@@ -215,7 +217,8 @@ public function format(): string
215217 foreach ($ data as $ label => $ value ) {
216218 // label exists
217219 if (!is_numeric ($ label )) {
218- $ width = mb_strlen ($ label , 'UTF-8 ' );
220+ $ width = Str::len2 ($ label , 'UTF-8 ' );
221+
219222 $ labelMaxWidth = $ width > $ labelMaxWidth ? $ width : $ labelMaxWidth ;
220223 }
221224
@@ -257,13 +260,13 @@ public function format(): string
257260 $ title = ucwords ($ title );
258261 $ titleLength = mb_strlen ($ title , 'UTF-8 ' );
259262 $ panelWidth = $ panelWidth > $ titleLength ? $ panelWidth : $ titleLength ;
260- $ indentSpace = str_pad (' ' , ceil ($ panelWidth / 2 ) - ceil ($ titleLength / 2 ) + 2 * 2 , ' ' );
263+ $ indentSpace = Str:: pad (' ' , ceil ($ panelWidth / 2 ) - ceil ($ titleLength / 2 ) + 2 * 2 , ' ' );
261264 $ buffer ->write (" {$ indentSpace }<bold> {$ title }</bold> \n" );
262265 }
263266
264267 // output panel top border
265268 if ($ topBorder = $ this ->titleBorder ) {
266- $ border = str_pad ($ topBorder , $ panelWidth + (3 * 3 ), $ topBorder );
269+ $ border = Str:: pad ($ topBorder , $ panelWidth + (3 * 3 ), $ topBorder );
267270 $ buffer ->write (' ' . $ border . PHP_EOL );
268271 }
269272
@@ -280,7 +283,7 @@ public function format(): string
280283
281284 // output panel bottom border
282285 if ($ footBorder = $ this ->footerBorder ) {
283- $ border = str_pad ($ footBorder , $ panelWidth + (3 * 3 ), $ footBorder );
286+ $ border = Str:: pad ($ footBorder , $ panelWidth + (3 * 3 ), $ footBorder );
284287 $ buffer ->write (' ' . $ border . PHP_EOL );
285288 }
286289
0 commit comments