tin is a PHP code highlighter for the terminal.

Overview

tin

tin is a PHP code highlighter for the terminal.

Tests Formats Version Total Downloads License

Installation

Requires PHP 8.0.0+

You can install the package via composer:

composer require felixdorn/tin

🔞 Screenshots

A piece of code highlighted using tin

Yes, this comes from a terminal.

Usage



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

$theme = new JetbrainsDark();
$tin = new Tin($theme);

echo $tin->highlight(");

Customizing the output

Apart from using a custom theme to change the colors, you have complete control over the highlighting proccess.

is(";")) { return null; } return $token->text; } ) ">
use Felix\Tin\Token;

$tin->process(
    $code,
    function(Token $token, Token $lastToken): ?string  {
        // won't print any of the ";" tokens
        if ($token->is(";")) {
           return null;
        }
        
        return $token->text;
    }
)

Last token represents the last token in the input code, it is very useful as you can then get the number of lines in the code with $lastToken->line to properly indent line numbers for example.

If you return null from the callback, the token will be skipped.

Themes

Creating a theme

You need to extend Felix\Tin\Themes\Theme and set the colors to whatever you want.

The color are RGB values separated by a ;.

use Felix\Tin\Themes\Theme;

class OneDark extends Theme
{
    public string $keyword        = '199;120;221';
    public string $variable       = '224;107;116';
    public string $comment        = '91;98;110';
    public string $default        = '171;178;191';
    public string $string         = '152;195;121';
    public string $function       = '98;174;239';
    public string $number         = '229;192;122';
    public string $attribute      = '98;174;239';
    public string $namedParameter = '98;174;239';
}

Future

  • PHPDoc
  • Various outputs (cli / web)
  • grayscale theme
  • better themes (will also boost performances a lot!!)

Known Issues

Named parameters are simply ignored by the built-in PHP parser which means that if you're named parameter is also a keyword such as for, default. The highlighter won't pick up on it and will highlight it as a keyword rather than a named parameter.

There is no solution to that problem unless we implement our own parser (no) or the parser gets fixed,

Testing

composer test

tin was created by FĂ©lix Dorn under the MIT license.

You might also like...
A REPL for PHP

PsySH PsySH is a runtime developer console, interactive debugger and REPL for PHP. Learn more at psysh.org and in the manual. PsySH manual đź’ľ Installa

CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due

PHP Cron Expression Parser NOTE This fork has been deprecated and development moved to https://github.com/dragonmantank/cron-expression. More informat

A tiny REPL for PHP

Boris A tiny, but robust REPL for PHP. Announcement: I'm looking to add one or two additional collaborators with commit access. If you are actively in

đź–Ą  Build beautiful PHP CLI menus. Simple yet Powerful. Expressive DSL.
đź–Ą Build beautiful PHP CLI menus. Simple yet Powerful. Expressive DSL.

Contents Minimum Requirements Installation Upgrading Usage Quick Setup Examples API Appearance Menu Title Colour Width Padding Margin Borders Exit But

An Elegant CLI Library for PHP

Commando An Elegant PHP CLI Library Commando is a PHP command line interface library that beautifies and simplifies writing PHP scripts intended for c

Lovely PHP wrapper for using the command-line

ShellWrap What is it? It's a beautiful way to use powerful Linux/Unix tools in PHP. Easily and logically pipe commands together, capture errors as PHP

Cilex a lightweight framework for creating PHP CLI scripts inspired by Silex

Cilex, a simple Command Line Interface framework Cilex is a simple command line application framework to develop simple tools based on Symfony2 compon

A powerful command line application framework for PHP. It's an extensible, flexible component, You can build your command-based application in seconds!
A powerful command line application framework for PHP. It's an extensible, flexible component, You can build your command-based application in seconds!

CLIFramework CLIFramework is a command-line application framework, for building flexiable, simple command-line applications. Commands and Subcommands

[ABANDONED] PHP library for executing commands on multiple remote machines, via SSH
[ABANDONED] PHP library for executing commands on multiple remote machines, via SSH

#Shunt Inspired by Ruby's Capistrano, Shunt is PHP library for executing commands on multiple remote machines, via SSH. Specifically, this library was

Releases(1.2.2)
Owner
Felix Dorn
Felix Dorn
PHP's best friend for the terminal.

Running PHP from the command line? CLImate is your new best bud. CLImate allows you to easily output colored text, special formats, and more. Installa

The League of Extraordinary Packages 1.8k Dec 30, 2022
I gues i tried to make a shell that's looks like a terminal in single php file

php-shell-gui Terms of service This tool can only be used for legal purposes. You take full responsibility for any actions performed using this. The o

Squar3 4 Aug 23, 2022
Create a simple todo-list application with the basic PHP programming language implemented in the terminal

PHP-DASAR---simple-todo-list-app-with-terminal create a simple todo-list application with the basic PHP programming language implemented in the termin

Ahmad Wali Alchalidi 2 Sep 7, 2022
Render the symfony profiler toolbar in your terminal.

sourceability/console-toolbar-bundle Render the symfony profiler toolbar in your terminal. Each panel links to the corresponding web profiler page.

null 49 Nov 8, 2022
Hentai Bash - This is the core of Hentai Terminal, responsible for the basic functions and commands

Hentai Bash - This is the core of Hentai Terminal, responsible for the basic functions and commands. It is mainly used for writing and executing commands.

Hentai Group 1 Jan 26, 2022
A command line code generator for Drupal.

Drupal Code Generator A command line code generator for Drupal. Installation Download the latest stable release of the code generator.

Ivan 227 Dec 14, 2022
A tool to generate boilerplate code, interact with and debug Drupal.

Table of Contents generated with DocToc Drupal Console Required PHP version Drupal Console documentation Download Drupal Console Run Drupal Console Co

Hecho en Drupal 929 Jan 5, 2023
A command line code generator for Drupal

Drupal Code Generator A command line code generator for Drupal.

Ivan 227 Dec 14, 2022
PHP Reverse Shell > reverse-shell.php

PHP Reverse Shell > reverse-shell.php PHP Cmd Shell > cmd.php JPG cmd Shell > cmd.jpg /etc/passwd Pulling Shell > etc-passwd.php Configuration Pulling

Dark-Network 5 Feb 24, 2022
Web Shell Detector – is a php script that helps you find and identify php/cgi(perl)/asp/aspx shells.

Web Shell Detector – is a php script that helps you find and identify php/cgi(perl)/asp/aspx shells. Web Shell Detector has a “web shells” signature database that helps to identify “web shell” up to 99%. By using the latest javascript and css technologies, web shell detector has a light weight and friendly interface.

Maxim 763 Dec 27, 2022