terminal: make the code of disable_echo() reusable