Skip to content

Commit d4c90a9

Browse files
Populate remote subcommand shell
Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
1 parent 1031454 commit d4c90a9

File tree

4 files changed

+254
-42
lines changed

4 files changed

+254
-42
lines changed

src/git_sim/commands.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
from typing import List, TYPE_CHECKING
66

7-
from git_sim.enums import ResetMode, StashSubCommand
87
from git_sim.settings import settings
8+
from git_sim.enums import ResetMode, StashSubCommand, RemoteSubCommand
99

1010
if TYPE_CHECKING:
1111
from manim import Scene
@@ -271,9 +271,9 @@ def rebase(
271271

272272

273273
def remote(
274-
action: str = typer.Argument(
274+
command: RemoteSubCommand = typer.Argument(
275275
default=None,
276-
help="The action to perform for the remote",
276+
help="Remote subcommand (add, rename, remove, get-url, set-url)",
277277
),
278278
remote: str = typer.Argument(
279279
default=None,
@@ -286,7 +286,7 @@ def remote(
286286
):
287287
from git_sim.remote import Remote
288288

289-
scene = Remote(action=action, remote=remote, url_or_path=url_or_path)
289+
scene = Remote(command=command, remote=remote, url_or_path=url_or_path)
290290
handle_animations(scene=scene)
291291

292292

src/git_sim/config.py

+34-14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def __init__(self, l: bool, settings: List[str]):
2424
super().__init__()
2525
self.l = l
2626
self.settings = settings
27+
self.time_per_char = 0.05
2728

2829
for i, setting in enumerate(self.settings):
2930
if " " in setting:
@@ -47,12 +48,13 @@ def construct(self):
4748

4849
def add_details(self):
4950
down_shift = m.DOWN * 0.5
50-
self.camera.frame.scale_to_fit_width(18 * 1.1)
5151
project_root = m.Rectangle(
5252
height=9.0,
5353
width=18.0,
5454
color=self.fontColor,
55-
)
55+
).move_to((0, 1000, 0))
56+
self.camera.frame.scale_to_fit_width(18 * 1.1)
57+
self.camera.frame.move_to(project_root.get_center())
5658

5759
cmd_text = m.Text(
5860
self.trim_cmd(self.cmd, 50),
@@ -87,11 +89,11 @@ def add_details(self):
8789
config_text.align_to(dot_git_text, m.UP).shift(down_shift).align_to(dot_git_text, m.LEFT).shift(m.RIGHT * 0.5)
8890

8991
if settings.animate:
90-
self.play(m.AddTextLetterByLetter(cmd_text))
91-
self.play(m.Create(project_root))
92-
self.play(m.AddTextLetterByLetter(project_root_text))
93-
self.play(m.AddTextLetterByLetter(dot_git_text))
94-
self.play(m.AddTextLetterByLetter(config_text))
92+
self.play(m.AddTextLetterByLetter(cmd_text, time_per_char=self.time_per_char))
93+
self.play(m.Create(project_root, time_per_char=self.time_per_char))
94+
self.play(m.AddTextLetterByLetter(project_root_text, time_per_char=self.time_per_char))
95+
self.play(m.AddTextLetterByLetter(dot_git_text, time_per_char=self.time_per_char))
96+
self.play(m.AddTextLetterByLetter(config_text, time_per_char=self.time_per_char))
9597
else:
9698
self.add(cmd_text)
9799
self.add(project_root)
@@ -102,23 +104,26 @@ def add_details(self):
102104
config = self.repo.config_reader()
103105
if self.l:
104106
last_element = config_text
105-
for section in config.sections():
107+
for i, section in enumerate(config.sections()):
106108
section_text = m.Text(f"[{section}]", font=self.font, color=self.fontColor, font_size=20).align_to(last_element, m.UP).shift(down_shift).align_to(config_text, m.LEFT).shift(m.RIGHT * 0.5)
107109
self.toFadeOut.add(section_text)
108110
if settings.animate:
109-
self.play(m.AddTextLetterByLetter(section_text))
111+
self.play(m.AddTextLetterByLetter(section_text, time_per_char=self.time_per_char))
110112
else:
111113
self.add(section_text)
112114
last_element = section_text
113-
for option in config.options(section):
115+
project_root = self.resize_rectangle(project_root, last_element)
116+
for j, option in enumerate(config.options(section)):
114117
if option != "__name__":
115118
option_text = m.Text(f"{option} = {config.get_value(section, option)}", font=self.font, color=self.fontColor, font_size=20).align_to(last_element, m.UP).shift(down_shift).align_to(section_text, m.LEFT).shift(m.RIGHT * 0.5)
116119
self.toFadeOut.add(option_text)
117120
last_element = option_text
118121
if settings.animate:
119-
self.play(m.AddTextLetterByLetter(option_text))
122+
self.play(m.AddTextLetterByLetter(option_text, time_per_char=self.time_per_char))
120123
else:
121124
self.add(option_text)
125+
if not (i == len(config.sections()) - 1 and j == len(config.options(section)) - 1):
126+
project_root = self.resize_rectangle(project_root, last_element)
122127
else:
123128
if not self.settings:
124129
print("git-sim error: no config option specified")
@@ -140,13 +145,12 @@ def add_details(self):
140145
elif len(self.settings) == 2:
141146
value = self.settings[1].strip('"').strip("'").strip("\\")
142147
section_text = m.Text(f"[{self.trim_cmd(section, 50)}]", font=self.font, color=self.fontColor, font_size=20, weight=m.BOLD).align_to(config_text, m.UP).shift(down_shift).align_to(config_text, m.LEFT).shift(m.RIGHT * 0.5)
143-
144148
option_text = m.Text(f"{self.trim_cmd(option, 40)} = {self.trim_cmd(value, 40)}", font=self.font, color=self.fontColor, font_size=20, weight=m.BOLD).align_to(section_text, m.UP).shift(down_shift).align_to(section_text, m.LEFT).shift(m.RIGHT * 0.5)
145149
self.toFadeOut.add(section_text)
146150
self.toFadeOut.add(option_text)
147151
if settings.animate:
148-
self.play(m.AddTextLetterByLetter(section_text))
149-
self.play(m.AddTextLetterByLetter(option_text))
152+
self.play(m.AddTextLetterByLetter(section_text, time_per_char=self.time_per_char))
153+
self.play(m.AddTextLetterByLetter(option_text, time_per_char=self.time_per_char))
150154
else:
151155
self.add(section_text)
152156
self.add(option_text)
@@ -156,3 +160,19 @@ def add_details(self):
156160
self.toFadeOut.add(project_root_text)
157161
self.toFadeOut.add(dot_git_text)
158162
self.toFadeOut.add(config_text)
163+
164+
def resize_rectangle(self, rect, last_element):
165+
if last_element.get_bottom()[1] - 3 * last_element.height > rect.get_bottom()[1]:
166+
return rect
167+
new_rect = m.Rectangle(width=rect.width, height=rect.height + 2 * last_element.height, color=rect.color)
168+
new_rect.align_to(rect, m.UP)
169+
self.toFadeOut.remove(rect)
170+
self.toFadeOut.add(new_rect)
171+
if settings.animate:
172+
self.recenter_frame()
173+
self.scale_frame()
174+
self.play(m.ReplacementTransform(rect, new_rect))
175+
else:
176+
self.remove(rect)
177+
self.add(new_rect)
178+
return new_rect

src/git_sim/enums.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ class ResetMode(Enum):
88
HARD = "hard"
99

1010

11-
class StashSubCommand(Enum):
12-
POP = "pop"
13-
APPLY = "apply"
14-
PUSH = "push"
15-
16-
1711
class ColorByOptions(Enum):
1812
AUTHOR = "author"
1913
BRANCH = "branch"
@@ -34,3 +28,17 @@ class VideoFormat(str, Enum):
3428
class ImgFormat(str, Enum):
3529
JPG = "jpg"
3630
PNG = "png"
31+
32+
33+
class StashSubCommand(Enum):
34+
POP = "pop"
35+
APPLY = "apply"
36+
PUSH = "push"
37+
38+
39+
class RemoteSubCommand(Enum):
40+
ADD = "add"
41+
RENAME = "rename"
42+
REMOVE = "remove"
43+
GET_URL = "get-url"
44+
SET_URL = "set-url"

0 commit comments

Comments
 (0)