[PATCH] obtain terminal_width via curses

Robey Pointer robey at lag.net
Thu Apr 27 05:17:40 BST 2006


On 26 Apr 2006, at 18:48, Matthew Hannigan wrote:

> On Tue, Apr 25, 2006 at 07:46:06PM -0700, Robey Pointer wrote:
>>
>> === modified file 'bzrlib/osutils.py'
>> --- bzrlib/osutils.py
>> +++ bzrlib/osutils.py
>> @@ -617,4 +617,12 @@
>>      try:
>>          return int(os.environ['COLUMNS'])
>>      except (IndexError, KeyError, ValueError):
>> -        return 80
>> +        pass
>> +    try:
>> +        # this only works on posix
>> +        import fcntl, termios, struct
>> +        height, width = struct.unpack('hh', fcntl.ioctl(sys.stdout,
>
> I think you should ioctl sys.stdin, not stdout.
> A typical usage might be to preview on the screen, then
> run again to direct into a file.  You don't want the latter
> to fail.  Speaking of which, you should catch
> 	IOError: [Errno 25] Inappropriate ioctl for device
> as well.

I'm +1 on the patch with those 2 changes (use stdin; catch IOError).

robey





More information about the bazaar mailing list