Search code examples
terminalioctlsttyxonsh

Why does `stty cols 40` have different effects in the two shells bash and xonsh


I get weird behaviour when using stty in the xonsh shell on Linux/macOS. (Commands do not seem to obey the defined column under xonsh, but they do so under bash.)

To get a better understanding of the situation I wrote a little C program which calls ioctl with TIOCGWINSZ for the 3 standard streams stdin, stdout, stderr and prints the widths out.

Before doing any stty command I get the following results for the ioctl width:

bash xonsh
stdin=80, stdout=80, stderr=80 stdin=80, stdout=80, stderr=80

So far so good. This means my terminal is 80 cols wide.

Now I issue in each shell stty cols 40, run my little program and get these results:

bash xonsh
stdin=40, stdout=40, stderr=40 stdin=40, stdout=80, stderr=80

How strange, that under xonsh for the file descriptors stdout and stderr the width of 80 is reported(!) while under bash everything as expected all descripters have a width of 40.

This sheds some light on the fact that various commands (e.g. wget) do not obey stty col calls under xonsh.

But why is this the case? And how can I issue a stty-style command that sets under xonsh the width of all standard streams to 40?


Solution

  • By default, stty reads/sets the terminal settings on stdin. You can set some other terminal with the -F or --file argument

    stty -F /dev/stdout ...
    

    Now the question is, why is there a difference between stdin and stdout (and stderr) if all are connected to the same terminal -- the settings are supposed to be per terminal, not per file descriptor. That I don't know.