src/eric7/UI/DiffHighlighter.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
5 5
6 """ 6 """
7 Module implementing a syntax highlighter for unified and context diff outputs. 7 Module implementing a syntax highlighter for unified and context diff outputs.
8 """ 8 """
9 9
10 from EricGui.EricGenericDiffHighlighter import ( 10 from EricGui.EricGenericDiffHighlighter import TERMINAL, EricGenericDiffHighlighter
11 TERMINAL, EricGenericDiffHighlighter
12 )
13 11
14 12
15 class DiffHighlighter(EricGenericDiffHighlighter): 13 class DiffHighlighter(EricGenericDiffHighlighter):
16 """ 14 """
17 Class implementing a diff highlighter for Git. 15 Class implementing a diff highlighter for Git.
18 """ 16 """
17
19 def __init__(self, doc): 18 def __init__(self, doc):
20 """ 19 """
21 Constructor 20 Constructor
22 21
23 @param doc reference to the text document (QTextDocument) 22 @param doc reference to the text document (QTextDocument)
24 """ 23 """
25 super().__init__(doc) 24 super().__init__(doc)
26 25
27 def generateRules(self): 26 def generateRules(self):
28 """ 27 """
29 Public method to generate the rule set. 28 Public method to generate the rule set.
30 """ 29 """
31 diffHeaderBold = self.makeFormat(fg=self.textColor, 30 diffHeaderBold = self.makeFormat(
32 bg=self.headerColor, 31 fg=self.textColor, bg=self.headerColor, bold=True
33 bold=True) 32 )
34 diffContext = self.makeFormat(fg=self.textColor, 33 diffContext = self.makeFormat(fg=self.textColor, bg=self.contextColor)
35 bg=self.contextColor)
36 34
37 diffAdded = self.makeFormat(fg=self.textColor, 35 diffAdded = self.makeFormat(fg=self.textColor, bg=self.addedColor)
38 bg=self.addedColor) 36 diffRemoved = self.makeFormat(fg=self.textColor, bg=self.removedColor)
39 diffRemoved = self.makeFormat(fg=self.textColor, 37 diffReplaced = self.makeFormat(fg=self.textColor, bg=self.replacedColor)
40 bg=self.removedColor)
41 diffReplaced = self.makeFormat(fg=self.textColor,
42 bg=self.replacedColor)
43
44 diffBarRegex = TERMINAL(r'^\*+$')
45 38
46 diffOldRegex = TERMINAL(r'^--- ') 39 diffBarRegex = TERMINAL(r"^\*+$")
47 diffNewRegex = TERMINAL(r'^\+\+\+ |^\*\*\*') 40
48 diffContextRegex = TERMINAL(r'^@@ ') 41 diffOldRegex = TERMINAL(r"^--- ")
49 42 diffNewRegex = TERMINAL(r"^\+\+\+ |^\*\*\*")
50 diffAddedRegex = TERMINAL(r'^[+>]') 43 diffContextRegex = TERMINAL(r"^@@ ")
51 diffRemovedRegex = TERMINAL(r'^[-<]') 44
52 diffReplacedRegex = TERMINAL(r'^!') 45 diffAddedRegex = TERMINAL(r"^[+>]")
53 46 diffRemovedRegex = TERMINAL(r"^[-<]")
54 self.createRules((diffBarRegex, diffHeaderBold), 47 diffReplacedRegex = TERMINAL(r"^!")
55 (diffOldRegex, diffRemoved), 48
56 (diffNewRegex, diffAdded), 49 self.createRules(
57 (diffContextRegex, diffContext), 50 (diffBarRegex, diffHeaderBold),
58 (diffAddedRegex, diffAdded), 51 (diffOldRegex, diffRemoved),
59 (diffRemovedRegex, diffRemoved), 52 (diffNewRegex, diffAdded),
60 (diffReplacedRegex, diffReplaced), 53 (diffContextRegex, diffContext),
61 ) 54 (diffAddedRegex, diffAdded),
55 (diffRemovedRegex, diffRemoved),
56 (diffReplacedRegex, diffReplaced),
57 )

eric ide

mercurial