I'm a C# developer having worked with .Net since it was in beta. Before that I mainly worked in C and C++. I have been developing commercial software for more than 20 years. I also mess around with microprocessors, but that's just for fun. I live near Cambridge, England and work from home in my 'silicon shed'.

Blogroll

Whilst messing about with my own programming language, I've been getting it to display output in the browser, which all looks very retro because it's text only.

So I decided that it would be nice to prettify things a little bit, without going to very much trouble. It would also be nice to be able to do things like clear the screen, or move the cursor around. But I didn't want to invent my own protocol, I thought that it would be much better to just use an existing thing.

For that reason, I thought it might be handy just to use ANSI escape sequences. Whilst that would still look all very retro (use of these codes goes way back to the 1970s), it would bring some new capabilities to the table, like colour and very simple graphics. It should even allow very basic animations. Of course, this isn't what I have designed H2D2 for; but it's a nice way to test the language.

What I have ended up with is a JavaScript library which renders ANSI escape sequences onto a webpage. I was able to get a very good head start by using the existing code in escapes.js.

But with my version, it doesn't matter where the output comes from, the code just deals with drawing it onto the page. It means that the library can deal with any text containing ANSI escape codes. It even allows more than one 'console' to appear on the same webpage. I have also included support for extended colour codes, meaning that RGB values can be used. It's possible to turn scrolling on or off, and you can keep appending more text when you like.

Anyway, it worked a treat when I plugged it back into my H2D2 demo. Here's some hurriedly hacked together example output:

As you can see, all I have done is taken my existing sphere drawing program and gotten it to output ANSI escape codes rather than plain text characters. When I get some time, I'll probably put the JavaScript library on GitHub.