eric6/UI/DiffHighlighter.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7781
607a6098cb44
child 8218
7c09585bd960
permissions
-rw-r--r--

Updated copyright for 2021.

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
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2015 - 2021 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
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from E5Gui.E5GenericDiffHighlighter import TERMINAL, E5GenericDiffHighlighter
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 class DiffHighlighter(E5GenericDiffHighlighter):
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 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
16 """
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 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
18 """
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 Constructor
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 @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
22 """
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 super(DiffHighlighter, self).__init__(doc)
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 def generateRules(self):
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 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
28 """
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 diffHeaderBold = self.makeFormat(fg=self.textColor,
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 bg=self.headerColor,
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 bold=True)
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 diffContext = self.makeFormat(fg=self.textColor,
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 bg=self.contextColor)
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 diffAdded = self.makeFormat(fg=self.textColor,
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 bg=self.addedColor)
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 diffRemoved = self.makeFormat(fg=self.textColor,
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 bg=self.removedColor)
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 diffReplaced = self.makeFormat(fg=self.textColor,
4110
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4109
diff changeset
40 bg=self.replacedColor)
4109
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 diffBarRegex = TERMINAL(r'^\*+$')
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 diffOldRegex = TERMINAL(r'^--- ')
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 diffNewRegex = TERMINAL(r'^\+\+\+ |^\*\*\*')
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 diffContextRegex = TERMINAL(r'^@@ ')
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 diffAddedRegex = TERMINAL(r'^[+>]')
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 diffRemovedRegex = TERMINAL(r'^[-<]')
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 diffReplacedRegex = TERMINAL(r'^!')
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 self.createRules((diffBarRegex, diffHeaderBold),
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 (diffOldRegex, diffRemoved),
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 (diffNewRegex, diffAdded),
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 (diffContextRegex, diffContext),
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 (diffAddedRegex, diffAdded),
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 (diffRemovedRegex, diffRemoved),
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 (diffReplacedRegex, diffReplaced),
809b8268183d Changed the diff dialog to use the new diff highlighter logic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 )

eric ide

mercurial