Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jeremiah-shaulov/html-to-vt100

Convert HTML to VT100 terminal codes, to print colored and styled messages.
https://github.com/jeremiah-shaulov/html-to-vt100

Last synced: 6 days ago
JSON representation

Convert HTML to VT100 terminal codes, to print colored and styled messages.

Awesome Lists containing this project

README

        

# html-to-vt100

Convert HTML to VT100 terminal codes, to print colored and styled messages.

## Installation

Create a directory for your application, `cd` to it, and issue:

```bash
composer require jeremiah-shaulov/html-to-vt100
```

## Example

```php
BBBccc
');

// to error log
error_log(Vt100::from_html('aaaBBBccc
'));
```

CLI applications can echo messages to terminal. Web applications can write them to error log, or to a custom log file, and then view it with

```bash
less -r filename.log
```

The written file can be then converted to HTML and presented in browser:

```php
IMPORTANT message
"));
file_put_contents($FILENAME, Vt100::from_html("Notice message
"), FILE_APPEND);
file_put_contents($FILENAME, Vt100::from_html("Warning message
"), FILE_APPEND);

// 2. Read and present to browser
echo Vt100::to_html(file_get_contents($FILENAME));
```

## What supported

Limited subset of HTML is supported:

- `
`
- `bold`
- `italic`
- `underlined`
- `blink` - Most modern terminals don't support this.
- `inverse fg/bg`
- `` - Produces classic escape codes for black, red, green, yellow, blue, magenta, cyan and white. For other HTML colors - nonclassic.
- `` - Produces nonclassic escape codes.
- ``
- ``
- `bold normal`
- `italic normal`
- `underlined normal`
- `blue`

## API

Namespace Vt100 contains one class called Vt100 with 2 static functions:

```php
public static function from_html($str); // Converts HTML to VT100 escape codes.

public static function to_html($str); // Converts VT100 escape codes produced by from_html() back to HTML.
```