Merge pull request #22 from gnome-terminator/compat-regex

terminal: Add compat detection for Vte regexp feature
This commit is contained in:
Markus Frosch 2020-04-18 12:31:17 +02:00 committed by GitHub
commit 6a9a345768
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 24 deletions

View File

@ -33,6 +33,12 @@ from terminatorlib.layoutlauncher import LayoutLauncher
# TODO: Please replace with a proper reference to VTE, I found none! # TODO: Please replace with a proper reference to VTE, I found none!
PCRE2_MULTILINE = 0x00000400 PCRE2_MULTILINE = 0x00000400
if hasattr(Vte, 'REGEX_FLAGS_DEFAULT'):
REGEX_FLAGS = (Vte.REGEX_FLAGS_DEFAULT | PCRE2_MULTILINE)
REGEX_MODERN = True
else:
REGEX_FLAGS = (GLib.RegexCompileFlags.OPTIMIZE | GLib.RegexCompileFlags.MULTILINE)
REGEX_MODERN = False
# pylint: disable-msg=R0904 # pylint: disable-msg=R0904
class Terminal(Gtk.VBox): class Terminal(Gtk.VBox):
@ -150,7 +156,7 @@ class Terminal(Gtk.VBox):
self.vte.show() self.vte.show()
self.default_encoding = self.vte.get_encoding() self.default_encoding = self.vte.get_encoding()
self.regex_flags = (Vte.REGEX_FLAGS_DEFAULT | PCRE2_MULTILINE) self.regex_flags = REGEX_FLAGS
self.update_url_matches() self.update_url_matches()
self.terminalbox = self.create_terminalbox() self.terminalbox = self.create_terminalbox()
@ -262,8 +268,12 @@ class Terminal(Gtk.VBox):
return(terminalbox) return(terminalbox)
def _add_regex(self, name, re): def _add_regex(self, name, re):
if REGEX_MODERN:
reg = Vte.Regex.new_for_match(re, len(re), self.regex_flags) reg = Vte.Regex.new_for_match(re, len(re), self.regex_flags)
self.matches[name] = self.vte.match_add_regex(reg, 0) self.matches[name] = self.vte.match_add_regex(reg, 0)
else:
reg = GLib.Regex.new(re, self.regex_flags, 0)
self.matches[name] = self.vte.match_add_gregex(reg, 0)
self.vte.match_set_cursor_name(self.matches[name], 'pointer') self.vte.match_set_cursor_name(self.matches[name], 'pointer')
def update_url_matches(self): def update_url_matches(self):