[Python-ideas] Suggestion: Clear screen command for the REPL

Chris Angelico rosuav at gmail.com
Mon Sep 19 04:38:00 EDT 2016


On Mon, Sep 19, 2016 at 6:31 PM, Paul Moore <p.f.moore at gmail.com> wrote:
> On 19 September 2016 at 03:40, Chris Angelico <rosuav at gmail.com> wrote:
>> On Mon, Sep 19, 2016 at 12:32 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>>> (The fallback if all else fails is easy: get the height of the terminal,
>>> in lines, and print that many blank lines.)
>>
>> Assuming you can get the height in lines. Have you tried that in the
>> default Windows shell? I don't think tcgetattr works on Windows.
>
> shutil.get_terminal_size() is available on all platforms.
>
> I don't think it would be unreasonable to add shutil.clear_terminal()
> (at the moment, get_terminal_size is the only "terminal handling"
> function in shutil, but it would be the obvious place to add others if
> we chose to do so).

Sounds good to me. This is definitely sounding complicated and messy
enough to justify (a) writing a function to clear the screen, and (b)
testing that function thoroughly as a PyPI module before pushing
anything into the stdlib.

ChrisA


More information about the Python-ideas mailing list