[PATCH] obtain terminal_width via curses
Robert Widhopf-Fenk
hack at robf.de
Wed Apr 26 23:43:42 BST 2006
On Wednesday, April 26, 2006 at 10:45:57, Martin Pool wrote:
>
> On 25/04/2006, at 8:24 AM, Robert Widhopf-Fenk wrote:
>
> > The attached patch modifies "bzr log --log-format line" to
> > use the actual terminal width instead of a hard coded 79.
> >
> > Further osutils.py:terminal_width() is modified to use the
> > curses module to get the current terminal width.
> >
> > In order to avoid flickering due to subsequent calls to
> > curses.initsrc(), the width is saved in a global variable.
> > It should not change the line buffering of stdout, but still
> > seems to do it on my terminal/curses/python combination for
> > the output of "bzr log ..."
> >
> > Robert
> >
> > <log-line.diff>
>
> 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?
That was the first thing I found working, but I also found
reasons against it, flickering, strange buffering, but the
biggest one: if it fails to open the terminal it will _exit()
the python interpreter.
Attached is a diff with the code from Gustavo. This now works
for me in Konsole, XTerm, (X)Emacs shell/term.
With Robeys patch I get an assertion error in the XEmacs
shell since the width returned by ioctl is 0, thus my patch
tries to fix that. I also added the -1 in log.py, but not
terminal_width() as it does not seem the right place for it.
Robert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: log-line.diff
Type: application/octet-stream
Size: 1357 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060427/b7250d7f/attachment.obj
More information about the bazaar
mailing list