Post

How to fix Enter key printing ^M in terminal

On a Scala REPL or other places

I ran into an issue when playing around with Scala and trying to get user input working on the terminal. It was picking up all my keypresses but whenever I pressed the Enter key it would just print ^M


Error Message

Problem:

  • Terminal is sending \r instead of \n to terminate a line. ^M is the ASCII representation of a carriage return, so its printing that instead of going to a new line.

Solution:

I had this problem on iTerm but not the default Mac terminal, which pinned this problem to the emulator.

The solution was to change the iTerm setting to send a \n instead of \r to terminate commands.

You can find this setting under Profiles -> Terminal or search for it in search bar.


iTerm Setting

Other terminal emulators should have a similar setting to fix this issue.

Restart the terminal and test it once again


Woo Hoo

Happy coding!


Likes
This post is licensed under CC BY 4.0 by the author.