Giter Club home page Giter Club logo

html-to-vt100's Introduction

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:

composer require jeremiah-shaulov/html-to-vt100

Example

<?php

require_once 'vendor/autoload.php';
use Vt100\Vt100;

// to output
echo Vt100::from_html('aaa<b style="color:magenta">BBB</b>ccc<br>');

// to error log
error_log(Vt100::from_html('aaa<b style="color:magenta">BBB</b>ccc<br>'));

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

less -r filename.log

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

<?php

require_once 'vendor/autoload.php';
use Vt100\Vt100;

$FILENAME = '/tmp/myapp.log';

// 1. Write some messages to file
file_put_contents($FILENAME, Vt100::from_html("<b>IMPORTANT</b> message<br>"));
file_put_contents($FILENAME, Vt100::from_html("<i style='color:blue'>Notice</i> message<br>"), FILE_APPEND);
file_put_contents($FILENAME, Vt100::from_html("<b style='color:yellow; background-color:black'>Warning</b> message<br>"), FILE_APPEND);

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

What supported

Limited subset of HTML is supported:

  • <br>
  • <b>bold</b>
  • <i>italic</i>
  • <u>underlined</u>
  • <blink>blink</blink> - Most modern terminals don't support this.
  • <em>inverse fg/bg</em>
  • <span style="color: magenta"> - Produces classic escape codes for black, red, green, yellow, blue, magenta, cyan and white. For other HTML colors - nonclassic.
  • <span style="color: #AABBCC"> - Produces nonclassic escape codes.
  • <span style="background-color: magenta">
  • <span style="background-color: #AABBCC">
  • <b>bold <span style="font-weight: normal">normal</span></b>
  • <i>italic <span style="font-style: normal">normal</span></i>
  • <u>underlined <span style="text-decoration: none">normal</span></u>
  • <font color=blue>blue</font>

API

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

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.

html-to-vt100's People

Contributors

jeremiah-shaulov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.