[PATCH V2] util.termwidth: never return 0 for terminal width

Martin Geisler mg at aragost.com
Mon May 2 07:35:43 CDT 2011


Jason Harris <jason.f.harris at gmail.com> writes:

> # HG changeset patch
> # User jfh <jason at jasonfharris.com>
> # Date 1303087372 -7200
> # Node ID 26246decb27d319452610b3c20aa251cc4cbb292
> # Parent  e83ced8b6464ff8f4c6cd9e4b780ba4b5d6208e0
> util.termwidth: never return 0 for terminal width
>
> Catch a case where the termwidth was being reported as 0 when I was
> connecting with TLMTask instead of NSTask in OSX. This caused the
> progress extension to print no progress. The termwidth should never
> return 0 so in case we would return 0, simply fall back to the default
> termwidth below which is 80.
>
> diff --git a/mercurial/posix.py b/mercurial/posix.py
> --- a/mercurial/posix.py
> +++ b/mercurial/posix.py
> @@ -316,7 +316,9 @@
>                  if not os.isatty(fd):
>                      continue
>                  arri = fcntl.ioctl(fd, termios.TIOCGWINSZ, '\0' * 8)
> -                return array.array('h', arri)[1]
> +                width = array.array('h', arri)[1]
> +                if width < 0:
> +                    return width

If you want to never return 0, then this should be 'if width > 0',
right?

-- 
Martin Geisler

aragost Trifork
Professional Mercurial support
http://mercurial.aragost.com/kick-start/


More information about the Mercurial-devel mailing list