kt_git.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:sublimeplugins 作者: ktuan89 项目源码 文件源码
def run(self, edit):
        (viewport_x, viewport_y) = self.view.viewport_position()
        path = gitPath(self.view.window())
        current_path = self.view.file_name()
        if current_path is not None and current_path.startswith(path):
            remaining_path = current_path[len(path):]
            command = ("cd '{0}';git blame --show-email '{1}'").format(path, remaining_path)

            output, _ = run_bash_for_output(command)
            lines = output.split('\n')

            line_count = 0

            regions = self.view.lines(sublime.Region(0, self.view.size()))
            phantoms = []

            last_hash = None

            for line in lines:
                matches = re.search(r'^([0-9a-z]+).*?\(<(.*?)>', line)
                # print(line, ' ', matches)
                if matches is not None and line_count < len(regions):
                    hash = matches.group(1)
                    email = matches.group(2)
                    at_position = email.find("@")
                    if at_position != -1:
                        email = email[:at_position]
                    if len(email) > 10:
                        email = email[:10]
                    email = "{:*>10}".format(email)

                    if hash == last_hash:
                        email = "." * 10
                        html = "<b>{0}</b>".format(email)
                    else:
                        html = "<a href='{0}'>{1}</a>".format(hash, email)

                    last_hash = hash

                    r = regions[line_count]
                    phantom = Phantom(sublime.Region(r.begin(), r.begin()), html, sublime.LAYOUT_INLINE, lambda link: self.click(link) )
                    phantoms.append(phantom)

                line_count = line_count + 1
            global phantomSet
            phantomSet = PhantomSet(self.view, 'git_blame')
            phantomSet.update(phantoms)
            global viewIdToPhantomSet
            viewIdToPhantomSet[self.view.id()] = phantomSet
            self.view.set_viewport_position((0, viewport_y))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号