Sharing Open Source HTML Virtual Terminal
Posted by Kris Kowal (FastSoft Sourcerer)
Last month, we experimented with integrating Ajaxterm with Django. Ajaxterm is a polling HTTP based terminal emulator that can provide a web interface for a local SSH or login session with all the glory of ASCII and Ncurses so you can administer your system or edit configuration files with Vim or, in a pinch, Emacs. The heart of the terminal emulator is a Terminal class to which you can write the output of a pseudo-terminal stream and from which you can periodically read a block of HTML representing the complete terminal window state. We needed to “pickle” (serialize in Java parlance) Terminal instances so that they could be picked up by Django’s round-robin FastCGI processes. We refactored Terminal such that it’s serializable and posted a Github gist for your use.
The original terminal class created instance methods on initialization. Pickles can’t serialize instance methods, so all of these had to be converted into class methods. To do that, using mostly the same code, we moved the method definition code into a Terminal metaclass. For more information about metaclasses, I wrote an article about a year ago on my personal “Ask a Wizard” blog.
