[PATCH] obtain terminal_width via curses
Robey Pointer
robey at lag.net
Wed Apr 26 03:46:06 BST 2006
On 25 Apr 2006, at 18:36, Gustavo Niemeyer wrote:
> Hey Martin,
>
>> Thanks for the patch. There is an existing bug open for this,
>> https://launchpad.net/products/bzr/+bug/3507
>>
>> That bug suggests using TIOCGWINSZ to do this, rather than curses,
>> which is at least conceptually more lightweight. Are there any
>> particular advantages to using curses?
>
> I've just added a comment to the bug with the function I use
> in Smart PM, based on TIOCGWINSZ.
I can't follow links right now because I'm offline, but apparently I
posted a patch for this back on Valentine's day. I can't remember
why it got rejected? Attached below my sig.
robey
=== 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,
termios.TIOCGWINSZ, " "))
+ return width
+ except ImportError:
+ pass
+ return 80
More information about the bazaar
mailing list