-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Félix Dorn
committed
Mar 14, 2024
1 parent
b0d9576
commit 9d0e1c8
Showing
15 changed files
with
293 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Felix\Tin\Outputs; | ||
|
||
use Felix\Tin\Contracts\OutputInterface; | ||
use Felix\Tin\Contracts\ThemeInterface; | ||
use Felix\Tin\Enums\TokenType; | ||
use Felix\Tin\Line; | ||
|
||
class CallableOutput implements OutputInterface | ||
{ | ||
/** @var callable */ | ||
private $transformer; | ||
|
||
public function __construct( | ||
protected ThemeInterface $theme, | ||
callable $transformer | ||
) { | ||
$this->transformer = $transformer; | ||
} | ||
|
||
public function transform(TokenType $type, string $value): string | ||
{ | ||
return $value; | ||
} | ||
|
||
public function transformLine(Line $line): ?string | ||
{ | ||
return ($this->transformer)($line); | ||
} | ||
|
||
public function theme(): ThemeInterface | ||
{ | ||
return $this->theme; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Felix\Tin\Outputs; | ||
|
||
use Felix\Tin\Contracts\OutputInterface; | ||
use Felix\Tin\Contracts\ThemeInterface; | ||
use Felix\Tin\Enums\TokenType; | ||
use Felix\Tin\Line; | ||
|
||
readonly class HtmlOutput implements OutputInterface | ||
{ | ||
public function __construct( | ||
protected ThemeInterface $theme, | ||
) { | ||
} | ||
|
||
public function transform(TokenType $type, string $value): string | ||
{ | ||
return sprintf( | ||
'<span style="color:rgb(%s);">%s</span>', | ||
str_replace(';', ',', $this->theme->color($type)), | ||
$value | ||
); | ||
} | ||
|
||
public function theme(): ThemeInterface | ||
{ | ||
return $this->theme; | ||
} | ||
|
||
public function transformLine(Line $line): string | ||
{ | ||
return sprintf( | ||
'<div class="line"><span class="line-number">%s</span>%s</div>', | ||
$line->number, $line->toString() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.