Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(514)

Side by Side Diff: dart/tools/build.py

Issue 13726008: Only emit "interactive" output if stdout supports colors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added a comment Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 3 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
4 # for details. All rights reserved. Use of this source code is governed by a 4 # for details. All rights reserved. Use of this source code is governed by a
5 # BSD-style license that can be found in the LICENSE file. 5 # BSD-style license that can be found in the LICENSE file.
6 # 6 #
7 7
8 import optparse 8 import optparse
9 import os 9 import os
10 import shutil 10 import shutil
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 def is_empty_chunk(chunk): 252 def is_empty_chunk(chunk):
253 empty_chunk = ['Check dependencies', '', ''] 253 empty_chunk = ['Check dependencies', '', '']
254 return not chunk or (len(chunk) == 4 and chunk[1:] == empty_chunk) 254 return not chunk or (len(chunk) == 4 and chunk[1:] == empty_chunk)
255 255
256 def unbuffered(callable): 256 def unbuffered(callable):
257 # Use iter to disable buffering in for-in. 257 # Use iter to disable buffering in for-in.
258 return iter(callable, '') 258 return iter(callable, '')
259 259
260 section = None 260 section = None
261 chunk = [] 261 chunk = []
262 # Is stdout a terminal? 262 # Is stdout a terminal which supports colors?
263 isatty = sys.stdout.isatty() 263 is_fancy_tty = False
264 clr_eol = None
265 if sys.stdout.isatty():
266 term = os.getenv('TERM', 'dumb')
267 # The capability "clr_eol" means clear the line from cursor to end
268 # of line. See man pages for tput and terminfo.
269 clr_eol = subprocess.check_output(['tput', '-T' + term, 'el'])
270 if clr_eol:
271 is_fancy_tty = True
264 for line in unbuffered(process.stdout.readline): 272 for line in unbuffered(process.stdout.readline):
265 line = line.rstrip() 273 line = line.rstrip()
266 if line.startswith('=== BUILD ') or line.startswith('** BUILD '): 274 if line.startswith('=== BUILD ') or line.startswith('** BUILD '):
267 if not is_empty_chunk(chunk): 275 if not is_empty_chunk(chunk):
268 print '\n'.join(chunk) 276 print '\n'.join(chunk)
269 section = line 277 section = line
270 if isatty: 278 if is_fancy_tty:
271 # If stdout is a terminal, emit "progress" information. 279 # If stdout is a terminal, emit "progress" information. The
272 print '%s[2K%s\r' % (chr(27), section), 280 # progress information is the first line of the current chunk.
281 # After printing the line, move the cursor back to the
282 # beginning of the line. This has two effects: First, if the
283 # chunk isn't empty, the first line will be overwritten
284 # (avoiding duplication). Second, the next segment line will
285 # overwrite it too avoid long scrollback. clr_eol ensures
286 # that there is no trailing garbage when a shorter line
287 # overwrites a longer line.
288 print '%s%s\r' % (clr_eol, section),
273 chunk = [] 289 chunk = []
274 if not section: 290 if not section:
275 print line 291 print line
276 else: 292 else:
277 chunk.append(line) 293 chunk.append(line)
278 if not is_empty_chunk(chunk): 294 if not is_empty_chunk(chunk):
279 print '\n'.join(chunk) 295 print '\n'.join(chunk)
280 296
281 297
282 def Main(): 298 def Main():
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 process.wait() 402 process.wait()
387 if process.returncode != 0: 403 if process.returncode != 0:
388 print "BUILD FAILED" 404 print "BUILD FAILED"
389 return 1 405 return 1
390 406
391 return 0 407 return 0
392 408
393 409
394 if __name__ == '__main__': 410 if __name__ == '__main__':
395 sys.exit(Main()) 411 sys.exit(Main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698