[issue14841] os.get_terminal_size() should check stdin as a fallback

2021-03-06 Thread Eryk Sun


Change by Eryk Sun :


--
components: +Extension Modules, Library (Lib)
versions: +Python 3.10, Python 3.9 -Python 3.4, Python 3.5, Python 3.6, Python 
3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14841] os.get_terminal_size() should check stdin as a fallback

2019-04-05 Thread daniel hahler


daniel hahler  added the comment:

Created a PR at https://github.com/python/cpython/pull/12697.

It prefers stdin and stderr over stdout.

I think stdin is most likely connected to a terminal, and wondered why ncurses 
uses stderr/stdout first, and only then stdin.
stdin handling was added there in 
https://github.com/mirror/ncurses/commit/aa70bf3c#diff-10ad6ea20599ac9258757354665b80cbR1295,
 and it looks just like an oversight maybe - it is also not that critical in C 
I guess.

--
nosy: +blueyed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14841] os.get_terminal_size() should check stdin as a fallback

2019-04-05 Thread daniel hahler


Change by daniel hahler :


--
keywords: +patch
pull_requests: +12622
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14841] os.get_terminal_size() should check stdin as a fallback

2018-08-21 Thread Eryk Sun


Eryk Sun  added the comment:

The Windows implementation shouldn't map file-descriptor values 0, 1, and 2 to 
the process standard handles. fileno(stdout) may not even be 1 in some cases. 
It should use `handle = _get_osfhandle(fd)`, which is more generally correct 
and not limited to hard-coded defaults. 

Regarding this issue, the docs should clarify that the Windows console's input 
buffer cannot be used to get the screen buffer size. Typically the input buffer 
is STDIN_FILENO (0) or opened via  "CONIN$" or "CON" (read mode). Thus there is 
no point to checking stdin in Windows since it will always fail.

I agree that the default behavior should be extended to check a 
platform-dependent tty/console device. In Windows this is `fd = 
_open("CONOUT$", _O_RDWR)`.

--
nosy: +eryksun

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14841] os.get_terminal_size() should check stdin as a fallback

2018-08-21 Thread Mark Lawrence


Change by Mark Lawrence :


--
nosy:  -BreamoreBoy

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14841] os.get_terminal_size() should check stdin as a fallback

2018-08-21 Thread Grant Jenks


Grant Jenks  added the comment:

I asked on the ncurses maintainers email list about their logic and was pointed 
to tty_settings.c which checks:

1. stderr
2. stdout
3. stdin
4. open('/dev/tty', 'r+')

I don't know a cross-platform way to check #4 but I think #1-3 are a reasonable 
change to shutil.get_terminal_size().

The current logic checks only stdout. I'd like to amend that to try stderr, 
stdout, and stdin after checking the COLUMNS and LINES env vars. So the new 
logic would be:

1. Check COLUMNS and LINES env vars (for overrides)
2. Check os.get_terminal_size(stderr)
3. Check os.get_terminal_size(stdout)
4. Check os.get_terminal_size(stdin)

--
nosy: +grantjenks
versions: +Python 3.6, Python 3.7, Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14841] os.get_terminal_size() should check stdin as a fallback

2014-07-07 Thread Denilson Figueiredo de Sá

Denilson Figueiredo de Sá added the comment:

FYI, tput tool can find out the dimensions even when both stdin and stdout 
are redirected. It can't, however, if all stdin, stdout and stderr are 
redirected. Python should probably implement a similar logic.

$ echo | stty size
stty: standard input: Inappropriate ioctl for device
$ echo | tput cols | cat
223
$ echo | tput cols 21 | cat 
80

(tested under Linux)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14841
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14841] os.get_terminal_size() should check stdin as a fallback

2014-07-04 Thread Mark Lawrence

Mark Lawrence added the comment:

#13609 is closed fixed so can this also be closed?  I've tried to reproduce 
this on Windows with the help of unxutils but it didn't want to know, sorry :(

--
nosy: +BreamoreBoy
type:  - behavior
versions: +Python 3.4, Python 3.5 -Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14841
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14841] os.get_terminal_size() should check stdin as a fallback

2014-07-04 Thread Arfrever Frehtes Taifersar Arahesis

Arfrever Frehtes Taifersar Arahesis added the comment:

This bug is still reproducible in Python 3.4 and 3.5.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14841
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14841] os.get_terminal_size() should check stdin as a fallback

2012-05-17 Thread Arfrever Frehtes Taifersar Arahesis

New submission from Arfrever Frehtes Taifersar Arahesis 
arfrever@gmail.com:

$ stty size | cat
46 157
$ python3.3 -c 'import os; print(os.get_terminal_size())' | cat
Traceback (most recent call last):
  File string, line 1, in module
OSError: [Errno 22] Invalid argument

Redirection to `less` are often used.

A proposed patch was attached by Victor Stinner in issue #13609.

--
messages: 160988
nosy: Arfrever, denilsonsa, haypo, zbysz
priority: normal
severity: normal
status: open
title: os.get_terminal_size() should check stdin as a fallback
versions: Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue14841
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com