sifive/freedom-metal

Carriage returns required for alignment?

Opened this issue · 2 comments

When I compile the example programs I am finding that the output is misaligned. At first I thought it was extra spacing but later realized that the cursor was not going to the beginning of the next line. I am used to unix style line endings but if I change "\n" to "\r\n" then the output of programs looks as I would expect. Am I doing something wrong or should most example programs be updated?

Default output of sisense-welcome
Screenshot_2021-06-17_00-13-46

After swapping "\r\n" in for "\n"
Screenshot_2021-06-17_00-15-27

For reference I am using this to connect, which comes from the HiFive1 Rev B getting started manual:

sudo screen /dev/ttyACM0 115200

On my system (Ubuntu) it has Screen v4.08.00 05-Feb-20 which appears to be the latest version.

Historically, Freedom-Metal used to (sneakily, silently) replace \n by \r\n in C standard output routines. I found this behavior to be problematic and so I pushed to change it in March 2020 (PR #236). I think I still feel the same way.

A different question is whether the examples should instead use \r\n. I have less strong of an opinion here. There's no universally correct way to display a newline: \n, \r, \r\n, etc., are all "correct" on different terminal emulators, so it's impossible to write a single example program that will work correctly for everyone.

This being said, there is an issue here: you apparently followed our instructions (to use GNU screen), and had a bad experience. I think the solution is for SiFive to provide users with instructions on how to reconfigure GNU screen to reinterpret \n as \r\n (or whatever screen needs to display the correct output). Perhaps this isn't a screen setting at all, but is coming from the underlying terminal emulator that screen is running in. I Googled for a few minutes and couldn't figure this out: most Google hits suggested using a different program, or hacking the GNU screen source code.