Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upUse blessings when possible for WPT UI #8551
Conversation
| self.terminal = blessings.Terminal() | ||
| self.clear_eol = self.terminal.clear_eol | ||
| self.move_up = self.terminal.move_up | ||
| except: |
This comment has been minimized.
This comment has been minimized.
frewsxcv
Nov 16, 2015
Member
Can we make this except ImportError just so we silence+catch all exceptions in case one occurs from something else?
This comment has been minimized.
This comment has been minimized.
mrobinson
Nov 16, 2015
Author
Member
The idea here was that if the import failed, if creating the Terminal failed, or if the __getattr__ call in blessings fails (which just calls into curses), we should always fall back. If you like I can split the work into two try/except blocks and print an error in the second one.
This comment has been minimized.
This comment has been minimized.
jgraham
Nov 16, 2015
Contributor
try and except with no condition is never a good idea; even except Exception: is better because it won't catch KeyboardInterrupt. In this case I agree that splitting into two blocks is a better idea.
|
Reviewed 1 of 1 files at r1. Comments from the review on Reviewable.io |
|
Review status: all files reviewed at latest revision, 1 unresolved discussion. tests/wpt/grouping_formatter.py, line 33 [r1] (raw file): Comments from the review on Reviewable.io |
|
Reviewed 1 of 1 files at r2. tests/wpt/grouping_formatter.py, line 53 [r2] (raw file): tests/wpt/grouping_formatter.py, line 58 [r2] (raw file): Comments from the review on Reviewable.io |
| return self.terminal.clear_eol, self.terminal.move_up | ||
| except Exception, exception: | ||
| sys.stderr.write("GroupingFormatter: Could not get terminal " | ||
| "control characters: %s" % exception) |
This comment has been minimized.
This comment has been minimized.
|
Review status: all files reviewed at latest revision, 4 unresolved discussions. tests/wpt/grouping_formatter.py, line 60 [r2] (raw file): Comments from the review on Reviewable.io |
|
Review status: all files reviewed at latest revision, 4 unresolved discussions. tests/wpt/grouping_formatter.py, line 60 [r2] (raw file): Comments from the review on Reviewable.io |
Use blessings when it is possible for the WPT UI and fall back to using raw control characters. This also fixes a bug where the UI didn't work correctly in iTerm.app. Remove the one line version of the UI, since it is no longer used as the iTerm fallback.
|
Review status: all files reviewed at latest revision, 4 unresolved discussions. tests/wpt/grouping_formatter.py, line 53 [r2] (raw file): tests/wpt/grouping_formatter.py, line 58 [r2] (raw file): Comments from the review on Reviewable.io |
|
Reviewed 1 of 1 files at r3. tests/wpt/grouping_formatter.py, line 60 [r2] (raw file): Comments from the review on Reviewable.io |
|
Review status: all files reviewed at latest revision, 2 unresolved discussions. tests/wpt/grouping_formatter.py, line 60 [r2] (raw file): Comments from the review on Reviewable.io |
|
@bors-servo: r+ |
|
|
Use blessings when possible for WPT UI Use blessings when it is possible for the WPT UI and fall back to using raw control characters. This also fixes a bug where the UI didn't work correctly in iTerm.app. Remove the one line version of the UI, since it is no longer used as the iTerm fallback. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8551) <!-- Reviewable:end -->
|
|
|
|
||
| try: | ||
| self.terminal = blessings.Terminal() | ||
| return self.terminal.clear_eol, self.terminal.move_up |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
salty-horse
Dec 6, 2015
Contributor
Will do. Can I put my other suggestion in a separate commit in the same PR?
| else: | ||
| return ("\033[F" + "\033[K") * len(self.current_display.splitlines()) | ||
| return ((self.move_up + self.clear_eol) * | ||
| len(self.current_display.splitlines())) |
This comment has been minimized.
This comment has been minimized.
salty-horse
Dec 5, 2015
Contributor
instead of len(s.splitlines()), s.count('\n') should be equivalent (unless Windows does weird things, which I doubt)
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
salty-horse
Dec 6, 2015
Contributor
It's slightly faster (did not measure). No need to create a list with new strings just to count its length. However:
- It only works if you assume the last line ends with a newline (Simple fix if you want to support other cases, but I don't think it's an issue)
- Only tested on Linux.
This comment has been minimized.
This comment has been minimized.
frewsxcv
Dec 6, 2015
Member
It might be better use s.count(os.linesep) for better Windows support, though I'm not too sure TBH
This comment has been minimized.
This comment has been minimized.
mrobinson
Dec 6, 2015
Author
Member
This is counting the number of lines in self.current_display, which is always assigned internally. I believe that means that Windows line endings shouldn't pose any complications. As far as I can tell the .count("\n") approach should be fine.
This comment has been minimized.
This comment has been minimized.
salty-horse
Dec 6, 2015
Contributor
The rest of the strings are composed with \n, so I'm not sure what that will do :)
If no-one can confirm it's working on Windows/Mac, I'll just patch the other bit.
This comment has been minimized.
This comment has been minimized.
salty-horse
Dec 6, 2015
Contributor
I tested this on mac and windows, and it does what you expect. So seems fine to me:
'a\nb\nc\n'.count('\n')
This comment has been minimized.
This comment has been minimized.
jdm
Dec 6, 2015
Member
I would expect splitting a constant string on a constant separator to work the same on all platforms :) The real question is given multiline string content from an external source, does it contain \r values that would cause difficulties when splitting on \n?
This comment has been minimized.
This comment has been minimized.
salty-horse
Dec 6, 2015
Contributor
You're right. Not sure why I tested that :P. In any case, there is no external source other than file names in that output.
Fix redraw of WPT UI output, and slightly improve line counting See discussion in PR #8551. Redraw of the first test name was broken due to a mix-up between two ANSI escape codes. I also took the opportunity to change the way line count is calculated. It's a bit cleaner that way (the new operation is ~%20 faster, but that's unnoticeable). <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8861) <!-- Reviewable:end -->
mrobinson commentedNov 16, 2015
Use blessings when it is possible for the WPT UI and fall back to using
raw control characters. This also fixes a bug where the UI didn't work
correctly in iTerm.app. Remove the one line version of the UI, since it
is no longer used as the iTerm fallback.