Skip to content

Commit

Permalink
Tag console highlighter
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Sep 20, 2024
1 parent 759134f commit 0266b68
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 35 deletions.
2 changes: 2 additions & 0 deletions src/Tempest/Console/src/Commands/TailDebugLogCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Tempest\Console\ConsoleCommand;
use Tempest\Console\Highlight\VarExportLanguage\VarExportLanguage;
use Tempest\Console\Output\TailReader;
use Tempest\Container\Tag;
use Tempest\Highlight\Highlighter;
use Tempest\Log\LogConfig;

Expand All @@ -16,6 +17,7 @@
public function __construct(
private Console $console,
private LogConfig $logConfig,
#[Tag('console')]
private Highlighter $highlighter,
) {
}
Expand Down
2 changes: 2 additions & 0 deletions src/Tempest/Console/src/Commands/TailProjectLogCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Tempest\Console\ConsoleCommand;
use Tempest\Console\Highlight\LogLanguage\LogLanguage;
use Tempest\Console\Output\TailReader;
use Tempest\Container\Tag;
use Tempest\Highlight\Highlighter;
use Tempest\Log\Channels\AppendLogChannel;
use Tempest\Log\LogConfig;
Expand All @@ -17,6 +18,7 @@
public function __construct(
private Console $console,
private LogConfig $logConfig,
#[Tag('console')]
private Highlighter $highlighter,
) {
}
Expand Down
2 changes: 2 additions & 0 deletions src/Tempest/Console/src/Commands/TailServerLogCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Tempest\Console\ConsoleCommand;
use Tempest\Console\Highlight\LogLanguage\LogLanguage;
use Tempest\Console\Output\TailReader;
use Tempest\Container\Tag;
use Tempest\Highlight\Highlighter;
use Tempest\Log\LogConfig;

Expand All @@ -16,6 +17,7 @@
public function __construct(
private Console $console,
private LogConfig $logConfig,
#[Tag('console')]
private Highlighter $highlighter,
) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Tempest\Console\Console;
use Tempest\Console\Input\ConsoleArgumentBag;
use Tempest\Container\Tag;
use Tempest\Core\ExceptionHandler;
use Tempest\Highlight\Escape;
use Tempest\Highlight\Highlighter;
Expand All @@ -15,6 +16,7 @@
{
public function __construct(
private Console $console,
#[Tag('console')]
private Highlighter $highlighter,
private ConsoleArgumentBag $argumentBag,
) {
Expand Down
2 changes: 2 additions & 0 deletions src/Tempest/Console/src/GenericConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Tempest\Console\Components\InteractiveComponentRenderer;
use Tempest\Console\Exceptions\UnsupportedComponent;
use Tempest\Console\Highlight\TempestConsoleLanguage\TempestConsoleLanguage;
use Tempest\Container\Tag;
use Tempest\Highlight\Highlighter;

final class GenericConsole implements Console
Expand All @@ -29,6 +30,7 @@ final class GenericConsole implements Console
public function __construct(
private readonly OutputBuffer $output,
private readonly InputBuffer $input,
#[Tag('console')]
private readonly Highlighter $highlighter,
private readonly ExecuteConsoleCommand $executeConsoleCommand,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use Tempest\Container\Singleton;
use Tempest\Highlight\Highlighter;

final readonly class HighlighterInitializer implements Initializer
final readonly class ConsoleHighlighterInitializer implements Initializer
{
#[Singleton]
#[Singleton(tag: 'console')]
public function initialize(Container $container): Highlighter
{
return new Highlighter(new TempestTerminalTheme());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,6 @@
{
use IsTagInjection;

// public function parse(string $content, Highlighter $highlighter): ParsedInjection
// {
// $lines = explode(PHP_EOL, $content);
//
// if (count($lines) > 1) {
// $comment = implode(
// PHP_EOL,
// [
// '/*',
// ...array_map(
// fn (string $line) => " * {$line}",
// $lines,
// ),
// ' */',
// ],
// );
// } else {
// $comment = '/* ' . $lines[0] . ' */';
// }
//
// $comment = str_replace('/* *', '/*', $comment);
//
// return $comment;
//
// return $this->parseContent($content, $highlighter);
// }

public function getTag(): string
{
return 'comment';
Expand Down
2 changes: 1 addition & 1 deletion src/Tempest/Console/src/Testing/ConsoleTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function call(string|Closure|array $command): self
$console = new GenericConsole(
output: $memoryOutputBuffer,
input: $memoryInputBuffer,
highlighter: $clone->container->get(Highlighter::class),
highlighter: $clone->container->get(Highlighter::class, 'console'),
executeConsoleCommand: $clone->container->get(ExecuteConsoleCommand::class),
);

Expand Down
3 changes: 1 addition & 2 deletions src/Tempest/Support/src/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ final class ArrayHelper implements Iterator, ArrayAccess, Serializable, Countabl

public function __construct(
mixed $input = [],
)
{
) {
if (is_array($input)) {
$this->array = $input;
} elseif ($input instanceof self) {
Expand Down
4 changes: 3 additions & 1 deletion src/Tempest/Support/src/InvalidMapWithKeysUsage.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Tempest\Support;

use Exception;
Expand All @@ -10,4 +12,4 @@ public function __construct()
{
parent::__construct('Invalid usage of mapWithKeys, the callback must return a generator: `fn (mixed $value, mixed $key) => yield $key => $value`');
}
}
}
3 changes: 1 addition & 2 deletions src/Tempest/Support/tests/ArrayHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
namespace Tempest\Support\Tests;

use PHPUnit\Framework\TestCase;
use Tempest\Support\InvalidMapWithKeysUsage;
use function Tempest\Support\arr;
use Tempest\Support\ArrayHelper;
use Tempest\Support\InvalidMapWithKeysUsage;

/**
* @internal
* @small
*/
final class ArrayHelperTest extends TestCase
{
Expand Down

0 comments on commit 0266b68

Please sign in to comment.