Skip to content

Commit a802922

Browse files
committed
Merge branch 'review-console'
2 parents 68987d8 + f6419ce commit a802922

File tree

73 files changed

+2268
-1969
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2268
-1969
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
'fully_qualified_strict_types' => true,
4545
'is_null' => true,
4646
'native_constant_invocation' => ['include' => $customTokens],
47+
'new_with_parentheses' => ['anonymous_class' => false],
4748
'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
4849
'no_unneeded_import_alias' => true,
4950
'no_unused_imports' => true,

docs/Console.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ called, preferably while bootstrapping your application.
4747
### Output methods
4848

4949
<!-- prettier-ignore -->
50-
| Method | Message level | Default prefix | Default output target |
51-
| --------------- | --------------------- | -------------- | ------------------------- |
52-
| `error[Once]()` | `LEVEL_ERROR` = `3` | ` ! ` | `STDERR` |
53-
| `warn[Once]()` | `LEVEL_WARNING` = `4` | ` ^ ` | `STDERR` |
54-
| `info[Once]()` | `LEVEL_NOTICE` = `5` | `` | `STDOUT` |
55-
| `log[Once]()` | `LEVEL_INFO` = `6` | ` - ` | `STDOUT` |
56-
| `debug[Once]()` | `LEVEL_DEBUG` = `7` | ` : ` | `STDOUT` (if `DEBUG` set) |
57-
| `group()`[^2] | `LEVEL_NOTICE` = `5` | ` » ` | `STDOUT` |
58-
| `logProgress()` | `LEVEL_INFO` = `6` | ` ` | `STDOUT` |
50+
| Method | Message level | Default prefix | Default output target |
51+
| --------------- | --------------------- | ---------------- | ------------------------- |
52+
| `error[Once]()` | `LEVEL_ERROR` = `3` | ` ! ` | `STDERR` |
53+
| `warn[Once]()` | `LEVEL_WARNING` = `4` | ` ^ ` | `STDERR` |
54+
| `info[Once]()` | `LEVEL_NOTICE` = `5` | `` | `STDOUT` |
55+
| `log[Once]()` | `LEVEL_INFO` = `6` | ` - ` | `STDOUT` |
56+
| `debug[Once]()` | `LEVEL_DEBUG` = `7` | ` : ` | `STDOUT` (if `DEBUG` set) |
57+
| `group()`[^2] | `LEVEL_NOTICE` = `5` | ` » ` | `STDOUT` |
58+
| `logProgress()` | `LEVEL_INFO` = `6` | ` ` (spinner) | `STDOUT` |
5959

