Tcell - Terminal functionality for Pure Go apps

Introducing Tcell  - Terminal functionality for Pure Go apps

As part of the work I've done on govisor, I had a desire for rich terminal functionality so that I could build a portable curses-style management application.

This turned out to be both easier and harder than I thought.

Easier, because there was an implementation to start from -- termbox-go, but harder because that version wasn't portable to the OS I cared most about, and fell short in some ways that I felt were important.  (Specifically, reduced functionality for mice, colors, and Unicode.)

This led me to create my own library; I've made some very very different design choices.  These design choices have let me both support more platforms (pretty much all POSIX platforms and Windows are included), increase support for a much richer set of terminals and terminal capabilities, etc.

The work is called "Tcell" (for terminal cells, which is the unit we operate on -- if you don't like the name ... well I'm open to suggestions.  I freely admit that I suck at naming -- and its widely acknowledged that naming is one of the "hard" problems in computer science.)

As part of this work, I've implemented a full Terminfo string parser/expander in Go.  This isn't quite as trivial as you might think, since the parameterized strings actually have a kind of stack based "minilanguage", including conditionals, in them.

Furthermore, I've wound up exploring lots more about mice, and terminals, and the most common emulators.  As a result, I think I have created a framework that can support very rich mouse reporting, key events, colors, and Unicode.  Of course, the functionality will vary somewhat by platform and terminal (your vt52 isn't going to support rich colors, Unicode, or even a mouse, after all.  But Xterm can, as can most modern emulators.)

This work would be a nice basis for portable readline implementations, getpassphrase, etc.  Or a full up curses implementation.  It does support a compatibility mode for termbox, and most termbox applications work with only changing the import line.   I still need to change govisor, and the topsl panels library, to use tcell, but part of that work will be including much more capable mouse reporting, which tcell now facilitates.

Admittedly, if you cannot tolerate cgo in any of your work -- this isn't for you -- yet.  I will probably start adding non-cgo implementations for particular ports such as Linux, Darwin, and FreeBSD.  But for other platforms there will always be cgo as a fallback.  Sadly, unless the standard Go library evolves to add sufficient richness that all of the termios functionality are available natively on all platforms (which is a real possibility), cgo will remain necessary.  (Note that Windows platform support does not use CGO.)


Popular posts from this blog

SP (nanomsg) in Pure Go

An important milestone

The Hand May Be Forced