Fix URLs are not clickable

Improve integration with current VTE
This commit is contained in:
Antonio Terceiro 2020-03-30 18:21:43 -03:00 committed by Markus Frosch
parent 05ce8831fa
commit b2a47a50fd

View File

@ -142,8 +142,7 @@ class Terminal(Gtk.VBox):
self.vte.show()
self.default_encoding = self.vte.get_encoding()
self.regex_flags = (GLib.RegexCompileFlags.OPTIMIZE | \
GLib.RegexCompileFlags.MULTILINE)
self.regex_flags = Vte.REGEX_FLAGS_DEFAULT
self.update_url_matches()
self.terminalbox = self.create_terminalbox()
@ -270,34 +269,34 @@ class Terminal(Gtk.VBox):
re = (lboundry + schemes +
"//(" + user + "@)?[" + hostchars +".]+(:[0-9]+)?(" +
urlpath + ")?" + rboundry + "/?")
reg = GLib.Regex.new(re, self.regex_flags, 0)
self.matches['full_uri'] = self.vte.match_add_gregex(reg, 0)
reg = Vte.Regex.new_for_match(re, len(re), self.regex_flags)
self.matches['full_uri'] = self.vte.match_add_regex(reg, 0)
if self.matches['full_uri'] == -1:
err ('Terminal::update_url_matches: Failed adding URL matches')
else:
re = (lboundry +
'(callto:|h323:|sip:)' + "[" + userchars + "+][" +
userchars + ".]*(:[0-9]+)?@?[" + pathchars + "]+" +
'(callto:|h323:|sip:)' + "[" + userchars + "+][" +
userchars + ".]*(:[0-9]+)?@?[" + pathchars + "]+" +
rboundry)
reg = GLib.Regex.new(re, self.regex_flags, 0)
self.matches['voip'] = self.vte.match_add_gregex(reg, 0)
reg = Vte.Regex.new_for_match(re, len(re), self.regex_flags)
self.matches['voip'] = self.vte.match_add_regex(reg, 0)
re = (lboundry +
"(www|ftp)[" + hostchars + "]*\.[" + hostchars +
"(www|ftp)[" + hostchars + "]*\.[" + hostchars +
".]+(:[0-9]+)?(" + urlpath + ")?" + rboundry + "/?")
reg = GLib.Regex.new(re, self.regex_flags, 0)
self.matches['addr_only'] = self.vte.match_add_gregex(reg, 0)
reg = Vte.Regex.new_for_match(re, len(re), self.regex_flags)
self.matches['addr_only'] = self.vte.match_add_regex(reg, 0)
re = (lboundry +
"(mailto:)?[a-zA-Z0-9][a-zA-Z0-9.+-]*@[a-zA-Z0-9]" +
"[a-zA-Z0-9-]*\.[a-zA-Z0-9][a-zA-Z0-9-]+" +
"[.a-zA-Z0-9-]*" + rboundry)
reg = GLib.Regex.new(re, self.regex_flags, 0)
self.matches['email'] = self.vte.match_add_gregex(reg, 0)
reg = Vte.Regex.new_for_match(re, len(re), self.regex_flags)
self.matches['email'] = self.vte.match_add_regex(reg, 0)
re = (lboundry +
"""news:[-A-Z\^_a-z{|}~!"#$%&'()*+,./0-9;:=?`]+@""" +
"[-A-Za-z0-9.]+(:[0-9]+)?" + rboundry)
reg = GLib.Regex.new(re, self.regex_flags, 0)
self.matches['nntp'] = self.vte.match_add_gregex(reg, 0)
reg = Vte.Regex.new_for_match(re, len(re), self.regex_flags)
self.matches['nntp'] = self.vte.match_add_regex(reg, 0)
# Now add any matches from plugins
try:
@ -311,9 +310,9 @@ class Terminal(Gtk.VBox):
if name in self.matches:
dbg('refusing to add duplicate match %s' % name)
continue
reg = GLib.Regex.new(match, self.regex_flags, 0)
self.matches[name] = self.vte.match_add_gregex(reg, 0)
dbg('added plugin URL handler for %s (%s) as %d' %
reg = Vte.Regex.new_for_match(match, len(match), self.regex_flags)
self.matches[name] = self.vte.match_add_regex(reg, 0)
dbg('added plugin URL handler for %s (%s) as %d' %
(name, urlplugin.__class__.__name__,
self.matches[name]))
except Exception as ex:
@ -324,8 +323,8 @@ class Terminal(Gtk.VBox):
if name in self.matches:
err('Terminal::match_add: Refusing to create duplicate match %s' % name)
return
reg = GLib.Regex.new(match, self.regex_flags, 0)
self.matches[name] = self.vte.match_add_gregex(reg, 0)
reg = Vte.Regex.new_for_match(match, len(match), self.regex_flags)
self.matches[name] = self.vte.match_add_regex(reg, 0)
def match_remove(self, name):
"""Remove a previously registered URL match"""