6060
[^1]:
6161
Actually a facade for [ConsoleInterface][], which is backed by a shared
@@ -75,10 +75,23 @@ The following Markdown-like syntax is supported in [Console][] messages:
7575
| "Bold" | `__` text `__`<br>`**` text `**` | **Bold + default colour** | `__command__`<br>`**command**` |
7676
| "Italic" | `_` text `_`<br>`*` text `*` | _Secondary colour_ | `_argument_`<br>`*argument*` |
7777
| "Underline" | `<` text `>` | _<u>Secondary colour + underline</u>_ | `<argument>` |
78-
| Low priority | `~~` text `~~` | <small>Dim</small> | `~~/path/to/script.php:42~~` |
78+
| Low priority | `~~` text `~~` | <small>Faint</small> | `~~/path/to/script.php:42~~` |
7979
| Inline code | `` ` `` text `` ` `` | <code>Bold</code> | `` The input format can be specified using the `-f/--from` option. `` |
8080
| Code block | ` ``` `<br>text<br>` ``` ` | <pre><code>Unchanged</code></pre> | <pre><code>\`\`\`&#10;$baz = Foo::bar();&#10;\`\`\`</code></pre> |
8181

82+
Paragraphs outside code blocks are wrapped to the width reported by the target,
83+
and backslash-escaped punctuation characters and line breaks are preserved.
84+
85+
Escaped line breaks may have a leading space, so the following are equivalent:
86+
87+
```
88+
Text with a \
89+
hard line break.
90+
91+
Text with a\
92+
hard line break.
93+
```
94+
8295
[Application]:
8396
https://salient-labs.github.io/toolkit/Salient.Container.Application.html
8497
[CliApplication]:

scripts/delete-covers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
}
7777

7878
if ($replaced) {
79-
Console::printOut('', Console::LEVEL_INFO);
79+
Console::printStdio('', Console::LEVEL_INFO);
8080
}
8181

8282
Console::summary(Inflect::format(

scripts/generate.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ function generated($commandOrFile): void
285285
if (!$debug) {
286286
foreach (Console::getTargets() as $target) {
287287
Console::deregisterTarget($target);
288+
$target->close();
288289
}
289290
Console::registerTarget($mockTarget = new MockTarget());
290291
}
@@ -294,6 +295,7 @@ function generated($commandOrFile): void
294295
$content = ob_get_clean();
295296
if ($mockTarget) {
296297
Console::deregisterTarget($mockTarget);
298+
$mockTarget->close();
297299
Console::registerStderrTarget();
298300
}
299301
if ($result !== $exitStatus) {

src/Toolkit/Cli/CliApplication.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace Salient\Cli;
44

55
use Salient\Cli\Exception\CliInvalidArgumentsException;
6-
use Salient\Console\Format\ConsoleFormatter as Formatter;
7-
use Salient\Console\Format\ConsoleManPageFormat;
8-
use Salient\Console\Format\ConsoleMarkdownFormat;
6+
use Salient\Console\Format\Formatter;
7+
use Salient\Console\Format\ManPageFormat;
8+
use Salient\Console\Format\MarkdownFormat;
99
use Salient\Container\Application;
1010
use Salient\Contract\Cli\CliApplicationInterface;
1111
use Salient\Contract\Cli\CliCommandInterface;
@@ -336,7 +336,7 @@ public function run()
336336
) {
337337
$usage = $this->getUsage($name, $node);
338338
if ($usage !== null) {
339-
Console::printOut($usage);
339+
Console::printStdio($usage);
340340
}
341341
$this->LastExitStatus =
342342
$arg === null
@@ -419,7 +419,7 @@ public function run()
419419
&& $name !== null
420420
&& ($usage = $this->getUsage($name, $node)) !== null
421421
) {
422-
Console::printOut("\n" . $usage);
422+
Console::printStdio("\n" . $usage);
423423
}
424424
$this->LastExitStatus = 1;
425425
return $this;
@@ -464,12 +464,12 @@ private function generateHelp(string $name, $node, int $target, string ...$args)
464464

465465
switch ($target) {
466466
case CliHelpTarget::MARKDOWN:
467-
$formats = ConsoleMarkdownFormat::getTagFormats();
467+
$formatter = MarkdownFormat::getFormatter(fn() => 80);
468468
$collapseSynopsis = Get::boolean($args[0] ?? null);
469469
break;
470470

471471
case CliHelpTarget::MAN_PAGE:
472-
$formats = ConsoleManPageFormat::getTagFormats();
472+
$formatter = ManPageFormat::getFormatter(fn() => 80);
473473
$progName = $this->getProgramName();
474474
printf(
475475
'%% %s(%d) %s | %s%s',
@@ -485,7 +485,6 @@ private function generateHelp(string $name, $node, int $target, string ...$args)
485485
throw new InvalidArgumentException(sprintf('Invalid CliHelpTarget: %d', $target));
486486
}
487487

488-
$formatter = new Formatter($formats, null, fn(): int => 80);
489488
$style = new CliHelpStyle($target, 80, $formatter);
490489

491490
if ($collapseSynopsis !== null) {

src/Toolkit/Cli/CliCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Salient\Cli\Exception\CliInvalidArgumentsException;
66
use Salient\Cli\Exception\CliUnknownValueException;
7-
use Salient\Console\Format\ConsoleFormatter as Formatter;
7+
use Salient\Console\Format\Formatter;
88
use Salient\Contract\Cli\CliApplicationInterface;
99
use Salient\Contract\Cli\CliCommandInterface;
1010
use Salient\Contract\Cli\CliHelpSectionName;
@@ -380,7 +380,7 @@ final public function getHelp(?CliHelpStyleInterface $style = null): array
380380
);
381381
if (
382382
$booleanValue
383-
|| mb_strlen($formatter->getWrapAfterApply()
383+
|| mb_strlen($formatter->wrapsAfterFormatting()
384384
? $formatter->format($indent . $_line)
385385
: Formatter::removeTags($indent . $_line)) <= ($width ?: 76)
386386
) {
@@ -512,7 +512,7 @@ final public function getSynopsis(?CliHelpStyleInterface $style = null): string
512512
$width = $style->getWidth();
513513

514514
// Synopsis newlines are hard line breaks, so wrap without markup
515-
$formatter = $style->getFormatter()->withWrapAfterApply(false);
515+
$formatter = $style->getFormatter()->withWrapAfterFormatting(false);
516516

517517
$name = $b . $this->getNameWithProgram() . $b;
518518
$full = $this->getOptionsSynopsis($style, $collapsed);

src/Toolkit/Cli/CliHelpStyle.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
namespace Salient\Cli;
44

5-
use Salient\Console\Format\ConsoleFormatter as Formatter;
6-
use Salient\Console\Format\ConsoleLoopbackFormat as LoopbackFormat;
7-
use Salient\Console\Format\ConsoleManPageFormat as ManPageFormat;
8-
use Salient\Console\Format\ConsoleMarkdownFormat as MarkdownFormat;
5+
use Salient\Console\Format\Formatter;
6+
use Salient\Console\Format\LoopbackFormat;
7+
use Salient\Console\Format\ManPageFormat;
8+
use Salient\Console\Format\MarkdownFormat;
99
use Salient\Contract\Cli\CliHelpSectionName;
1010
use Salient\Contract\Cli\CliHelpStyleInterface;
1111
use Salient\Contract\Cli\CliHelpTarget;
1212
use Salient\Contract\Cli\CliOptionVisibility;
13-
use Salient\Contract\Console\Format\ConsoleFormatterInterface as FormatterInterface;
13+
use Salient\Contract\Console\Format\FormatterInterface;
1414
use Salient\Core\Concern\ImmutableTrait;
1515
use Salient\Core\Facade\Console;
1616
use Salient\Utility\Regex;
@@ -69,7 +69,7 @@ public function __construct(
6969
$this->Bold = '__';
7070
$this->Width ??= self::getConsoleWidth();
7171
$this->Margin = 4;
72-
$this->Formatter = $formatter ?? Console::getFormatter();
72+
$this->Formatter = $formatter ?? Console::getTtyTarget()->getFormatter();
7373
break;
7474

7575
case CliHelpTarget::MARKDOWN:
@@ -267,7 +267,7 @@ public function maybeEscapeTags(string $string): string
267267

268268
public static function getConsoleWidth(): ?int
269269
{
270-
$width = Console::getWidth();
270+
$width = Console::getTtyTarget()->getWidth();
271271

272272
return $width === null
273273
? null

0 commit comments

Comments
 (0)