Handling terminal encoding