Skip to content

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

Closed
@wezm

Description

@wezm

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions