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