cartesi / machine-emulator

The off-chain implementation of the Cartesi Machine
GNU Lesser General Public License v3.0
58 stars 32 forks source link

fix: configure target terminal with -onlcr #193

Closed diegonehab closed 4 months ago

diegonehab commented 4 months ago

The expected behavior of the emulator is to pass through new-line control-characters directly from the inside to the outside. On the outside, if the output of the emulator is connected to a file, there should be no addition of a carriage-return. If, however, the output is connected to a terminal, the terminal itself will have been configured to add the carriage-return on its own.

In other words, we expect the following command to have the output shown

cartesi-machine.lua --no-init-splash --quiet -- echo | xxd
00000000: 0a                                       .

Instead, what we see before this PR (but when using a yet-to-be-released kernel linked to opensbi-1.3.1-ctsi-2) is

cartesi-machine.lua --no-init-splash --quiet -- echo | xxd
00000000: 0d0a                                     ..

This is because the terminal inside the emulator is configured with onlcr, so it is adding the carriage-return whenever it sees a new-line.

The PR configures the terminal with -onlcr so this doesn't happen.

Interestingly, prior to opensbi-1.3.1-ctsi-2, opensbi itself was adding yet another carriage-return on its own, whenever it saw a new-line sent to the legacy putchar we use with HTIF console. So the output was

cartesi-machine.lua --no-init-splash --quiet -- echo | xxd
00000000: 0d0d 0a                                  ...
diegonehab commented 4 months ago

Will add to cartesi-init instead.