Merge lp:~joke/bzr/bugfix353370 into lp:bzr

Proposed by Joke de Buhr on 2009-10-15
Status: Merged
Merged at revision: not available
Proposed branch: lp:~joke/bzr/bugfix353370
Merge into: lp:bzr
Diff against target: 13 lines
1 file modified
bzrlib/osutils.py (+3/-0)
To merge this branch: bzr merge lp:~joke/bzr/bugfix353370
Reviewer Review Type Date Requested Status
Vincent Ladeuil Needs Fixing on 2009-10-22
John A Meinel Needs Information on 2009-10-21
Ian Clatworthy 2009-10-15 Approve on 2009-10-19
Review via email: mp+13404@code.launchpad.net
To post a comment you must log in.
Joke de Buhr (joke) wrote :

It's a quick two line fix which pretends the terminal width is very large to prevent broken lines when using a pager like less.

  bzr help commands | less

It does not try to prevent the actual line formating code from formating which would be a better solution.

Ian Clatworthy (ian-clatworthy) wrote :

As you say, not necessarily the final solution but still an improvement from where we are today.

review: Approve
John A Meinel (jameinel) wrote :

Do we need something like "getattr(sys.stdout, 'isatty')" maybe not, but sys.stdout sometimes gets redirected to crazy things.

I suppose this could be YAGNI. Anyone else have an opinion?

review: Needs Information
Vincent Ladeuil (vila) wrote :

I agree with John about being careful when accessing sys.stdout
(even if StringIO objects provides a isatty()).

I'd also really like to have a comment there explaining the magic value
(why 10.000 and not 65536 or 1024 ?) and the intent (a value big enough
to never truncate lines ?).

I'll tweak and merge.

review: Needs Fixing
Joke de Buhr (joke) wrote :

> I agree with John about being careful when accessing sys.stdout
> (even if StringIO objects provides a isatty()).
>
> I'd also really like to have a comment there explaining the magic value
> (why 10.000 and not 65536 or 1024 ?) and the intent (a value big enough
> to never truncate lines ?).
>
> I'll tweak and merge.

10000 is a number which:
 - would probably be big enough to never truncate lines.
 - representable as an 16bit unsigned integer ( 2^(16-1) ).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/osutils.py'
2--- bzrlib/osutils.py 2009-10-15 04:01:26 +0000
3+++ bzrlib/osutils.py 2009-10-15 11:10:26 +0000
4@@ -1296,6 +1296,9 @@
5
6 def terminal_width():
7 """Return estimated terminal width."""
8+ if not sys.stdout.isatty():
9+ return 10000
10+
11 if sys.platform == 'win32':
12 return win32utils.get_console_size()[0]
13 width = 0