Skip to content

Commit 371e3b0

Browse files
committed
add changing colour scheme
1 parent 8fa57c4 commit 371e3b0

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

Preferences.sublime-settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"gitblame.scheme": "dark"
3+
}

git-blame.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,35 @@
66
from subprocess import check_output as shell
77

88

9-
blame_cache = {}
10-
template = '''
11-
<span>
9+
template_scheme = {}
10+
template_scheme['light'] = '''
1211
<style>
13-
span {{
12+
span {
13+
background-color: #aee;
14+
color: #444;
15+
}
16+
strong, a {
17+
text-decoration: none;
18+
color: #000;
19+
}
20+
</style>
21+
'''
22+
template_scheme['dark'] = '''
23+
<style>
24+
span {
1425
background-color: brown;
15-
}}
16-
a {{
26+
}
27+
a {
1728
text-decoration: none;
18-
}}
29+
}
1930
</style>
31+
'''
32+
33+
template = '''
34+
<span>
35+
{scheme}
2036
<strong>Git Blame:</strong> ({user})
21-
Updated: {date} {time} |
37+
Updated: {date} {time} |
2238
<a href="copy-{sha}">[{sha}]</a> |
2339
<a href="close">
2440
<close>X</close>&nbsp;
@@ -58,7 +74,7 @@ def parse_blame(self, blame):
5874
file_path = None
5975

6076
# Fix an issue where the username has a space
61-
# Im going to need to do something better though if people
77+
# Im going to need to do something better though if people
6278
# start to have multiple spaces in their names.
6379
if not isinstance(date[0], int):
6480
user = "{0} {1}".format(user, date)
@@ -70,7 +86,7 @@ def on_phantom_close(self, href):
7086
if href.startswith('copy'):
7187
sha = href.replace('copy-','')
7288
sublime.set_clipboard(sha)
73-
89+
7490
self.view.erase_phantoms('git-blame')
7591

7692

@@ -82,13 +98,18 @@ def run(self, edit):
8298
line = self.view.line(region)
8399
(row, col) = self.view.rowcol(region.begin())
84100
full_path = self.view.file_name()
85-
result = self.get_blame(int(row)+1, full_path)
101+
result = self.get_blame(int(row) + 1, full_path)
86102
if not result:
87103
# Unable to get blame
88104
return
89105

90106
sha, user, date, time = self.parse_blame(result)
91-
body = template.format(sha=sha, user=user, date=date, time=time)
107+
108+
settings = sublime.load_settings('Preferences.sublime-settings')
109+
scheme_color = settings.get('gitblame.scheme') or 'dark'
110+
111+
body = template.format(sha=sha, user=user, date=date, time=time,
112+
scheme=template_scheme.get(scheme_color, ''))
92113

93114
phantom = sublime.Phantom(line, body, sublime.LAYOUT_BLOCK, self.on_phantom_close)
94115
phantoms.append(phantom)

0 commit comments

Comments
 (0)