Ported more of the term handling.
Ported return key handling.