From 647f556582d9a08ad8f81317f091336f984a6651 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Thu, 8 May 2025 17:17:02 -0700 Subject: [PATCH] refactor: Use str.translate for spinner unicode mapping --- aider/utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/aider/utils.py b/aider/utils.py index 128e578f2..0ace78f6d 100644 --- a/aider/utils.py +++ b/aider/utils.py @@ -284,20 +284,20 @@ class Spinner: [ #=- ] """.strip().splitlines() - xlate = ("-=#", "≈≋≣") + xlate_from, xlate_to = ("-=#", "≈≋≣") # If unicode is supported, swap the ASCII chars for nicer glyphs. if self._supports_unicode(): - scan_char, trail_char = "≣", "" - frames = [f.replace("#", scan_char).replace("-", trail_char) for f in ascii_frames] + translation_table = str.maketrans(xlate_from, xlate_to) + frames = [f.translate(translation_table) for f in ascii_frames] + self.scan_char = xlate_to[xlate_from.find("#")] else: - scan_char, _ = "#", "-" frames = ascii_frames + self.scan_char = "#" # Bounce the scanner back and forth. self.frames = frames - self.frame_idx = Spinner.last_frame_idx # Initialize from class variable - self.scan_char = scan_char + self.frame_idx = Spinner.last_frame_idx # Initialize from class variable self.width = len(frames[0]) - 2 # number of chars between the brackets self.animation_len = len(frames[0])