eric6/E5Gui/E5GenericDiffHighlighter.py

Sat, 27 Feb 2021 12:08:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 27 Feb 2021 12:08:23 +0100
changeset 8138
169e65a6787c
parent 7923
91e843545d9a
child 8143
2c730d5fd177
permissions
-rw-r--r--

Shell: added functionality to show a prompt when the main client process has exited (e.g. a script ended).

4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a 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>
4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a syntax highlighter for diff outputs.
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import re
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
5765
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
12 from PyQt5.QtGui import QSyntaxHighlighter, QTextCharFormat, QFont
4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 import Preferences
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
4110
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4109
diff changeset
16
4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 def TERMINAL(pattern):
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 Function to mark a pattern as the final one to search for.
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 @param pattern pattern to be marked (string)
4110
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4109
diff changeset
22 @return marked pattern (string)
4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 return "__TERMINAL__:{0}".format(pattern)
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 # Cache the results of re.compile for performance reasons
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 _REGEX_CACHE = {}
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28
4110
5a106c734527 Added diff syntax highlighters to the various VCS interfaces.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4109
diff changeset
29
4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 class E5GenericDiffHighlighter(QSyntaxHighlighter):
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 Class implementing a generic diff highlighter.
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 def __init__(self, doc):
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 """
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 Constructor
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 @param doc reference to the text document (QTextDocument)
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 super(E5GenericDiffHighlighter, self).__init__(doc)
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41
5765
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
42 self.regenerateRules()
4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
5765
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
44 def __initColours(self):
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
45 """
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
46 Private method to initialize the highlighter colours.
4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 """
5765
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
48 self.textColor = Preferences.getDiffColour("TextColor")
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
49 self.addedColor = Preferences.getDiffColour("AddedColor")
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
50 self.removedColor = Preferences.getDiffColour("RemovedColor")
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
51 self.replacedColor = Preferences.getDiffColour("ReplacedColor")
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
52 self.contextColor = Preferences.getDiffColour("ContextColor")
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
53 self.headerColor = Preferences.getDiffColour("HeaderColor")
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
54 self.whitespaceColor = Preferences.getDiffColour("BadWhitespaceColor")
4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 def createRules(self, *rules):
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 """
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 Public method to create the highlighting rules.
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 @param rules set of highlighting rules (list of tuples of rule
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 pattern (string) and highlighting format (QTextCharFormat))
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
6187
2cc7e3629784 Started to fix some unused loop variable warnings.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
63 for _idx, ruleFormat in enumerate(rules):
4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 rule, formats = ruleFormat
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 terminal = rule.startswith(TERMINAL(''))
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 if terminal:
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 rule = rule[len(TERMINAL('')):]
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 try:
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 regex = _REGEX_CACHE[rule]
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 except KeyError:
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 regex = _REGEX_CACHE[rule] = re.compile(rule)
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 self._rules.append((regex, formats, terminal))
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 def formats(self, line):
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 """
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 Public method to determine the highlighting formats for a line of
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 text.
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 @param line text line to be highlighted (string)
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 @return list of matched highlighting rules (list of tuples of match
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 object and format (QTextCharFormat))
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 """
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 matched = []
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 for rx, formats, terminal in self._rules:
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 match = rx.match(line)
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 if not match:
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 continue
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 matched.append([match, formats])
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 if terminal:
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 return matched
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 return matched
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 def makeFormat(self, fg=None, bg=None, bold=False):
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 """
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 Public method to generate a format definition.
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 @param fg foreground color (QColor)
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 @param bg background color (QColor)
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 @param bold flag indicating bold text (boolean)
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 @return format definiton (QTextCharFormat)
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 """
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 font = Preferences.getEditorOtherFonts("MonospacedFont")
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
104 charFormat = QTextCharFormat()
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
105 charFormat.setFontFamily(font.family())
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
106 charFormat.setFontPointSize(font.pointSize())
4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 if fg:
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
109 charFormat.setForeground(fg)
4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 if bg:
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
112 charFormat.setBackground(bg)
4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 if bold:
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
115 charFormat.setFontWeight(QFont.Bold)
4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
117 return charFormat
4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 def highlightBlock(self, text):
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 """
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 Public method to highlight a block of text.
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 @param text text to be highlighted (string)
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 """
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 formats = self.formats(text)
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 if not formats:
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 # nothing matched
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 self.setFormat(0, len(text), self.normalFormat)
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 return
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130
5597
3d88d53f8c2b Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
131 for match, formatStr in formats:
4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 start = match.start()
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 groups = match.groups()
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 # No groups in the regex, assume this is a single rule
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 # that spans the entire line
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 if not groups:
5597
3d88d53f8c2b Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
138 self.setFormat(0, len(text), formatStr)
4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 continue
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 # Groups exist, rule is a tuple corresponding to group
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 for groupIndex, group in enumerate(groups):
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 if not group:
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 # empty match
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 continue
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 # allow None as a no-op format
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 length = len(group)
5597
3d88d53f8c2b Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
149 if formatStr[groupIndex]:
4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 self.setFormat(start, start + length,
5597
3d88d53f8c2b Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
151 formatStr[groupIndex])
4108
0059d2d09ab8 Added a generic syntax highlighter for diff outputs.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 start += length
5765
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
153
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
154 def regenerateRules(self):
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
155 """
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
156 Public method to initialize or regenerate the syntax highlighter rules.
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
157 """
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
158 self.normalFormat = self.makeFormat()
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
159
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
160 self.__initColours()
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
161
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
162 self._rules = []
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
163 self.generateRules()
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
164
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
165 def generateRules(self):
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
166 """
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
167 Public method to generate the rule set.
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
168
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
169 Note: This method must me implemented by derived syntax
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
170 highlighters.
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
171 """
39d8b26ff557 Made the colors of the diff dialogs configurable.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5597
diff changeset
172 pass

eric ide

mercurial