VIMINO

Simulating a Text Terminal

How hard can it be to make a Text Terminal Simulator in Javascript?
That's what I asked myself, having decided to make it a personal challenge.

In some Gamejams like the FFS Jam, the developers rate each others entries.
That's when I came into contact with a few games that used a curses-like library to make a game using the (text) terminal (also called a console or command line).
As they were distributed as Python scripts, it was troublesome to test if you didn't have it installed. Which got me thinking, if they had been made it in Javascript they could work directly in most browsers.

That's when I started working on Terminal.js, a prototype that uses a single page with a pre tag and modifies it using Javascript.
It replicated a basic terminal but I switched to a canvas tag to support some of the wider Unicode characters and to make it easier to adjust to different screen sizes.
After a day of work it had already evolved into JSTTS.js which was later renamed to JerboaTTS. Jerboas are small desert hopper rodents, think mouse kangaroo.
I created a matrix and drew each character in it with a specific style. Later defining that the canvas area was a visible matrix (the View) and that layers could be rendered to it (Grid) and tried to make it relatively easy to understand and use.

So there's my answer. It can get rather complex but the original idea was simple.
Let's call it "As simple as needed."

And in case you were wondering, there are Javascript curses-like libraries out there like blessed and ohui.
This was to be expected considering that NodeJS runs Javascript on the console.

Added on 2018-03-17 at 14:49:23

Comments