Skip to content

Commit 7ca931a

Browse files
committed
some update for splitLine
1 parent 3c3d925 commit 7ca931a

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

examples/Controllers/HomeController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,12 @@ public function titleCommand()
324324
*/
325325
public function splitLineCommand()
326326
{
327+
$this->output->splitLine('', '=', $this->input->getSameOpt(['w', 'width'], 0));
327328
$this->output->splitLine('split Line', '-', $this->input->getSameOpt(['w', 'width'], 0));
328329

329330
$this->output->splitLine('split 中文 Line', '-', $this->input->getSameOpt(['w', 'width'], 0));
330331

332+
331333
return 0;
332334
}
333335

@@ -357,13 +359,17 @@ public function panelCommand()
357359
$data = [
358360
'application version' => '1.2.0',
359361
'system version' => '5.2.3',
360-
'see help' => 'please use php bin/app -h',
362+
'key' => 'value ...',
361363
'a only value message text',
362364
];
363365

364366
Show::panel($data, 'panel show', [
365367
'borderChar' => '*'
366368
]);
369+
370+
Show::panel($data, 'panel show', [
371+
'borderChar' => '='
372+
]);
367373
}
368374

369375
/**

src/Utils/Show.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,23 @@ public static function __callStatic($method, array $args = [])
188188
* @param string $title
189189
* @param string $char
190190
* @param int $width
191+
* @return int
191192
*/
192193
public static function splitLine(string $title, string $char = '-', int $width = 0)
193194
{
194195
if ($width <= 0) {
195196
list($width,) = CliUtil::getScreenSize();
197+
$width -= 2;
198+
}
199+
200+
if (!$title) {
201+
return self::write(str_repeat($char, $width));
196202
}
197203

198-
$strLen = ceil(($width - Helper::strLen($title) + 2) / 2);
204+
$strLen = ceil(($width - Helper::strLen($title) - 2) / 2);
199205
$padStr = $strLen > 0 ? str_repeat($char, $strLen) : '';
200206

201-
self::write($padStr . ' ' . ucwords($title) . ' ' . $padStr);
207+
return self::write($padStr . ' ' . ucwords($title) . ' ' . $padStr);
202208
}
203209

204210
/**

0 commit comments

Comments
 (0)