terminal: Add compat detection for Vte regexp feature
Older Vte versions only offer the old implementation. fixes #10
This commit is contained in:
parent
715c4a667b
commit
9beb28a22e
|
@ -33,6 +33,12 @@ from terminatorlib.layoutlauncher import LayoutLauncher
|
|||
# TODO: Please replace with a proper reference to VTE, I found none!
|
||||
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
|
||||
class Terminal(Gtk.VBox):
|
||||
|
@ -150,7 +156,7 @@ class Terminal(Gtk.VBox):
|
|||
self.vte.show()
|
||||
|
||||
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.terminalbox = self.create_terminalbox()
|
||||
|
@ -262,8 +268,12 @@ class Terminal(Gtk.VBox):
|
|||
return(terminalbox)
|
||||
|
||||
def _add_regex(self, name, re):
|
||||
if REGEX_MODERN:
|
||||
reg = Vte.Regex.new_for_match(re, len(re), self.regex_flags)
|
||||
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')
|
||||
|
||||
def update_url_matches(self):
|
||||
|
|
Loading…
Reference in New Issue