> On 22 Dec 2020, at 12:39, Eryk Sun <eryk...@gmail.com> wrote:
>
> On 12/22/20, Barry Scott <ba...@barrys-emacs.org> wrote:
>>
>> 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')
>
> Here are some concerns I have:
>
> * Does not support Windows 8
> * Does not support legacy console in Windows 10 (on the "options" tab)
> * Does not check for SetConsoleMode failure
> * Does not support a different active screen buffer
> * Assumes StandardOutput is a screen buffer for the current console
> * Assumes the current mode of the screen buffer is 3 or 7. New modes
> have been added, and even more may be added
> * Sets a global console setting that persists after Python exits
>
snip...
Eryk,
Does this work for you:
import sys, os
def clear():
if sys.playform == 'win32':
os.system('cls')
else:
sys.stdout.write('\x1b[2J' '\x1b[H')
No need to address the list above because CLS does it.
No concern about CLS being a trojan becuse as a builtin to CMD and PowerShell
and it takes priority over cls.bat etc.
For all other platforms I'm assuming the VT100 level of ANSI escape sequences
is supported.
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/5SCM3VKDQORXYAEWBURP7IULSUYB6RUR/
Code of Conduct: http://python.org/psf/codeofconduct/