Skip to content

Get Original Shell Terminal Width #13713

@George-Ogden

Description

@George-Ogden

What's the problem this feature will solve?

Allows developers to access the terminal width during test runtime (useful for many pretty printing libraries).

Describe the solution you'd like

Ideally, I would like to be able to do:

width, _ = shutil.get_terminal_size(fallback=(80, 24)) # still use shutil
os.get_terminal_size(sys.__stderr__.fileno()) # use a specific file descriptor

But more realistically, I could access the default terminal and view its width:

from _pytest._io.terminalwriter import default_terminal
print(default_terminal.fullwidth)

Alternative Solutions

Looking at previous issues, the only relevant one seems to be #92.
This suggests that I can do:

from _pytest._io.terminalwriter import get_terminal_width
print(get_terminal_width())

However, this fails while the test is running, falling back to the default of 80 instead of the original terminal width.

There may be a way to do this already or it may be infeasible to implement, but I'd be interested to hear what you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions