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
1 changed files with 19 additions and 20 deletions

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,8 +269,8 @@ 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')
@ -280,24 +279,24 @@ class Terminal(Gtk.VBox):
'(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 +
".]+(:[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,8 +310,8 @@ 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)
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]))
@ -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"""