move terminal input reading into its own function

Signed-off-by: Mattias Andrée <maandree@operamail.com>