Skip to content

Commit 321d252

Browse files
committed
up: update some output format methods
1 parent 9cc675a commit 321d252

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

src/Component/Formatter/Title.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static function show(string $title, array $opts = []): void
4343
// list($sW, $sH) = Helper::getScreenSize();
4444
$width = (int)$opts['width'];
4545
$char = trim($opts['char']);
46-
$indent = (int)$opts['indent'] >= 0 ? $opts['indent'] : 2;
46+
$indent = (int)$opts['indent'] >= 0 ? $opts['indent'] : 0;
4747

4848
$indentStr = '';
4949
if ($indent > 0) {
@@ -60,18 +60,19 @@ public static function show(string $title, array $opts = []): void
6060
}
6161

6262
// title position
63+
$titleIndent = '';
6364
if ($tLength >= $width) {
6465
$titleIndent = Str::pad(self::CHAR_SPACE, $indent, self::CHAR_SPACE);
6566
} elseif ($opts['titlePos'] === self::POS_RIGHT) {
6667
$titleIndent = Str::pad(self::CHAR_SPACE, ceil($width - $tLength) + $indent, self::CHAR_SPACE);
6768
} elseif ($opts['titlePos'] === self::POS_MIDDLE) {
6869
$titleIndent = Str::pad(self::CHAR_SPACE, ceil(($width - $tLength) / 2) + $indent, self::CHAR_SPACE);
69-
} else {
70+
} elseif ($indent > 0) {
7071
$titleIndent = Str::pad(self::CHAR_SPACE, $indent, self::CHAR_SPACE);
7172
}
7273

7374
$titleText = ColorTag::wrap($title, $opts['titleStyle']);
74-
$titleLine = "$titleIndent{$titleText}\n";
75+
$titleLine = "$titleIndent$titleText\n";
7576

7677
$border = $indentStr . Str::pad($char, $width, $char);
7778

src/Concern/FormatOutputAwareTrait.php

+18-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
use Toolkit\Stdlib\Php;
1515
use function array_merge;
1616
use function count;
17+
use function implode;
1718
use function json_encode;
19+
use const PHP_EOL;
1820

1921
/**
2022
* Class FormatOutputAwareTrait
@@ -45,11 +47,22 @@ public function write($messages, $nl = true, $quit = false, array $opts = []): i
4547
//
4648
//
4749
// }
48-
//
49-
// public function echo(...$args): void
50-
// {
51-
// Console::printf($format, ...$args);
52-
// }
50+
51+
/**
52+
* @param ...$args
53+
*/
54+
public function echo(...$args): void
55+
{
56+
echo count($args) > 1 ? implode(' ', $args) : $args;
57+
}
58+
59+
/**
60+
* @param ...$args
61+
*/
62+
public function echoln(...$args): void
63+
{
64+
echo (count($args) > 1 ? implode(' ', $args) : $args), PHP_EOL;
65+
}
5366

5467
/**
5568
* @param string $format

src/IO/Input/StreamInput.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
use InvalidArgumentException;
1414
use Toolkit\FsUtil\File;
1515
use Toolkit\Stdlib\OS;
16+
use function fclose;
17+
use function fopen;
1618
use function fwrite;
19+
use function stream_get_contents;
1720
use function stream_get_meta_data;
21+
use function stream_set_blocking;
1822
use function strpos;
1923
use const STDIN;
2024

@@ -40,11 +44,13 @@ public function __construct($stream = STDIN)
4044
}
4145

4246
/**
47+
* @param bool $blocking
48+
*
4349
* @return string
4450
*/
45-
public function readAll(): string
51+
public function readAll(bool $blocking = true): string
4652
{
47-
return File::streamReadAll($this->stream);
53+
return File::streamReadAll($this->stream, $blocking);
4854
}
4955

5056
/**

0 commit comments

Comments
 (0)