src/eric7/UI/DiffHighlighter.py

Tue, 18 Oct 2022 16:06:21 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 18 Oct 2022 16:06:21 +0200
branch
eric7
changeset 9413
80c06d472826
parent 9221
bf71ee032bb4
child 9653
e67609152c5e
permissions
-rw-r--r--

Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.

4109
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
8881
54e42bc2437a Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8366
diff changeset
3 # Copyright (c) 2015 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4109
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a syntax highlighter for unified and context diff outputs.
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
9413
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
10 from eric7.EricGui.EricGenericDiffHighlighter import (
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
11 TERMINAL,
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
12 EricGenericDiffHighlighter,
80c06d472826 Changed the eric7 import statements to include the package name (i.e. eric7) in order to not fiddle with sys.path.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
13 )
4109
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
8356
68ec9c3d4de5 Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
16 class DiffHighlighter(EricGenericDiffHighlighter):
4109
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 """
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 Class implementing a diff highlighter for Git.
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
20
4109
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 def __init__(self, doc):
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
24
4109
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 @param doc reference to the text document (QTextDocument)
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
27 super().__init__(doc)
4109
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 def generateRules(self):
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 """
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 Public method to generate the rule set.
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
33 diffHeaderBold = self.makeFormat(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
34 fg=self.textColor, bg=self.headerColor, bold=True
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
35 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
36 diffContext = self.makeFormat(fg=self.textColor, bg=self.contextColor)
4109
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
38 diffAdded = self.makeFormat(fg=self.textColor, bg=self.addedColor)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
39 diffRemoved = self.makeFormat(fg=self.textColor, bg=self.removedColor)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
40 diffReplaced = self.makeFormat(fg=self.textColor, bg=self.replacedColor)
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
41
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
42 diffBarRegex = TERMINAL(r"^\*+$")
4109
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
44 diffOldRegex = TERMINAL(r"^--- ")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
45 diffNewRegex = TERMINAL(r"^\+\+\+ |^\*\*\*")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
46 diffContextRegex = TERMINAL(r"^@@ ")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
47
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
48 diffAddedRegex = TERMINAL(r"^[+>]")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
49 diffRemovedRegex = TERMINAL(r"^[-<]")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
50 diffReplacedRegex = TERMINAL(r"^!")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
51
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
52 self.createRules(
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
53 (diffBarRegex, diffHeaderBold),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
54 (diffOldRegex, diffRemoved),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
55 (diffNewRegex, diffAdded),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
56 (diffContextRegex, diffContext),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
57 (diffAddedRegex, diffAdded),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
58 (diffRemovedRegex, diffRemoved),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
59 (diffReplacedRegex, diffReplaced),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
60 )

eric ide

mercurial