On 2020-10-13 06:19, Stestagg wrote:
For example, the pypi `console` library provides a method: `console.sc.reset()` that behaves similarly to `CLS` on windows and also appears to be fairly reliable cross-platform.


Yes, there is more to it than appears at first glance. There is resetting the terminal, clearing the currently visible screen, and/or the scrollback buffer as well.

The legacy Windows console has another limitation in that I don't believe it has a single API call to clear the whole thing. One must iterate over the whole buffer and write spaces to each cell, or some similar craziness. That's why even folks writing C++ just punt and do a system("cls") instead.

With the mentioned lib console, the example above prints the ANSI codes to do a terminal reset, and while that works widely these days, it should not be the first choice. It would be better to use the cross-platform wrapper functions in the console.utils module, either:

    # A DOS-like reset, clears screen and scrollback, also aliased to cls()
    reset_terminal()

    # A Unix-like clear, configurable via param, and aliased to clear()
    clear_screen()

-Mike
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/MX54AOXMYJHGRVOO2XW3J7JWHQDDUKPQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to