eric6/Plugins/VcsPlugins/vcsMercurial/HgDiffHighlighter.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 7780
41420f82c0ac
child 8218
7c09585bd960
permissions
-rw-r--r--

Updated copyright for 2021.

4110
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
3 # Copyright (c) 2015 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
4110
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a syntax highlighter for unified and context diff outputs.
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from E5Gui.E5GenericDiffHighlighter import TERMINAL, E5GenericDiffHighlighter
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 class HgDiffHighlighter(E5GenericDiffHighlighter):
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 """
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 Class implementing a diff highlighter for Git.
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 """
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 def __init__(self, doc):
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 Constructor
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 @param doc reference to the text document (QTextDocument)
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 super(HgDiffHighlighter, self).__init__(doc)
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 def generateRules(self):
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Public method to generate the rule set.
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 diffHeader = self.makeFormat(fg=self.textColor,
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 bg=self.headerColor)
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 diffContext = self.makeFormat(fg=self.textColor,
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 bg=self.contextColor)
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 diffAdded = self.makeFormat(fg=self.textColor,
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 bg=self.addedColor)
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 diffRemoved = self.makeFormat(fg=self.textColor,
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 bg=self.removedColor)
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 diffHeaderRegex = TERMINAL(r'^diff -r ')
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 diffOldRegex = TERMINAL(r'^--- ')
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 diffNewRegex = TERMINAL(r'^\+\+\+ ')
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 diffContextRegex = TERMINAL(r'^@@ ')
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 diffAddedRegex = TERMINAL(r'^\+')
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 diffRemovedRegex = TERMINAL(r'^-')
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 self.createRules((diffOldRegex, diffRemoved),
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 (diffNewRegex, diffAdded),
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 (diffContextRegex, diffContext),
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 (diffHeaderRegex, diffHeader),
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 (diffAddedRegex, diffAdded),
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 (diffRemovedRegex, diffRemoved),
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 )

eric ide

mercurial