Commit e6ddf194 authored by Daniel Bratell's avatar Daniel Bratell Committed by Commit Bot

Stop gclient sync from scrolling during progress output

Change-Id: I08d3ea600d56875b92911c39762f888f9e140f00
Reviewed-on: https://chromium-review.googlesource.com/1138314
Commit-Queue: Daniel Bratell <bratell@opera.com>
Reviewed-by: 's avatarRobbie Iannucci <iannucci@chromium.org>
parent 3298e7b5
......@@ -49,6 +49,7 @@ class Progress(object):
if text:
text += ' ' + extra
text = text[:self.terminal_width()] # Avoid wrapping
spaces = max(self._width - len(text), 0)
sys.stdout.write('%s%*s\r' % (text, spaces, ''))
sys.stdout.flush()
......@@ -73,3 +74,44 @@ class Progress(object):
spaces = max(self._width - len(text), 0)
sys.stdout.write('%s%*s\n' % (text, spaces, ''))
sys.stdout.flush()
def terminal_width(self):
"""Returns sys.maxsize if the width cannot be determined."""
try:
if not sys.stdout.isatty():
return sys.maxsize
if sys.platform == 'win32':
import ctypes
class CONSOLE_SCREEN_BUFFER_INFO(ctypes.Structure):
_fields_ = [
('dwSize', ctypes.wintypes._COORD),
('dwCursorPosition', ctypes.wintypes._COORD),
('wAttributes', ctypes.c_ushort),
('srWindow', ctypes.wintypes._SMALL_RECT),
('dwMaximumWindowSize', ctypes.wintypes._COORD)
]
# Get our own instance of the kernel lib since python
# libraries and python ports are known to manipulate
# ctypes.windll.kernel32. See
# https://github.com/pallets/click/issues/126
kernel32 = ctypes.WinDLL('kernel32')
handle = kernel32.GetStdHandle(-12) # -12 == stderr
console_screen_buffer_info = CONSOLE_SCREEN_BUFFER_INFO()
if kernel32.GetConsoleScreenBufferInfo(
ctypes.c_ulong(handle),
ctypes.byref(console_screen_buffer_info)):
# Note that we return 1 less than the width since writing into
# the rightmost column automatically performs a line feed.
right = console_screen_buffer_info.srWindow.Right
left = console_screen_buffer_info.srWindow.Left
return right - left
return sys.maxsize
else:
import fcntl
import struct
import termios
packed = fcntl.ioctl(sys.stderr.fileno(), termios.TIOCGWINSZ, '\0' * 8)
_, columns, _, _ = struct.unpack('HHHH', packed)
return columns
except Exception: # pylint: disable=broad-except
return sys.maxsize
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment