Browse Source

[F] Fix choice saving

Azalea (on HyDEV-Daisy) 2 years ago
parent
commit
de0d381ee2
1 changed files with 11 additions and 10 deletions
  1. 11 10
      hyfetch/main.py

+ 11 - 10
hyfetch/main.py

@@ -186,9 +186,9 @@ def create_config() -> Config:
         asc = get_distro_ascii()
         asc = get_distro_ascii()
         asc_width = ascii_size(asc)[0]
         asc_width = ascii_size(asc)[0]
         fore_back = get_fore_back()
         fore_back = get_fore_back()
-        asciis = [
-            [*ColorAlignment('horizontal', fore_back=fore_back).recolor_ascii(asc, _prs).split('\n'), 'Horizontal'.center(asc_width)],
-            [*ColorAlignment('vertical').recolor_ascii(asc, _prs).split('\n'), 'Vertical'.center(asc_width)],
+        arrangements = [
+            ('Horizontal', ColorAlignment('horizontal', fore_back=fore_back)),
+            ('Vertical', ColorAlignment('vertical'))
         ]
         ]
         ascii_per_row = TERM_LEN // (asc_width + 2)
         ascii_per_row = TERM_LEN // (asc_width + 2)
 
 
@@ -204,8 +204,8 @@ def create_config() -> Config:
         else:
         else:
             choices = random.sample(perm, random_count)
             choices = random.sample(perm, random_count)
         choices = [{i + 1: n for i, n in enumerate(c)} for c in choices]
         choices = [{i + 1: n for i, n in enumerate(c)} for c in choices]
-        asciis += [[*ColorAlignment('custom', r).recolor_ascii(asc, _prs).split('\n'), f'random{i}'.center(asc_width)]
-                   for i, r in enumerate(choices)]
+        arrangements += [(f'random{i}', ColorAlignment('custom', r)) for i, r in enumerate(choices)]
+        asciis = [[*ca.recolor_ascii(asc, _prs).split('\n'), k.center(asc_width)] for k, ca in arrangements]
 
 
         while asciis:
         while asciis:
             current = asciis[:ascii_per_row]
             current = asciis[:ascii_per_row]
@@ -224,12 +224,13 @@ def create_config() -> Config:
         if choice == 'roll':
         if choice == 'roll':
             continue
             continue
 
 
-        if choice in ['horizontal', 'vertical']:
-            color_alignment = ColorAlignment(choice)
-        elif choice.startswith('random'):
-            color_alignment = ColorAlignment('custom', choices[int(choice[6])])
+        # Save choice
+        arrangement_index = {k.lower(): ca for k, ca in arrangements}
+        if choice in arrangement_index:
+            color_alignment = arrangement_index[choice]
         else:
         else:
-            raise NotImplementedError()
+            print('Invalid choice.')
+            continue
 
 
         break
         break