Skip to content

python curses newterm implementation #90092

Closed

Description

@draganic1
mannequin
BPO 45934
Nosy @gvanrossum, @pfmoore, @tjguk, @zware, @serhiy-storchaka, @zooba, @gvanrossum

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/serhiy-storchaka'
closed_at = None
created_at = <Date 2021-11-29.22:46:54.980>
labels = ['type-feature', 'library', '3.11']
title = 'python curses newterm implementation'
updated_at = <Date 2021-12-06.17:15:50.477>
user = 'https://bugs.python.org/draganic1'

bugs.python.org fields:

activity = <Date 2021-12-06.17:15:50.477>
actor = 'juliushamilton100'
assignee = 'serhiy.storchaka'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2021-11-29.22:46:54.980>
creator = 'draganic1'
dependencies = []
files = []
hgrepos = []
issue_num = 45934
keywords = []
message_count = 8.0
messages = ['407673', '407674', '407724', '407725', '407733', '407768', '407795', '407844']
nosy_count = 9.0
nosy_names = ['gvanrossum', 'paul.moore', 'tim.golden', 'zach.ware', 'serhiy.storchaka', 'steve.dower', 'Guido.van.Rossum', 'draganic1', 'juliushamilton100']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue45934'
versions = ['Python 3.11']

Linked PRs

Activity

  1. added
    type-feature
    on Nov 29, 2021
  2. gvanrossum commented on Dec 4, 2021

    @gvanrossum
    Member

    Since this is an enhancement, it should only target 3.11.--
    --Guido (mobile)

  3. gvanrossum commented on Dec 4, 2021

    @gvanrossum
    Member

    This does not apply to Windows (we don’t support curses there).

  4. added
    stdlib
    and removed on Dec 4, 2021
  5. removed
    3.7 (EOL)
    3.8 (EOL)
    3.9 (EOL)
    3.10 (EOL)
    on Dec 4, 2021
  6. juliushamilton100 commented on Dec 5, 2021

    juliushamilton100mannequin
    Mannequin

    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

  7. juliushamilton100 commented on Dec 5, 2021

    juliushamilton100mannequin
    Mannequin

    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 <[email protected]> wrote:

    Change by Éric Araujo <[email protected]>:

    ----------
    stage: -> needs patch
    versions: -Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9


    Python tracker <[email protected]>
    <https://bugs.python.org/issue45934\>


  8. serhiy-storchaka commented on Dec 5, 2021

    @serhiy-storchaka
    Member

    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.

  9. gvanrossum commented on Dec 6, 2021

    @gvanrossum
    Member

    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.

  10. serhiy-storchaka commented on Dec 6, 2021

    @serhiy-storchaka
    Member

    Thank you Guido for clarification. I have found that post:

    https://mail.python.org/archives/list/[email protected]/thread/YGSMPKP7G3HO73ISEQZFAWPPGCOA3JYZ/

    I agree that it is worth to implement newterm. In particular it would be useful in tests.

  11. juliushamilton100 commented on Dec 6, 2021

    juliushamilton100mannequin
    Mannequin

    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.

  12. transferred this issue fromon Apr 10, 2022
  13. added
    3.16
    and removed
    3.11
    on Jun 19, 2026
  14. serhiy-storchaka commented on Jun 19, 2026

    @serhiy-storchaka
    Member

    It was not easy, but I finally finished it: #151748. I added also nofilter() (see #151744), it was needed for tests, which are now better with use of newterm.

  15. added
    extension-modules
    on Jun 19, 2026
  16. added 3 commits that reference this issue on Jun 24, 2026
  17. moved this from Features to Done in Curses issueson Jun 24, 2026
  18. added a commit that references this issue on Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

3.16extension-modulesstdlibtype-feature

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions