Pseudo Terminals and Terminal Emulators

by Miguel de Icaza

There was a discussion about how to host REPLs in applications like MonoDevelop recently and some of the discussion was centered around how to host something like a shell into a program like MD.

Since I have been thinking about building a Silverlight-based version of the Midnight Commander (OH NOES!) I figured I should share some thoughts that I had on this matter.

Widgets like ZVT and VTE today bundle a number of things in a single widget:

  • A Unix Pseudo terminal with login/logout support (Unix flavor-specific).
  • A terminal emulator that turns escape sequences generated by a stream into rendering commands.
  • A binding to the Gtk+ toolkit to send input events to the child process and render the terminal results.

I would like to see some nice C# libraries for doing each one of those tasks independently of each other. Think of it as the MVC of terminal widgets. Like this:

Reusable Blocks for Terminal Emulation.

Pseudo-terminal support: the functionality to create pseudo terminals is very OS-specific, it is hard to get right and getting the more advanced features like registering your session is even harder. Very few applications get this right (mc, zvt and vte all use the same code that took me years to fine tune but has never been made reusable for other applications).

This can be used beyond terminal emulators, it can be used to script or control programs expect a real terminal to run. These are typically interactive Unix console applications.

Those applications either break or refuse to run when their standard input or standard output are redirected. Expect is a system built on top of this functionality

Terminal Emulation: A terminal emulator class that supports the vt100/xterm command set and render it into some internal buffer; can take high-level keystrokes and encode them as byte streams (for example turning Alt-X into ESC-x) and supports terminal resizing.

This terminal emulator should not be bound to Gtk+ it should merely render into a text buffer.

Gtk#, Silverlight and Curses Bindings: Once the underlying terminal emulator exists we will need to write a handful of bindings to the terminal emulator.

The Gtk# is an obvious choice for embedding terminal emulators inside things like MonoDevelop.

The Silverlight binding would allow people to create full fledged SSH clients on the web.

The curses binding could be used to implement an application like GNU Screen or it could be used in an application like the Midnight Commander (the Midnight Commander plays some Unix tricks to avoid having to emulate a terminal, and this has been a small weakness).

Posted on 20 Apr 2009