> On 22 Dec 2020, at 09:49, Barry Scott <ba...@barrys-emacs.org> wrote:
>
> The simplest answer is
>
> print('`\x1b[2J\x1b[H')
>
> Are there any terminals that this does not work on that are in active use?
>
> Is using curses that uses termcap needed these days?
>
> Of course Windows is the outlier, but the new Windows Terminal
> supports ANSI escapes sequences and utf-8.
>
> I tested the above with Windows Terminal 1.4 on Windows 10
> and it just works.
>
> Otherwise os.system('cls') works for windows terminal and the old
> windows console stuff.
It turns out that on Windows 10 it works for old console API if you do this:
-----
import sys
def clear_terminal():
if sys.platform == 'win32':
import ctypes
kernel32 = ctypes.windll.kernel32
# turn on the console ANSI colour handling
kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7)
sys.stdout.write('\x1b[2J' '\x1b[H')
-----
The above should work in all but the old none ANSI terminals.
Barry
_______________________________________________
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/7KA7OGZKLFG6DQDV7VO7DGKOYRG72Y5D/
Code of Conduct: http://python.org/psf/codeofconduct/