Unified TUIs
I do not like software using complicated GUI to achieve simple operations. For example, why use ThunderBird or Evolution, when one can use mutt ? Why use X-chat when irssi is available (and can run in screen) ? Why use Totem or VLC when Mplayer does the job ?
There is a pattern here: if possible, use a TUI.
I have reasons for that: first, it does not require advanced graphical capabilities; second, TUI are light and can be run through ssh; third: sobriety and minimalism; and last, it's prettier1.
After using this type of software, there is an obvious step: writing TUI. And this is far too clumsy. There are basically two2 way of doing it:
- Doing all the UI using ANSI escape sequences3
- Using ncurses
This is evidently a non-choice and anyway, almost all languages — even JavaScript — have ncurses bindings, so why even think about doing something else?
The problem is that each API is different, here is an example. Let's say I wan't to do something basic: clean up the terminal, write Syntactic Sugar and wait until a user presses q to exit. Pretty easy, no ?
Not that easy though. I won't put some code is several languages, but here are the step one has to take in order to implement this program:
- Initialize the screen
- Set up different options (echo off, etc.)
- Add the string to the current screen
- Start a input loop
The problem is there are no common conventions: let's assume that the screen is stdscr and that the function to add a string is addstr, should one use :
curses.addstr(stdscr , "foo") or stdscr.addstr(foo)? This depends on the language and on the bindings. Well, that's still ok, some languages have no objects, blah.
But the funny thing is not only how the functions are called, but what they do. For example, in C, there are 4 different functions: addstr, mvaddstr, waddstr, mvwaddstr; in Python there is just one function: addstr which takes different kind of arguments; in Ruby it's like in C; etc.
As I like to say, modern developers are not attached to one languages, but use the languages that fit their needs. I use OCaml, JavaScript, PHP and C on a regular basis, but I also happen to use Python from times to times4. The thing I'd really like is to be able to have advanced UI to the software I write, without having to learn and master several API.
I don't have any miraculous idea, but I may have a beginning of solution. I think one of the most important thing in programming is to learn from what other have done before and never reinvent anything5. This might look like heresy to some, but I'm pretty sure that a client/server model would be ideal to manage TUI, using the web as an inspirational source.
Basically, serving web applications is pretty much the same thing as writing a TUI6: there is a backend, written in whatever language you want, and a frontend which presents information and interacts with the user. I'm convinced this can be transposed to plain old terminal applications.
What I suggest is an XML format to describe the application layout, some kind of CSS to style the application and a script language7 to deal with events. This would have mainly two consequences:
- No more complicated/cluttered/different API to master
- The output of the application is independant of the platform
The first point is obvious: it was what I was looking for. The second is much more interesting: as the web is currently shifting to a platformy thing where content gets replaced by data flow and the page model shifts to an applicative model, I'm pretty confident that having applications which may run as well online and in a terminal might be the future of the TUI8.
Anyway, that was just a morning thought which got much more longer that I intended…
- but that's subjective [↩]
- in fact, three, but I won't talk about S-lang, it's much like ncurses [↩]
- this is very much like trying to write some advanced software in assembly… [↩]
- and I should learn Ruby and Perl in the near future [↩]
- except if you can do better [↩]
- though Web 2.0 apps are usually more eye candy… [↩]
- JavaScript ?
[↩] - after all, why should web 2.0 only be about GUI? [↩]