Screwtape's Notepad

Notes on terminal emulation

Closed questions

The VT52

xterm extensions

The Framebuffer


Tabs move the cursor, rather than printing output.

Note: xterm seems to not distinguish between:

printf 'hello   world'


printf 'hello\tworld'

…both produce a three-cell gap between the two words (as opposed to three 1-cell space characters, as iTerm does).

On the other hand, when you include colours, they are different:

printf "$(tput setab 3)hello$(tput setab 4)\\t$(tput setab 5)world\\n"
printf "$(tput setab 3)hello$(tput setab 4)   $(tput setab 5)world\\n"

When the words are seperated by a tab, a gap is left coloured in the original background colour. When the words are separated by spaces, those cells have their background colour set to ‘4’ (blue). So, uh, that makes things messy.

Printing across a word-wrap merges lines

If two consecutive physical lines are distinct (resizing the window does not affect the alignment of the second line), and text is printed across their shared boundary, the two lines are joined into one logical line, and after that resizing the window does affect the alignment of the second line.


printf 'hello\nworld\n\033[2A\033[78Gencyc\n\n'

Resizing the terminal pins the lower-left corner of the framebuffer.

In iTerm and, when making the framebuffer narrower, lines that wrap always push the lines above them up. For example, if physical and logical line 23 is exactly the width of the terminal, and the terminal is subsequently resized narrower such that it wraps onto two lines, those will be physical lines 22 and 23 (but still one logical line).


printf '\033[2J\033[1;79H01\n'
for (( i=2; i <= 23; i=i+1 )); do 
     printf '\033[79G%02i\n' $i
printf '\033[1;1H'

A double-width character at the end of a line wraps

In xterm and, printing a double-width character at the end of a line causes that character to appear at the beginning of the next line (in, such wrapping occurs dynamically, so dragging the window 1 cell wider makes it jump back to the end of the first line; in xterm the wrapping occurs statically).


printf '\033[80G病\n'