VIXL Release 1.10
Refer to the README.md and LICENCE files for details.
diff --git a/tools/printer.py b/tools/printer.py
index 7082636..dc97a5b 100644
--- a/tools/printer.py
+++ b/tools/printer.py
@@ -31,71 +31,95 @@
import time
import multiprocessing
+output_redirected_to_file = not sys.stdout.isatty()
-__need_newline__ = multiprocessing.Value('i', 0)
-__last_overwritable_line_length__ = multiprocessing.Value('i', 0)
+def ColourCode(colour):
+ return '' if output_redirected_to_file else colour
+
+COLOUR_GREEN = ColourCode("\x1b[0;32m")
+COLOUR_ORANGE = ColourCode("\x1b[0;33m")
+COLOUR_RED = ColourCode("\x1b[0;31m")
+NO_COLOUR = ColourCode("\x1b[0m")
+
+# Indicates the 'type' of the last printed line.
+LINE_TYPE_NONE = 0
+# Any type below this one is overwritable.
+LINE_TYPE_OVERWRITABLE = 1
+LINE_TYPE_PROGRESS = 2
+LINE_TYPE_LINTER = 3
+
__print_lock__ = multiprocessing.Lock()
+__last_overwritable_line_length__ = multiprocessing.Value('i', 0)
+__last_line_type__ = multiprocessing.Value('i', LINE_TYPE_NONE)
-# If the last printed character was not a newline, print one.
def EnsureNewLine():
- global __need_newline__
+ if __last_line_type__.value >= LINE_TYPE_OVERWRITABLE:
+ sys.stdout.write('\n')
+ __last_line_type__.value = LINE_TYPE_NONE
- if __need_newline__.value:
- __need_newline__.value = 0
+
+def PrintInternal(string):
+ sys.stdout.write(string)
+ spaces = __last_overwritable_line_length__.value - len(string)
+ if spaces > 0:
+ sys.stdout.write(' ' * spaces)
+
+
+def Print(string, has_lock = False):
+ if not has_lock: __print_lock__.acquire()
+
+ if __last_line_type__.value != LINE_TYPE_NONE:
sys.stdout.write('\n')
-
-# Like print, but insert a newline if necessary to avoid corrupting the status
-# display (provided by UpdateProgress).
-def Print(string):
- global __last_overwritable_line_length__
-
- EnsureNewLine()
- print string
+ PrintInternal(string)
+ sys.stdout.write('\n')
__last_overwritable_line_length__.value = 0
+ __last_line_type__.value = LINE_TYPE_NONE
+
+ if not has_lock: __print_lock__.release()
-def PrintOverwritableLine(string, verbose = False):
- global __need_newline__
- global __last_overwritable_line_length__
+# Lines of a specific type only overwrite and can only be overwritten by lines
+# of the same type.
+def PrintOverwritableLine(string, has_lock = False, type = LINE_TYPE_NONE):
+ if not has_lock: __print_lock__.acquire()
- with __print_lock__:
- if verbose:
- # In verbose mode we do not overwrite previous lines.
- EnsureNewLine()
- else:
- # Otherwise, overwrite the previous line.
- sys.stdout.write('\r')
+ if (__last_line_type__.value != type) and \
+ (__last_line_type__.value >= LINE_TYPE_OVERWRITABLE):
+ sys.stdout.write('\n')
- sys.stdout.write(string)
+ PrintInternal(string)
+ if not output_redirected_to_file:
+ sys.stdout.write('\r')
+ else:
+ sys.stdout.write('\n')
+ sys.stdout.flush()
- # Append spaces to hide the previous line.
- new_len = len(string)
- spaces = __last_overwritable_line_length__.value - new_len
- if spaces > 0:
- sys.stdout.write(' ' * spaces)
- __last_overwritable_line_length__.value = new_len
+ __last_overwritable_line_length__.value = len(string)
+ __last_line_type__.value = type
- # We haven't printed a newline, so any subsequent print output (with verbose
- # logs or error reports) will need to print one.
- __need_newline__.value = 1
+ if not has_lock: __print_lock__.release()
# Display the run progress:
-# [time| progress|+ passed|- failed] Name
-def UpdateProgress(start_time, passed, failed, count, verbose, name,
- prefix = ''):
+# prefix [time| progress|+ passed|- failed] name
+def UpdateProgress(start_time, passed, failed, count, name, prefix = '',
+ prevent_next_overwrite = False, has_lock = False):
minutes, seconds = divmod(time.time() - start_time, 60)
progress = float(passed + failed) / count * 100
- passed_colour = '\x1b[32m' if passed != 0 else ''
- failed_colour = '\x1b[31m' if failed != 0 else ''
+ passed_colour = COLOUR_GREEN if passed != 0 else ''
+ failed_colour = COLOUR_RED if failed != 0 else ''
indicator = '[%02d:%02d| %3d%%|'
- indicator += passed_colour + '+ %d\x1b[0m|'
- indicator += failed_colour + '- %d\x1b[0m]'
+ indicator += passed_colour + '+ %d' + NO_COLOUR + '|'
+ indicator += failed_colour + '- %d' + NO_COLOUR + ']'
progress_string = prefix
progress_string += indicator % (minutes, seconds, progress, passed, failed)
progress_string += ' ' + name
- PrintOverwritableLine(progress_string, verbose)
+ PrintOverwritableLine(progress_string, type = LINE_TYPE_PROGRESS,
+ has_lock = has_lock)
+ if prevent_next_overwrite:
+ sys.stdout.write('\n')
+ __last_line_type__.value = LINE_TYPE_NONE