GithubHelp home page GithubHelp logo

duukkis / terminal Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 2.0 3.8 MB

ttyrec-parser, writing screens to text-files, writing screens to gifs and writing gifs to animated gif all with PHP

PHP 100.00%
vt100 php ttyrec interpreter animatedgif

terminal's Introduction

Terminal

PHP parser for ttyrec-files.

File in example/game.ttyrec from https://alt.org/nethack/

Creative Commons Attribution 4.0 International License.

Requirements

// this so that composer autoload is loaded
require __DIR__ . './vendor/autoload.php';

use Terminal\Terminal;
use Terminal\Interpret;
use Terminal\Screen;

$file = __DIR__."/game.ttyrec";
$terminal = new Terminal($file);

// how to play the ttyrec file

// with actual delay coded in ttyrec file
$terminal->printScreens(true);
// speedy gonzales with small delay
$terminal->printScreens(false, 1000);
// quarter of a second delay between frames
$terminal->printScreens();


// if you wish to write the screens into files
// prequisite mkdir temp
$terminal->loopScreens(true);

// or print the screens / commands in screens
$screens = $terminal->getScreens();
/** @var Screen $screen */
foreach ($screens as $screen) {
    print_r($screen->getCommands());
}

Code logic

  • Terminal - the top file

  • Screen - ttyrec is splitted into these. Has sec, usec, len and the actual screen to print in terminal

  • Commands - Screen is splitted into commands. See Terminal/Commands dir

  • Interpret - Interprets screen strings into different commands.

  • Terminal has loopScreens function that interprets screen commands into actual output. Most of screens depend on the previous screens.

  • TerminalRow is a row that is a string and those are put into Terminal->console[rowIndex] array and modified / added based on screen commands.

screen_6415.txt

                        ----------
                       /          \
                      /    REST    \
                     /      IN      \
                    /     PEACE      \
                   /                  \
                   |     heather      |
                   |       7 Au       |
                   |   killed by a    |
                   |    giant bat     |
                   |                  |
                   |                  |
                   |       2020       |
                  *|     *  *  *      | *
         _________)/\\_//(\/(/\)/\//\/|_)_______


 Goodbye heather the Wizard...

 You died in The Dungeons of Doom on dungeon level 3 with 1655 points,
 and 7 pieces of gold, after 4835 moves.
 You were level 6 with a maximum of 49 hit points when you died.

Terminal to Gif

require __DIR__ . '/../vendor/autoload.php';

use Terminal\TerminalToGif;

$file = __DIR__."/game.ttyrec";

$terminalToGif = new TerminalToGif($file);
$terminalToGif->screenToGif(6415, "test.gif");

RIP

Creating animated gif with PHP

require __DIR__ . '/../vendor/autoload.php';

use Terminal\TerminalToGif;
use Gif\GifEncoder;

// create some gifs first 
$file = __DIR__."/game.ttyrec";
$terminalToGif = new TerminalToGif($file);

// write three files with different fgColor
$terminalToGif->setFgColor(255, 0, 0);
$terminalToGif->screenToGif(6415, "test.gif");
$terminalToGif->setFgColor(0, 0, 0);
$terminalToGif->screenToGif(6414, "test2.gif");
$terminalToGif->setFgColor(0, 0, 255);
$terminalToGif->screenToGif(6410, "test3.gif");

// make an animated gif from them with GifEncoder
$gifEncoder = new GifEncoder(["test3.gif", "test2.gif", "test.gif"], [100, 100, 200], 1, 2, "url");
// gif ready write it to animated gif
$gifEncoder->writeGif("animated.gif");

RIP

terminal's People

Contributors

duukkis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

terminal's Issues

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.