This is a template implementation of a tool with a terminal user interface.
- Haskell code for a TUI with all best practices
- OptParse for the TUI
- A nix build
- An example cast for documentation
- Stack-based CI
- Nix-based CI
- Pre-commit hooks
This template is not free to use. See https://template.cs-syd.eu/template/NorfairKing/template-tui for more information.
Copyright (c) 2020-2022 Tom Sydney Kerckhove.
All Rights Reserved.
To use this template in a new project, choose the name for your project, for example
Then use template-filler to use the template, like this:
template-filler --source /path/to/this/template-tui --destination /path/to/your/homeless-shelter --find FooBar --replace HomelessShelter
There is a single Haskell package in
It contains the following structure:
- The entry point in
- The TUI state in
- The rendering in
- The Worker environment and types in
- The worker function in
- The event handling in
The option parsing is based on the option parsing template. It is included in this template so you will not need to also buy the option parsing template.
For more information about how to use the option parsing, follow the instructions in
If you don't need a nix build, remove these files:
rm -rf *.nix nix .github/workflows/nix.yaml
nix/nixpkgs-version.nix, we pin a
nix/pkgs.nix we define our own 'version' of the
nixpkgs by adding our own overlays.
The project overlay is defined in
See the instructions in
nix/overlay.nix for more details.
CI is set up for both a stack build and a nix build.
.github/workflows for more details.
The stack build should "just work".
For the nix build to work, there is a manual step that you need to go through:
First, make a cachix cache at cachix.org.
Put its name in the right places within
Then put its signing key in the 'Secrets' part of your repository on github.
An example autorecorder cast is provided in the
You can declare ascii casts for your TUI for documentation using autorecorder.
If you don't need this, you can delete the
casts directory and the relevant part of
Adding functionality to the TUI
Brick, the TUI library that we use, uses the following architecture.
Start | v Event -> State -> Draw | | \----- Brick-----/
To add functionality:
- Change the
Stateto have what you need for your functionality. Remember that this state needs to contain everything that you may want to draw on the screen.
- If some long-running IO needs to happen, change the
Responsetype to support the messages that need to be sent. Also add the request handling to the
- Change the
drawfunction to draw the new state.
- Add any event handling that's necessary to the