STINNER Victor <victor.stin...@haypocalc.com> added the comment:

Some comments about termsize.diff.3.

I don't see why there are two functions, one should be enough: 
get_terminal_size() should be dropped, and query_terminal_size() renamed to 
get_terminal_size(). As said before, I don't think that reading ROWS and 
COLUMNS environment variables is useful. If a program chose to rely on these 
variables, it can reimplement its own "try env var or fallback on 
get_terminal_size()" function.

get_terminal_size() should not have a fallback value: it should raise an error, 
and the caller is responsible to decide what to do in this case (e.g. catch the 
exception and use its own default value). Most functions in the posix module 
work like this, and it avoids the difficult choice of the right default value. 
(fallback=None is an hack to avoid an exception, it's not the pythonic.)

I don't think that it's possible that stdin, stdout and/or stderr have its own 
terminal. I suppose that the 3 streams are always attached to the same 
terminal. So I don't see why the function would take an argument. Tell me if I 
am wrong.

Instead of using sys.__stdout__.fileno(), you can directly use 1 because Python 
always create sys.__stdout__ from the file descriptor 1.

I think that a tuple (columns, rows) would be just fine. A namedtuple helps 
when you have a variable number of fields, or more than 3 fields, but here you 
just have 2 fields, it's not too much difficult to remember which one contains 
the columns.

I would prefer an optional function, instead of implementing a function raising 
a NotImplementedError. All other posix functions are defined like this.

ioctl() is already exposed in the fcntl module, I don't see a specific test for 
<sys/ioctl.h> header. It looks like the module is always compiled on Unix, I 
don't see how fcntl and ioctl are tested in setup.py.

I don't think that you need <conio.h> to get GetConsoleScreenBufferInfo(), 
<windows.h> should be enough. So just check for "#ifdef MS_WINDOWS".

Your function is helpful, and it is surprising that nobody proposed to 
implement it in Python. Some libraries did already implement their own function 
(like the "py" library).

----------
nosy: +haypo

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue13609>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to