coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

Initial implementation of `stty`

Open tertsdiepraam opened this issue 3 years ago • 8 comments

I got annoyed that there was no stty yet, so I started working on it :)

In this initial version:

  • ~Only binary flags are implemented (i.e. attributes that are enabled and disabled). This means that attributes like tabN where N is a number between 0 and 3 is missing.~ This is now supported.
  • --all is implemented.
  • -F/--file and -g/--save are ignored.
  • Special characters, special settings and combined settings are missing.
  • The nix crate is used (not libc). Sadly, here are already some attributes that seem to be missing in nix.

The tests are broken on my machine with the error:

thread 'main' panicked at 'Could not get terminal attributes: ENOTTY', src/uu/stty/src/stty.rs:83:44

So the stdout in cargo test does not seem to be a tty with terminal attributes. This might mean that we can't test stty at all? I'd like to try to find a workaround though.

tertsdiepraam avatar Jun 25 '22 20:06 tertsdiepraam

wahou, amazing :)

sylvestre avatar Jun 26 '22 07:06 sylvestre

@tertsdiepraam can we use crossterm for this (or are we using it ?)

Maybe we will have to use shell scripts for that TTY issue.

https://docs.rs/crossterm/latest/crossterm/index.html

Wahou indeed (pardon my french interjections ;)

anastygnome avatar Jun 28 '22 13:06 anastygnome

I'm not currently using crossterm, but nix, which has support for most of the flags that we need for this. crossterm seems to be more about writing to the terminal than changing it's characteristics. The terminal size could come in handy but crossterm doesn't seem to support setting the size. So I'm afraid it will have to stay as low level as it is.

tertsdiepraam avatar Jun 28 '22 14:06 tertsdiepraam

@tertsdiepraam I thought so as well, but maybe it could be an inspiration for which calls we should use.

anastygnome avatar Jun 28 '22 14:06 anastygnome

I've ignored the tests that need to be run from a tty for now, but added some for the argument parsing. I've also added the special settings for the terminal (baudrate, columns, rows and line), but they can only be printed for now (not changed). With those changes this is at least ready to be considered somewhat of a viable first version, though of course there is much to be done :)

tertsdiepraam avatar Jul 02 '22 17:07 tertsdiepraam

Apparently it needs some work on mac. It will take me a while to fix it though. If someone else wants to fix it up for mac, feel free to do so in the meantime.

tertsdiepraam avatar Jul 02 '22 23:07 tertsdiepraam

@tertsdiepraam I belive mac os has no support for the cline field in termios.

Hence, should we ignore it ?

I believe the same problem is the cause for the other errors

anastygnome avatar Jul 03 '22 10:07 anastygnome

Yeah I think that makes sense. The other issue with mac is that the baudrate is represented with a u32 instead of the baudrate enum.

tertsdiepraam avatar Jul 03 '22 10:07 tertsdiepraam

Okay, so I think it's correct now. I can't test with mac, but I get the correct speed on FreeBSD. There are of course some minor issues and missing functionality with this implementation, but I think we can merge this and I can start opening issues for those.

tertsdiepraam avatar Aug 19 '22 10:08 tertsdiepraam

sounds good, let's wait for the CI :) I can do more testing on mac if you need

sylvestre avatar Aug 19 '22 10:08 sylvestre

I'm not sure what's going on with the Cargo.lock format. I can't find anything important that has changes with respect to main.

tertsdiepraam avatar Aug 19 '22 12:08 tertsdiepraam

Bravo ! would you like to do a release now? :)

sylvestre avatar Aug 20 '22 07:08 sylvestre

Yes, I'll start working on it!

tertsdiepraam avatar Aug 20 '22 09:08 tertsdiepraam