Skip to content
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

Use ioctl() to determine width of controlling terminal #415

Merged
merged 4 commits into from
Dec 22, 2016

Conversation

roehling
Copy link
Contributor

This PR gets rid of the tput cols subprocess, which is slow and pollutes log files with tput: No value for $TERM and no -T specified messages if no controlling terminal is present.

height, width = struct.unpack("hh", ioctl(f.fileno(), TIOCGWINSZ, "1234"))
except (IOError, OSError, struct.error):
# return default size if actual size can't be determined
return 80
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should an error be printed (once?) if the size cannot be determined? Might avoid users not understanding why catkin_tools output is limited to 80 chars in case the ioctl doesn't work for them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say the 80 column default should work well enough that no error message is necessary. It's not difficult to add though.

Copy link
Contributor

@gavanderhoorn gavanderhoorn Dec 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an error was a bit strong, a warning would be better.

I'm not worried about it not working, I'm just thinking that it might avoid some confusion when users are somehow ending up with 80 col output on a 200+ col screen (or catkin insisting on 80 col output on a 30 col window) and they have no way of finding out why other than looking through the source code.

@wjwwood
Copy link
Member

wjwwood commented Dec 22, 2016

I added 2e5695b, let me know what you guys think.

__warn_terminal_width_once_has_printed = True
print('WARNING: Could not determine the width of the terminal. '
'This warning will only be printed once.',
file=sys.stderr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be: "WARNING: Could not determine the width of the terminal, will use default of 80 columns. This warning will only be printed once"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, I added a note about the default of 80 in the message in 7d586d4.

I also changed the WARNING to NOTICE, but that's just to check a hunch about the failing CI.

Copy link
Contributor Author

@roehling roehling Dec 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer notice to warning anyway :-)
Speaking of noticing, I saw that only the OSX build is failing, maybe the terminal ioctl() does not work with that OS, and the warning messes with the unit test somehow?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my latest commit it is passing, I think it was picking up the WARNING in a check for whether or not there were warnings 😄. So changing it to NOTICE was an easy workaround.

@wjwwood
Copy link
Member

wjwwood commented Dec 22, 2016

Ok, that looks good to me. Thanks @roehling and @gavanderhoorn, if you guys have more comments, we can pick them up in a follow up pr.

@wjwwood wjwwood merged commit c5e3a18 into catkin:master Dec 22, 2016
@gavanderhoorn
Copy link
Contributor

Looks ok.

A comment: we should probably introduce a constant instead of using the magic nr 80 here, here, here and here (all in common.py).

@gavanderhoorn
Copy link
Contributor

A question: is there a specific reason there are three places a default is returned? Is that just to keep terminal_width_windows() and terminal_width_linux() usable without having to through terminal_width()?

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

Successfully merging this pull request may close these issues.

3 participants