Skip to main content
Deno 2 is finally here šŸŽ‰ļø
Learn more

Scratch38-S0015

A bunch of TypeScript code to help me build simple TUIs; things that look like:

Screenshot of a status dashboard mockup...thing

I have tried to keep the different components separate from each other as much as possible so that you can mix and match the parts that are useful.

Major components

  • inputeventparser has functions for parsing escape sequences from the terminal.
  • TextRaster2 defines a common representation of styled terminal text.
  • tuiappframework3 takes care of TUI application lifecycle management stuff.
  • components2 defines a component layout and ā€˜rendering’ system and several predefined component classes.
  • tuidemo3.ts uses all of the above to demonstrate how this library can be used.

There are also various vestigial bits, like SpanMan, which was a cool idea but turned out to not be especially useful under the ā€˜pure functions that return TextRaster2s’ regime.

Things this library does not have

  • Mouse input handling
  • Any routing of input to ā€˜components’; the components defined by components2 are output-only, and do not themselves handle input.

TUIAppFramework3

To run demonstration, try one of:

  • deno run --check=all src/demo/ts/tuidemo3.ts help
  • deno run --check=all src/demo/ts/tuidemo3.ts boxes
    • Box layout demo!
  • deno run --check=all src/demo/ts/tuidemo3.ts hello
  • deno run --check=all src/demo/ts/tuidemo3.ts clock
  • deno run --check=all --allow-read src\demo\ts\tuidemo3.ts wc README.md CHANGELOG.txt
  • deno run --check=all src\demo\ts\tuidemo3.ts wc -
    • This one reads data from stdin; recommendation is to pipe in a file
    • You can also type text in but it will ā€˜look messy’ and you’ll have to manually send EOF (Ctrl+z on Windows, Ctrl+d on Unixen) or Ctrl+c to quit.
  • deno run --check=all src\demo\ts\tuidemo3.ts status-mockup
    • Device status dashboard mockup

Pass --capture-input before the subcommand if you want to be able to hit ā€œqā€ to quit instead of having to control+c.

Other stuff

For reading characters and escape codes as sent by terminals, use toCharishes from escapeparser.ts, which will give you an AsyncIterable<Charish>, where Charish is either a number (for a regular character) or an object representing the data contained in an escape sequence. See charishdemo.ts for example.

Streams of charishes can in turn be translated into ā€˜input events’. See eventreader.ts for example.

There’s also some stuff about box drawing buried in here.

This project is currently ā€˜just a bunch of code’, isn’t very well organized, and may change drastically between versions.

See DEVLOG.md for stream of consciousness as I try to figure out what I’m trying to build.