On Mon, Dec 21, 2020 at 08:22:35AM +1100, Cameron Simpson wrote:
Anyway, I think it should be in curses (or be loaded via curses on demand), and just have a clear_screen function thus:
def clear_screen(): setupterm() print(ti_getstr('cl'), end='', flush=True)
is it so bad to use a subprocess?
Yes. It is _really slow_, depends on external reaources which might not be there, and subprocess brings other burdens too. Python comes with curses and that knows directly how to do this.
Do you have benchmarks showing that shelling out to "clear" or "cls" is actually slower than running the full curses machinery for this?
IPython claims that the magic `%clear` command shells out to `clear`, are there complaints about the time it takes to clear the screen?
On my computer, shelling out to "clear" takes about one hundredth of a millisecond, which in interactive use is pretty much instantaneous. Do you have examples of tight loops where this would be a bottleneck?
Other than performance, are there any other reasons why we shouldn't just use `os.system('clear')` (or equivalent on Windows) and delegate to the shell command for this?
I guess there could be unusual platforms with no shell clear command, so we might need a fallback.