The ptytest crate provides a convenient way to test programs that write to terminals, by matching over the state of the pseudo-terminal.