Improve terminal input/output logging

Log input data as strings instead of individual chars, and also log keycodes as produced by terminal.