Mechanism for testing terminal interact loop in-process.

While this is complex, I much prefer it to starting a separate process
and piping commands in.