Skip to content

RFC: Extract stderr_width to crate and make more portable #6322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wezm opened this issue Nov 17, 2018 · 2 comments
Closed

RFC: Extract stderr_width to crate and make more portable #6322

wezm opened this issue Nov 17, 2018 · 2 comments

Comments

@wezm
Copy link
Member

wezm commented Nov 17, 2018

tl;dr: See winsize and my winsize branch of cargo.

Describe the problem you are trying to solve

I noticed whilst doing some development on my FreeBSD workstation that the new progress bar was not showing up for me. I did some research and saw that it all boiled down to whether there is an implementation of stderr_width for the platform.

Upon finding that code I was surprised to find it limited only to Linux and MacOS as I would have expected the behaviour to be pretty universal across UNIX like systems. Further research showed that this code was originally cfg(unix) but it was gated to linux and macos in #4713 as there were build failures on some platforms due to the differing size of an argument to ioctl. Additionally, looking at the libc crate shows that almost all of the unix platforms define the TIOCGWINSZ ioctl.

Describe the solution you'd like

I'd like the progress bar to work on FreeBSD, but ideally all platforms that support TIOCGWINSZ.

Notes

Since Alex Crichton said "I just didn't want to deal with all the portability stuff here" I'm proposing that this the window sizing stuff be extracted to a separate crate and deal with the portability there. I've gone ahead and done that:

https://github.com/wezm/winsize

I've also got a branch of cargo using the crate: b3d0b2e...wezm:winsize

I've added CI for FreeBSD, Linux, MacOS, and Windows to that repo and plan to add more platforms as sr.ht adds support for more build platforms (which is planned). Currently I've only added FreeBSD to the code path using the ioctl, I'd like to add others as methods become available to have them in CI too.

Currently it's a direct extraction from cargo. I wanted to get feedback on this before spending more time on it. If this seems like a reasonable approach I'd like to do the following before proposing cargo use it:

  • Generalise the crate more (allow different fds to be supplied)
  • Support width and height
  • Add documentation
  • Publish to crates.io
@dwijnand
Copy link
Member

There's prior art for this being done in cargo (the example I'm thinking of is the platform specific code for handling the --open in cargo doc --open), so I think we'd be happy for this effort to go ahead.

@wezm
Copy link
Member Author

wezm commented Nov 27, 2019

Closing as the progress bar now works in FreeBSD.

@wezm wezm closed this as completed Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants