Skip to content

Commit 6725e30

Browse files
Add --style option to allow different graphical styles
Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
1 parent d2ae613 commit 6725e30

File tree

8 files changed

+55
-21
lines changed

8 files changed

+55
-21
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ The `[global options]` apply to the overarching `git-sim` simulation itself, inc
150150
`--stdout`: Write raw image data to stdout while suppressing all other program output.
151151
`--output-only-path`: Only output the path to the generated media file to stdout. Useful for other programs to ingest.
152152
`--quiet, -q`: Suppress all output except errors.
153-
`--highlight-commit-messages`: Make commit message text bigger and bold, and hide commit ids.
153+
`--highlight-commit-messages`: Make commit message text bigger and bold, and hide commit ids.
154+
`--style`: Graphical style of the output image or animated video, i.e. `clean` (default) or `thick`.
154155

155156
Animation-only global options (to be used in conjunction with `--animate`):
156157

git_sim/__main__.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import typer
88

99
import git_sim.commands
10-
from git_sim.settings import ColorByOptions, ImgFormat, VideoFormat, settings
10+
from git_sim.settings import ColorByOptions, StyleOptions, ImgFormat, VideoFormat, settings
1111

1212
app = typer.Typer(context_settings={"help_option_names": ["-h", "--help"]})
1313

@@ -144,9 +144,13 @@ def main(
144144
False,
145145
"--version",
146146
"-v",
147-
help="Show the version of git-sim and exit.",
147+
help="Show the version of git-sim and exit",
148148
callback=version_callback,
149149
),
150+
style: StyleOptions = typer.Option(
151+
settings.style.value,
152+
help="Graphical style of the output image or animated video",
153+
),
150154
):
151155
import git
152156
from manim import WHITE, config
@@ -178,6 +182,7 @@ def main(
178182
settings.all = all
179183
settings.color_by = color_by
180184
settings.highlight_commit_messages = highlight_commit_messages
185+
settings.style = style
181186

182187
try:
183188
if sys.platform == "linux" or sys.platform == "darwin":

git_sim/enums.py

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ class ColorByOptions(Enum):
2121
notlocal2 = "notlocal2"
2222

2323

24+
class StyleOptions(Enum):
25+
CLEAN = "clean"
26+
THICK = "thick"
27+
28+
2429
class VideoFormat(str, Enum):
2530
mp4 = "mp4"
2631
webm = "webm"

git_sim/git_sim_base_command.py

+30-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from git.exc import GitCommandError, InvalidGitRepositoryError
1212
from git.repo import Repo
1313

14-
from git_sim.enums import ColorByOptions
14+
from git_sim.enums import ColorByOptions, StyleOptions
1515
from git_sim.settings import settings
1616

1717

@@ -62,6 +62,17 @@ def __init__(self):
6262
self.fill_opacity = 0.5
6363
self.ref_fill_opacity = 1.0
6464

65+
if settings.style == StyleOptions.CLEAN:
66+
self.commit_stroke_width = 5
67+
self.arrow_stroke_width = 5
68+
self.arrow_tip_shape = m.ArrowTriangleFilledTip
69+
self.font_weight = m.NORMAL
70+
elif settings.style == StyleOptions.THICK:
71+
self.commit_stroke_width = 30
72+
self.arrow_stroke_width = 10
73+
self.arrow_tip_shape = m.StealthTip
74+
self.font_weight = m.BOLD
75+
6576
def init_repo(self):
6677
try:
6778
self.repo = Repo(search_parent_directories=True)
@@ -243,6 +254,7 @@ def draw_commit(self, commit, i, prevCircle, shift=numpy.array([0.0, 0.0, 0.0]))
243254

244255
circle = m.Circle(
245256
stroke_color=commit_fill,
257+
stroke_width=self.commit_stroke_width,
246258
fill_color=commit_fill,
247259
fill_opacity=self.fill_opacity,
248260
)
@@ -280,7 +292,7 @@ def draw_commit(self, commit, i, prevCircle, shift=numpy.array([0.0, 0.0, 0.0]))
280292
)
281293
end = self.drawnCommits[commit.hexsha].get_center()
282294

283-
arrow = m.Arrow(start, end, color=self.fontColor)
295+
arrow = m.Arrow(start, end, color=self.fontColor, stroke_width=self.arrow_stroke_width, tip_shape=self.arrow_tip_shape, max_stroke_width_to_length_ratio=1000)
284296

285297
if commit == "dark":
286298
arrow = m.Arrow(
@@ -299,7 +311,7 @@ def draw_commit(self, commit, i, prevCircle, shift=numpy.array([0.0, 0.0, 0.0]))
299311
for commitCircle in self.drawnCommits.values():
300312
inter = m.Intersection(lineRect, commitCircle)
301313
if inter.has_points():
302-
arrow = m.CurvedArrow(start, end, color=self.fontColor)
314+
arrow = m.CurvedArrow(start, end, color=self.fontColor, stroke_width=self.arrow_stroke_width, tip_shape=self.arrow_tip_shape)
303315
if start[1] == end[1]:
304316
arrow.shift(m.UP * 1.25)
305317
if start[0] < end[0] and start[1] == end[1]:
@@ -320,7 +332,7 @@ def draw_commit(self, commit, i, prevCircle, shift=numpy.array([0.0, 0.0, 0.0]))
320332
font="Monospace",
321333
font_size=20 if settings.highlight_commit_messages else 14,
322334
color=self.fontColor,
323-
weight=m.BOLD if settings.highlight_commit_messages else m.NORMAL,
335+
weight=m.BOLD if settings.highlight_commit_messages or settings.style == StyleOptions.THICK else m.NORMAL,
324336
).next_to(circle, m.DOWN)
325337

326338
if settings.animate and commit != "dark" and isNewCommit:
@@ -373,14 +385,15 @@ def get_nonparent_branch_names(self):
373385
def build_commit_id_and_message(self, commit, i):
374386
hide_refs = False
375387
if commit == "dark":
376-
commitId = m.Text("", font="Monospace", font_size=20, color=self.fontColor)
388+
commitId = m.Text("", font="Monospace", font_size=20, color=self.fontColor, weight=self.font_weight)
377389
commitMessage = ""
378390
else:
379391
commitId = m.Text(
380392
commit.hexsha[0:6],
381393
font="Monospace",
382394
font_size=20,
383395
color=self.fontColor,
396+
weight=self.font_weight,
384397
)
385398
commitMessage = commit.message.split("\n")[0][:40].replace("\n", " ")
386399
return commitId, commitMessage, commit, hide_refs
@@ -397,7 +410,7 @@ def draw_head(self, commit, i, commitId):
397410
else:
398411
headbox.next_to(commitId, m.UP)
399412
headText = m.Text(
400-
"HEAD", font="Monospace", font_size=20, color=self.fontColor
413+
"HEAD", font="Monospace", font_size=20, color=self.fontColor, weight=self.font_weight,
401414
).move_to(headbox.get_center())
402415

403416
head = m.VGroup(headbox, headText)
@@ -444,7 +457,7 @@ def draw_branch(self, commit, i, make_branches_remote=False):
444457
)
445458

446459
branchText = m.Text(
447-
text, font="Monospace", font_size=20, color=self.fontColor
460+
text, font="Monospace", font_size=20, color=self.fontColor, weight=self.font_weight,
448461
)
449462
branchRec = m.Rectangle(
450463
color=m.GREEN,
@@ -490,6 +503,7 @@ def draw_tag(self, commit, i):
490503
font="Monospace",
491504
font_size=20,
492505
color=self.fontColor,
506+
weight=self.font_weight,
493507
)
494508
tagRec = m.Rectangle(
495509
color=m.YELLOW,
@@ -653,6 +667,7 @@ def setup_and_draw_zones(
653667
font="Monospace",
654668
font_size=28,
655669
color=self.fontColor,
670+
weight=m.BOLD,
656671
)
657672
.move_to((vert1.get_center()[0] - 4, 0, 0))
658673
.shift(m.UP * self.zone_title_offset)
@@ -663,6 +678,7 @@ def setup_and_draw_zones(
663678
font="Monospace",
664679
font_size=28,
665680
color=self.fontColor,
681+
weight=m.BOLD,
666682
)
667683
.move_to(self.camera.frame.get_center())
668684
.align_to(firstColumnTitle, m.UP)
@@ -673,6 +689,7 @@ def setup_and_draw_zones(
673689
font="Monospace",
674690
font_size=28,
675691
color=self.fontColor,
692+
weight=m.BOLD,
676693
)
677694
.move_to((vert2.get_center()[0] + 4, 0, 0))
678695
.align_to(firstColumnTitle, m.UP)
@@ -985,7 +1002,7 @@ def setup_and_draw_parent(
9851002
color=m.RED,
9861003
):
9871004
circle = m.Circle(
988-
stroke_color=color, fill_color=color, fill_opacity=self.ref_fill_opacity
1005+
stroke_color=color, stroke_width=self.commit_stroke_width, fill_color=color, fill_opacity=self.ref_fill_opacity
9891006
)
9901007
circle.height = 1
9911008
circle.next_to(
@@ -997,12 +1014,12 @@ def setup_and_draw_parent(
9971014

9981015
start = circle.get_center()
9991016
end = self.drawnCommits[child.hexsha].get_center()
1000-
arrow = m.Arrow(start, end, color=self.fontColor)
1017+
arrow = m.Arrow(start, end, color=self.fontColor, stroke_width=self.arrow_stroke_width, tip_shape=self.arrow_tip_shape, max_stroke_width_to_length_ratio=1000)
10011018
length = numpy.linalg.norm(start - end) - (1.5 if start[1] == end[1] else 3)
10021019
arrow.set_length(length)
10031020

10041021
commitId = m.Text(
1005-
"abcdef", font="Monospace", font_size=20, color=self.fontColor
1022+
"abcdef", font="Monospace", font_size=20, color=self.fontColor, weight=self.font_weight,
10061023
).next_to(circle, m.UP)
10071024
self.toFadeOut.add(commitId)
10081025

@@ -1014,6 +1031,7 @@ def setup_and_draw_parent(
10141031
font="Monospace",
10151032
font_size=14,
10161033
color=self.fontColor,
1034+
weight=self.font_weight,
10171035
).next_to(circle, m.DOWN)
10181036
self.toFadeOut.add(message)
10191037

@@ -1061,7 +1079,7 @@ def get_nondark_commits(self):
10611079
return nondark_commits
10621080

10631081
def draw_ref(self, commit, top, i=0, text="HEAD", color=m.BLUE):
1064-
refText = m.Text(text, font="Monospace", font_size=20, color=self.fontColor)
1082+
refText = m.Text(text, font="Monospace", font_size=20, color=self.fontColor, weight=self.font_weight)
10651083
refbox = m.Rectangle(
10661084
color=color,
10671085
fill_color=color,
@@ -1196,6 +1214,7 @@ def color_by(self, offset=0):
11961214
font="Monospace",
11971215
font_size=36,
11981216
color=self.colors[int(i % 11)],
1217+
weight=self.font_weight,
11991218
)
12001219
authorText.move_to(
12011220
[(-5 - offset) if settings.reverse else (5 + offset), -i, 0]

git_sim/merge.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def construct(self):
8383
if head_commit.hexsha in self.drawnCommits:
8484
start = self.drawnCommits["abcdef"].get_center()
8585
end = self.drawnCommits[head_commit.hexsha].get_center()
86-
arrow = m.CurvedArrow(start, end, color=self.fontColor)
86+
arrow = m.CurvedArrow(start, end, color=self.fontColor, stroke_width=self.arrow_stroke_width, tip_shape=self.arrow_tip_shape)
8787
self.draw_arrow(True, arrow)
8888

8989
reset_head_to = "abcdef"
@@ -152,7 +152,10 @@ def construct(self):
152152
self.repo.git.clear_cache()
153153

154154
# Delete the local clone
155-
shutil.rmtree(new_dir, onerror=self.del_rw)
155+
try:
156+
shutil.rmtree(new_dir, onerror=self.del_rw)
157+
except (FileNotFoundError, UnboundLocalError):
158+
pass
156159

157160
def check_merge_conflict(self, branch1, branch2):
158161
git_root = self.repo.git.rev_parse("--show-toplevel")

git_sim/rebase.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def setup_and_draw_parent(
111111
shift=numpy.array([0.0, 0.0, 0.0]),
112112
draw_arrow=True,
113113
):
114-
circle = m.Circle(stroke_color=m.RED, fill_color=m.RED, fill_opacity=0.25)
114+
circle = m.Circle(stroke_color=m.RED, stroke_width=self.commit_stroke_width, fill_color=m.RED, fill_opacity=0.25)
115115
circle.height = 1
116116
circle.next_to(
117117
self.drawnCommits[child],
@@ -122,7 +122,7 @@ def setup_and_draw_parent(
122122

123123
start = circle.get_center()
124124
end = self.drawnCommits[child].get_center()
125-
arrow = m.Arrow(start, end, color=self.fontColor)
125+
arrow = m.Arrow(start, end, color=self.fontColor, stroke_width=self.arrow_stroke_width, tip_shape=self.arrow_tip_shape, max_stroke_width_to_length_ratio=1000)
126126
length = numpy.linalg.norm(start - end) - (1.5 if start[1] == end[1] else 3)
127127
arrow.set_length(length)
128128

git_sim/revert.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def build_commit_id_and_message(self, commit, i):
9191
return commitId, commitMessage, commit, hide_refs
9292

9393
def setup_and_draw_revert_commit(self):
94-
circle = m.Circle(stroke_color=m.RED, fill_color=m.RED, fill_opacity=0.25)
94+
circle = m.Circle(stroke_color=m.RED, stroke_width=self.commit_stroke_width, fill_color=m.RED, fill_opacity=0.25)
9595
circle.height = 1
9696
circle.next_to(
9797
self.drawnCommits[self.get_commit().hexsha],
@@ -101,7 +101,7 @@ def setup_and_draw_revert_commit(self):
101101

102102
start = circle.get_center()
103103
end = self.drawnCommits[self.get_commit().hexsha].get_center()
104-
arrow = m.Arrow(start, end, color=self.fontColor)
104+
arrow = m.Arrow(start, end, color=self.fontColor, stroke_width=self.arrow_stroke_width, tip_shape=self.arrow_tip_shape, max_stroke_width_to_length_ratio=1000)
105105
length = numpy.linalg.norm(start - end) - (1.5 if start[1] == end[1] else 3)
106106
arrow.set_length(length)
107107

git_sim/settings.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from pydantic import BaseSettings
55

6-
from git_sim.enums import ColorByOptions, ImgFormat, VideoFormat
6+
from git_sim.enums import StyleOptions, ColorByOptions, ImgFormat, VideoFormat
77

88

99
class Settings(BaseSettings):
@@ -39,6 +39,7 @@ class Settings(BaseSettings):
3939
all = False
4040
color_by: Union[ColorByOptions, None] = None
4141
highlight_commit_messages = False
42+
style: Union[StyleOptions, None] = StyleOptions.CLEAN
4243

4344
class Config:
4445
env_prefix = "git_sim_"

0 commit comments

Comments
 (0)