Tuesday, September 6, 2011

Embedded terminal in websites

I release today jquery.terminal, a jQuery plugin to embed a terminal in web pages. It has several base commands and can be customized in order to add application-specific commands. It has a powerful operator mechanism to group command together (allowing to pipe commands and more combinations). And it is very, very geek.

Try the demo online!

I first coded this plugin two years ago, when Aurélien asked me for a terminal to administrate a game he made, without having to build a web interface. I thought it was a good idea and build a system which requires JavaScript and PHP to execute commands on the server side. Last weekend I found this code, and because I dropped PHP in favor of "all in JavaScript!" for months, I wanted to rewrite it. Here is the result!

I really love the command flow, that the outputs of one command serve as additional arguments for another one. With real computer terminals, there are two input methods: arguments in the command line, or the standard input. I made here life much more easier: a single input way. Actually, it has been designed as a data stream with filters which can map values to other ones.

It is the first time I build an execution tree. Because the syntax is really easy, it was not so difficult to parse and collect information. It mainly relies on state machines with a really few number of states. Another solution would have been to use a BNF grammar and a JavaScript parser. I don't know if it exists one, and anyway I thought it was too heavy. However, the final code is more complex to read, thus to maintain, than if it used BNF.

Follow the development on GitHub.

No comments:

Post a Comment