PHPackages                             enco/cli-styles - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. enco/cli-styles

ActivePackage[CLI &amp; Console](/categories/cli)

enco/cli-styles
===============

Package to manage cli output styles (color, background, font style)

1.0.4(3y ago)05GPL-3.0-onlyPHPPHP ^7.2.0

Since Sep 14Pushed 3y ago1 watchersCompare

[ Source](https://github.com/EncoXXX/cli-styles)[ Packagist](https://packagist.org/packages/enco/cli-styles)[ RSS](/packages/enco-cli-styles/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

CLI styles for PHP
==================

[](#cli-styles-for-php)

With this library you can stylize CLI output

Available styles:

- Bold
- Italic
- Blink
- Underline
- Cross line
- Over line
- Text color
- Background color

### How to use:

[](#how-to-use)

You can add different styles to different parts of text. For example, you specify two styles with names 'success' and 'error'. So your text must be like:

```
Some text without styles
Text with success styles
Some text without styles
Text with error styles
Some text without styles
```

**NOTE:**  You can`t use tags hierarchy. This text will be incorrect:

```
Some text without styles
Text with success styles
    Text with error styles
    Text with success styles

Some text without styles
```

In your code you must use 2 classes: `\Enco\CliStyles` and `\Enco\Style`

`\Enco\Style` uses to define style
You are obligated to set style name. Otherwise, the exception will be thrown
The name must match `^[a-z0-9_-]+$` regular expression
Available methods:

```
use \Enco\Style;

public function setName(string $name): Style; //Set name of style. Used like html tags
public function setColor(string $color): Style; //Only color hash. Ex: #ff0024
public function setBackground(string $background): Style; //Only color hash. Ex: #ff0024
public function setBold(bool $isBold = true): Style;
public function setItalic(bool $isItalic = true): Style;
public function setUnderline(bool $isUnderline = true): Style;
public function setCrossLine(bool $isCrossLine = true): Style;
public function setOverLine(bool $isOverline = true): Style;
public function setBlink(bool $isBlink = true): Style;

public static function formatLink(string $url, string $text): string;
```

Also, you can specify default style, that applies to text without tags
To do this you just need to specify `\Enco\Style::DEFAULT_STYLE_NAME` constant as name of style

`\Enco\CliStyles` uses to apply styles to text
You must add styles, that you want to use

Available methods:

```
use Enco\CliStylesPool;
use Enco\Style;

public function addStyle(Style $style): CliStylesPool;
public function addText(string $text): CliStylesPool
public function resolve(): string;
public function __toString(): string; //Symlink to resolve() method
```

You can use `$cliStylesObject` to echo text. Styles will be applied automatically. Example:

```
$cliStylesObject = new \Enco\CliStylesPool();
...
echo $cliStylesObject;
```

Also, you can escape tag:

```
This is example of \\ tags
```

Output will be:

```
This is example of  tags

```

PHP code example:

```
use Enco\CliStylesPool;
use Enco\Style;

$style = new Style();
$style->setName('temp');
$style->setColor('#555555')
    ->setBackground('#ffffff')
    ->setItalic()
    ->setBold()
    ->setCrossLine();;

$defaultStyle = new Style();
$defaultStyle->setName(Style::DEFAULT_STYLE_NAME)
->setColor('#ff00ff');

$errorStyle = new Style();
$errorStyle->setName('error')
    ->setColor('#ffffff')
    ->setBackground('#ff0000');

$text = "
This is simple text without styles\n
Some text with styles\n
One more text with styles\n
";

$cliColors = new CliStylesPool();
$cliColors->setText($text)
    ->addStyle($style)
    ->addStyle($defaultStyle)
    ->addStyle($errorStyle);

echo $cliColors;
```

### Cli cursor management

[](#cli-cursor-management)

You can manage CLI cursor position. For ex. mov cursor or set absolute position

To manage CLI cursor you must use `\Enco\CliCursor`

Available methods:

```
use \Enco\CliCursor;

public function saveCursorPosition(): CliCursor //You can save only one position
public function restoreCursorPosition(): CliCursor //Restore cursor position from saved one
public function moveLeft(int $cols): CliCursor //Move cursor left. $cols must be > 0
public function moveRight(int $cols): CliCursor //Move cursor right. $cols must be > 0
public function moveUp(int $lines, bool $moveToStartOfLine = false): CliCursor //Move cursor up. If $moveToStartOfLine = true -> also moves cursor to first column
public function moveDown(int $lines, bool $moveToStartOfLine = false): CliCursor // Move cursor down. If $moveToStartOfLine = true -> also moves cursor to first column
public function setCol(int $col): CliCursor //Set cursor column position (horizontal)
public function setLine(int $line): CliCursor //Set cursor line position (vertical)
public function setPosition(int $line, int $col): CliCursor //Set absolute cursor position in both directions
public function eraseWindow(): CliCursor //Erase window (works like `clear` in bash) and set position to 1;1
public function eraseCurrentLine(): CliCursor //Erase current line and set cursor position to start of line
public function scrollUp(int $height): CliCursor //Scroll terminal up (add new lines to header). $height must be > 0. Lines at bottom will be erased
public function scrollDown(int $height): CliCursor //Scroll terminal down (add new lines to bottom). $height must be > 0. Lines at header will be erased
public function hideCursor(): CliCursor //Hide cursor (cursor in terminal will be invisible, but still works)
public function showCursor(): CliCursor //Show cursor position (cursor blink in terminal)
public function getTerminalWidth(): int //Returns terminal width in cols
public function getTerminalHeight(): int //Returns terminal height in lines
```

You must be careful to use `\Enco\CliStyles` and `\Enco\CliCursor`, because `\Enco\CliCursor` in some cases can reset styles (when new text override styled text)

Code example:

```
use Enco\CliCursor;

$cursor = new CliCursor();
$cursor->eraseWindow();
echo '1'; //After echo cursor moves right, so position will be 1, 2
$cursor->setPosition(2, 2);
echo '2'; //After echo cursor moves right, so position will be 2, 3
$cursor->setPosition(3, 3);
echo '3'; //After echo cursor moves right, so position will be 3, 4
$cursor->moveLeft(1)
       ->moveDown(1);
echo "Height: " . $cursor->getTerminalHeight() . ' lines. ';
echo "Width: " . $cursor->getTerminalWidth() . 'columns';
```

Output will be:

```
1
 2
  3
  Height: 52 lines. Width: 204 columns

```

You always can ask questions to ``

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1340d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8658a8cbf325076c5dc5c5dec11be63cb0c6d1a080b0455df69cbcd5556be003?d=identicon)[EncoXXX](/maintainers/EncoXXX)

---

Top Contributors

[![andrii-bednarskyi](https://avatars.githubusercontent.com/u/55691792?v=4)](https://github.com/andrii-bednarskyi "andrii-bednarskyi (1 commits)")

### Embed Badge

![Health badge](/badges/enco-cli-styles/health.svg)

```
[![Health](https://phpackages.com/badges/enco-cli-styles/health.svg)](https://phpackages.com/packages/enco-cli-styles)
```

###  Alternatives

[wp-cli/wp-cli

WP-CLI framework

5.0k17.2M320](/packages/wp-cli-wp-cli)[consolidation/annotated-command

Initialize Symfony Console commands from annotated command class methods.

22569.8M19](/packages/consolidation-annotated-command)[chi-teck/drupal-code-generator

Drupal code generator

26947.8M5](/packages/chi-teck-drupal-code-generator)[seld/cli-prompt

Allows you to prompt for user input on the command line, and optionally hide the characters they type

24725.8M17](/packages/seld-cli-prompt)[illuminate/console

The Illuminate Console package.

12944.1M5.1k](/packages/illuminate-console)[php-tui/php-tui

Comprehensive TUI library heavily influenced by Ratatui

589747.0k6](/packages/php-tui-php-tui)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
