oolong — a terminal interface library built in layers

oolong — a terminal interface library built in layers A architecture diagram generated by Archify. ssh · remote session host · Architecture component · module ssh remote session host module Terminal · TERM · PTY · escape stream · Architecture component · outside the library Terminal TERM · PTY · escape stream outside the library ptytest · spawns a real pty · Architecture component · nothing imports it ptytest spawns a real pty nothing imports it components/kit · theme, glyphs, widgets · components — two layers · replaceable whole components/kit theme, glyphs, widgets replaceable whole components/headless · behaviour without appearance · components — two layers · 40+ controllers components/headless behaviour without appearance 40+ controllers core/term · ownership and capability probe · Architecture component core/term ownership and capability probe core/program · one goroutine, one frame schedule · Architecture component · runtime core/program one goroutine, one frame schedule runtime core/grid · cells, display atoms, diffing · Architecture component · the heart core/grid cells, display atoms, diffing the heart core/input · keys, mouse, Kitty protocol · Architecture component core/input keys, mouse, Kitty protocol core/layout · one-dimensional allocator · Architecture component · no internal deps core/layout one-dimensional allocator no internal deps core/text · styled lines and wrapping · Architecture component core/text styled lines and wrapping content modules · markdown · highlight · latex · Architecture component · peer modules content modules markdown · highlight · latex peer modules owns and returns drives a real pty Host: events in, frames out same Host interface structural, no import composes, not mirrors draws into a clipped View decodes keys and mouse rectangles produces text.Line components — two layers

The layering is checkable

  • • core's internal dependency graph is acyclic and four deep; layout, ansi and diff import nothing internal
  • • core has four direct external dependencies: uniseg, go-runewidth, x/sys, x/term
  • • internal/arch fails CI when a boundary is crossed, so the rules are not advice in a document

Behaviour really is separable

  • • headless owns state, input and semantics, and decides how nothing looks
  • • kit answers what headless refuses: which characters draw a border, which grey is muted text
  • • headless never imports kit, so dropping the appearance layer and keeping the behaviour stays possible

One concurrency rule

  • • one goroutine draws and handles input; state reached only from it needs no lock
  • • work that happens elsewhere returns through Runtime.Dispatcher and runs there
  • • the program parks when there is nothing to do — no clock runs regardless