jatoben/CommandLine

Wrap long lines in generated usage message

Closed this issue · 2 comments

Wrapping long help lines to the terminal width would make the usage message look much better. Unfortunately the canonical method to get the terminal size is an ioctl(2) call, and Swift is not compatible with C varargs.

One option for this is the following:

import Darwin.ncurses

initscr()
let terminalWidth = COLS
endwin()

Not the greatest solution, it does feel heavy invoking ncurses just for this, and has a few caveats.

  • import Darwin.ncurses in Xcode 7 Beta 1 no longer automatically links ncurses for you, has to be done manually. I have a feeling this is a bug as Apple changed some stuff related to .dylibs that has caused another issue so it may be related [1]. The workaround is to add it manually to the build phases setting in Xcode.
  • This won’t work inside the Xcode “terminal” as I imagine its because terminfo/termcap don’t recognize it. So it be an issue for running tests inside Xcode, though I’m not sure ioctl(2) would work either.

I’m wondering though, is it necessary to do this based on terminal width? I know manual pages do this, but wouldn’t it be better for reading that it was some fixed width? Defaulted to say 80, but would be configurable (in code). Or possibly even offer both options, fixed & dynamic.

[1] https://forums.developer.apple.com/message/8609#8609

This repository is being archived. See #111.