Skip to content

Library, which allows you to highlight your PHP code in console (terminal)

Notifications You must be signed in to change notification settings

mkgor/highlighter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

Highlighter

Library, which allows you to highlight your PHP code in terminal

Installation

Installation via composer:

composer require mkgor/highlighter

Printing whole file

<?php

require_once "vendor/autoload.php";

$highlighter = new \Highlighter\Highlighter();

echo $highlighter->getWholeFile(__FILE__);

Result

Result

Printing code snippet (and highlighting specified line)

<?php

require_once "vendor/autoload.php";

$highlighter = new \Highlighter\Highlighter();

echo $highlighter->getSnippet(__FILE__, 3);

Result

Result

Printing code snippet with specified lines

<?php

require_once "vendor/autoload.php";

$highlighter = new \Highlighter\Highlighter();

echo $highlighter->getSpecifiedSnippet(__FILE__, 3, 5);

Result

Result

Printing single line

<?php

require_once "vendor/autoload.php";

$highlighter = new \Highlighter\Highlighter();

echo $highlighter->getLine(__FILE__, 3);

Result

Result

You can use same functions with suffix WithoutNumbers to highlight code without line numbers:

<?php

require_once "vendor/autoload.php";

$highlighter = new \Highlighter\Highlighter();

echo $highlighter->getWholeFileWithoutNumbers(__FILE__);

Result

Result

Themes

This highlighter supports custom themes. It has built-in themes, but you can create your own by implementing Highlighter\Theme\ThemeInterface

So, to set theme, just call setTheme method of Highlighter

<?php

require_once "vendor/autoload.php";

$highlighter = new \Highlighter\Highlighter();
$highlighter->setTheme(new Highlighter\Theme\DefaultThemes\Minimalistic());

echo $highlighter->getWholeFile(__FILE__);

Built-in themes:

Minimalistic

Theme

Light

Theme

Material

Theme