id: 'idea--thule-alternatives'
content: |
  The big alternative I know of is
  [TermKit](https://github.com/unconed/TermKit), which is an interesting
  experiment: but, to me, it's filled with far too many special cases
  and not enough nice primitives. For example, there's a special
  way of outputting a list of files (e.g. output from `ls`) but this
  isn't because "files" are necessarily a distinct thing, but because
  there's a special type of output for `ls`-like commands (in this
  case, `application/json; schema=termkit.files`, which corresponds
  to a list of filenames.)

  Thule builds on top of this by having a standard set of building
  blocks, so that you no longer have the special-case "list of files",
  but rather primitive building blocks like `list` and `file`.
  Consider the output from `wc`: this also contains file references,
  but it additionally contains a table mapping those to values. In
  a TermKit-like setting, you'd have to come up with a new schema
  (say, `application/json; schema=termkit.wordcount`) that understands
  which parts of the output are files and which aren't. This is
  particularly tricky for `wc`, because you want to have the
  final `total` row, which does _not_ contain a file. And what if
  other tools also print table-like structures? Can those be
  processed with the same tools?

  Thule aims to pull those low-level building blocks out, so the
  output from `ls` might give you a collection like

      (set (file "/tmp/foo.txt") (file "/tmp/bar.c"))

  and the output from `wc` will give you

      (table ((text "lines") (text "words") (text "characters") (text "file"))
        ((int 10) (int 30) (int 300)  (file "/tmp/foo.txt"))
        ((int 20) (int 60) (int 900)  (file "/tmp/bar.c"))
        ((int 30) (int 90) (int 1200) (text "total")))

  rather the structure of the collections would be a hint to the
  shell on how to display them in a rich way.
related:
  - name: idea--thule
    why: The high-level idea