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.

classification
Title: python curses newterm implementation
Type: enhancement Stage: needs patch
Components: Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: Guido.van.Rossum, draganic1, gvanrossum, juliushamilton100, paul.moore, serhiy.storchaka, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2021-11-29 22:46 by draganic1, last changed 2022-04-11 14:59 by admin.

Messages (8)
msg407673 - (view) Author: Guido van Rossum (Guido.van.Rossum) Date: 2021-12-04 15:54
Since this is an enhancement, it should only target 3.11.--
--Guido (mobile)
msg407674 - (view) Author: Guido van Rossum (Guido.van.Rossum) Date: 2021-12-04 15:57
This does not apply to Windows (we don’t support curses there).
msg407724 - (view) Author: Julius Hamilton (juliushamilton100) Date: 2021-12-05 18:06
I’m trying to patch this bug.

Here are my current working questions:

1. What is the relationship between an fd (file descriptor) and a terminal? What software / hardware component goes to “fd 0” to receive input from it? Is there a GNU Screen command to receive stdin from “fd n”, fd 3 for example?

2. Looking at the source code:

def initscr():
    import _curses, curses
    # we call setupterm() here because it raises an error
    # instead of calling exit() in error cases.
    setupterm(term=_os.environ.get("TERM", "unknown"),
              fd=_sys.__stdout__.fileno())
    stdscr = _curses.initscr()
    for key, value in _curses.__dict__.items():
        if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
            setattr(curses, key, value)

    return stdscr

- why does initscr() begin by importing _curses and curses? Precompiled C curses and non-compiled C or is the second importing Python? How can a module be importing itself?

- they call “setupterm”, a C curses function, because it raises an error if there’s a problem in case of just quitting. But how so, specifically? Do the errors get detected at stderr and then the terminal raises another error or something? I’m not clear on the details. Plus, why can they call this function without referring to the enclosing package, curses.setupterm? Is that a C thing that all functions are automatically added to the namespace?

- Someone wrote that “initscr” actually calls “newterm”, in the code. So I guess I should look at the C newterm code, see how it works and see if a direct implementation is possible.


(I said in an email I would double post an email I sent but instead I’m posting more specific questions here related to that email. Also, I’m still studying an email Guido sent, so apologies for any redundant questions here.)

Thanks,
Julius
msg407725 - (view) Author: Julius Hamilton (juliushamilton100) Date: 2021-12-05 18:21
I’m trying to patch this bug.

Here are my current working questions:

1. What is the relationship between an fd (file descriptor) and a terminal?
What software / hardware component goes to “fd 0” to receive input from it?
Is there a GNU Screen command to receive stdin from “fd n”, fd 3 for
example?

2. Looking at the source code:

def initscr():
import _curses, curses
# we call setupterm() here because it raises an error
# instead of calling exit() in error cases.
setupterm(term=_os.environ.get("TERM", "unknown"),
fd=_sys.__stdout__.fileno())
stdscr = _curses.initscr()
for key, value in _curses.__dict__.items():
if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
setattr(curses, key, value)
return stdscr

- why does initscr() begin by importing _curses and curses? Precompiled C
curses and non-compiled C or is the second importing Python? How can a
module be importing itself?

- they call “setupterm”, a C curses function, because it raises an error if
there’s a problem in case of just quitting. But how so, specifically? Do
the errors get detected at stderr and then the terminal raises another
error or something? I’m not clear on the details. Plus, why can they call
this function without referring to the enclosing package, curses.setupterm?
Is that a C thing that all functions are automatically added to the
namespace?

- Someone wrote that “initscr” actually calls “newterm”, in the code. So I
guess I should look at the C newterm code, see how it works and see if a
direct implementation is possible.

(I said in an email I would double post an email I sent but instead I’m
posting more specific questions here related to that email. Also, I’m still
studying an email Guido sent, so apologies for any redundant questions
here.)

Thanks,
Julius

On Sun 5. Dec 2021 at 00:01, Éric Araujo <report@bugs.python.org> wrote:

>
> Change by Éric Araujo <merwok@netwok.org>:
>
>
> ----------
> stage:  -> needs patch
> versions:  -Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue45934>
> _______________________________________
>
msg407733 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-12-05 19:15
What is it about? The first message is by Guido, but not this message nor the title does not give me any idea what is it about.
msg407768 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-12-06 04:36
Serhiy, this started with a post by Julius to the core-mentorship list. He wants to add newterm(), and found that an issue about that was just created by a different user (draganic1) -- apparently without a comment body, so it appears the first comment is mine (I didn't know that was possible in bpo).

Windows experts are welcome to take themselves off the nosy list.
msg407795 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-12-06 12:29
Thank you Guido for clarification. I have found that post:

https://mail.python.org/archives/list/core-mentorship@python.org/thread/YGSMPKP7G3HO73ISEQZFAWPPGCOA3JYZ/

I agree that it is worth to implement newterm. In particular it would be useful in tests.
msg407844 - (view) Author: Julius Hamilton (juliushamilton100) Date: 2021-12-06 17:15
I’m currently planning on studying the C code for initscr and newterm so I can really understand how they work.

I’ll post any updates about this soon.

Thanks.
History
Date User Action Args
2022-04-11 14:59:52adminsetgithub: 90092
2021-12-06 17:15:50juliushamilton100setmessages: + msg407844
2021-12-06 12:52:06serhiy.storchakasetassignee: serhiy.storchaka
2021-12-06 12:29:47serhiy.storchakasetmessages: + msg407795
2021-12-06 04:36:01gvanrossumsetnosy: + gvanrossum
messages: + msg407768
2021-12-05 19:15:01serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg407733
2021-12-05 18:21:30juliushamilton100setmessages: + msg407725
2021-12-05 18:06:14juliushamilton100setmessages: + msg407724
2021-12-04 23:01:23eric.araujosetstage: needs patch
versions: - Python 3.6, Python 3.7, Python 3.8, Python 3.9, Python 3.10
2021-12-04 15:57:51Guido.van.Rossumsetmessages: + msg407674
components: + Library (Lib), - Windows, C API
2021-12-04 15:54:08Guido.van.Rossumsetmessages: + msg407673
2021-12-04 12:05:19juliushamilton100setnosy: + Guido.van.Rossum, juliushamilton100
2021-11-29 22:46:54draganic1create