Closed wconrad closed 9 years ago
Hmm. The way it figures out what to do is here: https://github.com/davetron5000/gli/blob/gli-2/lib/gli/terminal.rb#L53 (sorry about that code—I think I had just discovered lambdas and was reading a lot of FP stuff at the time :).
You could have your editor export COLUMNS
and LINES
, but I would agree that ignoring 0's probably makes sense. You could probably change this line: https://github.com/davetron5000/gli/blob/gli-2/lib/gli/terminal.rb#L81 so that it ignores any 0's and moves on to the next "size determiner".
The lambdas are fine. I think, though, that having them come in pairs is causing a bit of a problem. To make this change, the first lambda--the predicate--will need to actually run the stty command just as the second lambda does. If there was just one, and it returned nil or some-such to indicate "don't know," that would make things easier for this change.
However, I think calling stty twice is the sure thing: The test coverage in this code isn't complete, and I hesitate to make to much of a change to it
I've got ideas for how the code could be structured differently, but they are more radical surgery (with attendant risks, and taking more time). I would think of moving each determiner into its own little class, tested in isolation. Are you interested in any changes of that sort?
When I run a gli program inside Emacs in Linux, the help output is too narrow. To reproduce:
Create a new gli project
gli init todo list add complete
, etc.)Versions
The stty command is the culprit
Run outside of emacs, the stty command reports its width normally:
But inside an Emacs shell, it reports the width like this:
I presume that "0 0" means that stty can't determine the terminal size. I haven't found out if this represents a bug, or is just the way it is in an Emacs shell.
A possible workaround
It should be possible to make gli to disregard a zero width report from stty, causing it to fallback to
Terminal.default_size
. That will result in passable output when a gli program is run in emacs, or any other environment where stty doesn't know the terminal width.If you like, I'd be glad to submit a pull request with that change.