Python ANSI VT100 implementation of Erase Screen
uv add vtclear
or
pip install vtclear
from vtclear import clear_screen
clear_screen()The escape sequence itself is exported too, in case you want to write it somewhere other than stdout:
import sys
from vtclear import CLEAR_SCREEN
sys.stderr.write(CLEAR_SCREEN)
sys.stderr.flush() # no newline in the sequence, so flush by handAny VT100 compatible terminal reads the sequence, Windows Terminal included:
it has been the default host on Windows 11 since 22H2. The exception is the
classic console host, conhost.exe, still the default on Windows 10, where
virtual terminal processing stays off unless something turns it on and CPython
does not. There the sequence is printed verbatim instead of clearing, and
enabling it is the caller's job, e.g. through
colorama.just_fix_windows_console().
This project is licensed under the MIT License.
