refactor: Move charset test to separate method in Spinner class

This commit is contained in:
Paul Gauthier 2024-12-05 14:57:13 -08:00 committed by Paul Gauthier (aider)
parent 3016d7b8f3
commit 73205b1f8c

View file

@ -277,7 +277,12 @@ class Spinner:
self.last_update = 0
self.visible = False
self.is_tty = sys.stdout.isatty()
self.tested = False
def test_charset(self):
if self.tested:
return
self.tested = True
# Try unicode first, fall back to ascii if needed
try:
# Test if we can print unicode characters
@ -303,6 +308,7 @@ class Spinner:
if not self.visible:
return
self.test_charset()
print(f"\r{self.text} {next(self.spinner_chars)}\r{self.text} ", end="", flush=True)
def end(self):