This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author zbysz
Recipients denilsonsa, giampaolo.rodola, pitrou, zbysz
Date 2011-12-16.13:41:30
SpamBayes Score 0.0
Marked as misclassified No
Message-id <1324042892.11.0.759534392024.issue13609@psf.upfronthosting.co.za>
In-reply-to
Content
One reply to three comments:

[To myself]:
>  I'll post an updated version here in a moment.
Hm, it's not so simple. The implementation is simple,
but the configure defines are harder than I thought.
But I'm getting there :)

> Zbyszek, I just looked at [1] and I disagree that the environment variable should have higher precedence. In fact, I believe it should have lower precedence, and should be used as a fallback.

I disagree. $COLUMNS will usually _not_ be set:

$ echo $COLUMNS
119

$ ./python -c 'import os; print("COLUMNS" in os.environ)'
False

As I wrote before, the shell only sets COLUMNS for use in the shell, without exporting. Giving a precedence to the environment variable (if it is set by the user) allows to do something like this:
$ COLUMNS=80 python program.py
... do whatever is to be dome for 80 columns ...
and the normal case (with dynamic checking) will also work correctly.

Anyway, I think that two functions should be provided: a "raw" one, which does the ioctl, and the "normal" one, which queries $COLUMNS and the the "raw" function. If different behaviour is wanted, than just
the "raw" one can be called.

> Also, the Windows implementation should not rely on ctypes.
Of course. For windows I have:
  #include <conio.h>
  ...
  GetConsoleScreenBufferInfo(handle, &csbi)
  ...

> This looks like something which would fit better into shutil module rather than os.
This is problematic. The docstring for shutil says:
  Utility functions for copying and archiving files and directory trees.
So it doesn't seem to fit at all.

OTOH, there's termios and tty, but they are UNIX only. Module curses is also UNIX only, and slightly different topic, because get_terminal_width should be independent of curses.

> Plus, you should provide also heigth, not only width, possibly as a namedtuple.
Agreed.
History
Date User Action Args
2011-12-16 13:41:32zbyszsetrecipients: + zbysz, pitrou, giampaolo.rodola, denilsonsa
2011-12-16 13:41:32zbyszsetmessageid: <1324042892.11.0.759534392024.issue13609@psf.upfronthosting.co.za>
2011-12-16 13:41:31zbyszlinkissue13609 messages
2011-12-16 13:41:31zbyszcreate