Changes to terminal.py to work on Python 3

This is a minimal set of changes, just mapping the use of Python 2-specific idioms into workable Python 3 versions.

The biggest worry is probably the mapping of `unichr()` to `chr()`. This implies that there is Unicode handling, which almost certainly means that something doesn't work. I didn't see a test suite to run it through to verify the behavior, so I'm hoping for the best.