/plushcap/analysis/warp/the-data-structure-behind-terminals

The data structure behind terminals

What's this blog post about?

Grids are fundamental building blocks for terminals, providing a two-dimensional array of characters that enable basic operations like entering commands and receiving output. In Warp, the grid is especially important as it separates commands into blocks consisting of three grids each. The efficiency of terminal operations such as reading data from the shell, scrolling through content, and resizing the screen or splitting panes depends on the implementation of the grid. Warp's grid implementation optimizes for specific operations like scrolling by rotating the underlying vector, which allows efficient scrolling at the cost of added complexity in index conversion. The terminal reads streamed input from the shell and writes it character-by-character to the specified grid location. In the worst-case scenario, expanding the vertical grid dimension requires memory movement. Resizing a grid is another essential operation that comes with its own performance trade-offs. Warp stores grids at the dimensions of the pane in which they render, allowing horizontal limits to be imposed during resizing rather than rendering. Overall, terminal grid design should balance competing priorities and optimize for specific operations while minimizing resulting costs.

Company
Warp

Date published
May 4, 2023

Author(s)
Jack Nichols

Word count
1280

Language
English

Hacker News points
6


By Matt Makai. 2021-2024.