PHP code example of felixdorn / tin

1. Go to this page and download the library: Download felixdorn/tin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

felixdorn / tin example snippets




use Felix\Tin\Themes\JetbrainsDark;
use Felix\Tin\Tin;

echo Tin::from(JetbrainsDark::class, $ansi = true)->highlight("\n\necho 'Hello world';\n");

$tin = new \Felix\Tin\Tin(
    new \Felix\Tin\Outputs\AnsiOutput()
)

$tin = new \Felix\Tin\Tin(
    new \Felix\Tin\Outputs\HtmlOutput()
)

$tin = new \Felix\Tin\Tin(
    new \Felix\Tin\Outputs\CallableOutput(
        new \Felix\Tin\Themes\OneDark(),
        fn (\Felix\Tin\Line $line) => $line->number % 2 ? 
            (new \Felix\Tin\Outputs\AnsiOutput())->transformLine($line) :
             null
    )
)

use Felix\Tin\Contracts\ThemeInterface;
use Felix\Tin\Enums\TokenType;

class OneDark extends ThemeInterface
{
    /** {@inheritDoc} */
    public function color(TokenType $type): string
    {
        return match ($type) {
            TokenType::Keyword  => '199;120;221',
            TokenType::Variable => '224;107;116',
            TokenType::Comment  => '91;98;110',
            TokenType::String   => '152;195;121',
            TokenType::Function, TokenType::NamedParameter, TokenType::Attribute => '98;174;239',
            TokenType::Number, TokenType::Html => '229;192;122',
            default => '171;178;191',
        };
    }
}