Skip to content

Commit

Permalink
flush output on clear() to improve responsiveness
Browse files Browse the repository at this point in the history
  • Loading branch information
belliriccardo authored and davidism committed Jun 30, 2023
1 parent dcdca58 commit 8924144
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Unreleased
- Bash version detection doesn't fail on Windows. :issue:`2461`
- Completion works if there is a dot (``.``) in the program name. :issue:`2166`
- Improve type annotations for pyright type checker. :issue:`2268`
- Improve responsiveness of ``click.clear()``. :issue:`2284`


Version 8.1.3
Expand Down
9 changes: 3 additions & 6 deletions src/click/termui.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import inspect
import io
import itertools
import os
import sys
import typing as t
from gettext import gettext as _

from ._compat import isatty
from ._compat import strip_ansi
from ._compat import WIN
from .exceptions import Abort
from .exceptions import UsageError
from .globals import resolve_color_default
Expand Down Expand Up @@ -443,10 +441,9 @@ def clear() -> None:
"""
if not isatty(sys.stdout):
return
if WIN:
os.system("cls")
else:
sys.stdout.write("\033[2J\033[1;1H")

# ANSI escape \033[2J clears the screen, \033[1;1H moves the cursor
echo("\033[2J\033[1;1H", nl=False)


def _interpret_color(
Expand Down

0 comments on commit 8924144

Please sign in to comment.