TL;DR: I build terminal applications (TUIs) like kl for k8s logs and wander for Nomad. Core functionality of TUIs includes interacting with large blocks of text, like application manifests and logs. I created a reusable viewport component in Go for text navigation in my projects. Terminal pagers are programs that allow you to interactively navigate multi-page text. I used my viewport component to make lore, which I’m now daily driving as my terminal pager. In this post, I detail the features I wanted to support in my viewport as well as some learnings and design decisions on the way to making them a reality.
Introduction to Terminal Paging#
Along with running commands, the terminal is often a place for viewing and navigating text.
❯ cat file.txt I love terminals!
Terminals have a grid-like nature with a monospace font. Their size is defined in rows and columns, with text filling this grid accordingly.
❯ cat ~/chessboard.txt a b c d e f g h 8 R N B Q K B N R 7 P P P P P P P P 6 5 4 3 2 P P P P P P P P 1 R N B Q K B N R a b c d e f g h
Aside: styling text in terminals You can style text in terminals with ANSI escape codes. ❯ echo "default, \x1b[31mred text\x1b[0m, default" default, red text , default \x1b[31m : begin red foreground text styling
: begin red foreground text styling red text : content to be styled
: content to be styled \x1b[0m : reset styling This type of styling is how we get the grey checkerboard pattern in the terminal out of chessboard.txt above: chessboard.txt contains text with ANSI escape codes styling it for the terminal.
Developers often scan through high volumes of text in their terminal:
... continue reading