Merge pull request #22 from gnome-terminator/compat-regex
terminal: Add compat detection for Vte regexp feature
This commit is contained in:
commit
6a9a345768
|
@ -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):
|
||||
|
@ -70,7 +76,7 @@ class Terminal(Gtk.VBox):
|
|||
(GObject.TYPE_INT,)),
|
||||
'group-all': (GObject.SignalFlags.RUN_LAST, None, ()),
|
||||
'group-all-toggle': (GObject.SignalFlags.RUN_LAST, None, ()),
|
||||
'move-tab': (GObject.SignalFlags.RUN_LAST, None,
|
||||
'move-tab': (GObject.SignalFlags.RUN_LAST, None,
|
||||
(GObject.TYPE_STRING,)),
|
||||
}
|
||||
|
||||
|
@ -79,7 +85,7 @@ class Terminal(Gtk.VBox):
|
|||
|
||||
MOUSEBUTTON_LEFT = 1
|
||||
MOUSEBUTTON_MIDDLE = 2
|
||||
MOUSEBUTTON_RIGHT = 3
|
||||
MOUSEBUTTON_RIGHT = 3
|
||||
|
||||
terminator = None
|
||||
vte = None
|
||||
|
@ -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):
|
||||
reg = Vte.Regex.new_for_match(re, len(re), self.regex_flags)
|
||||
self.matches[name] = self.vte.match_add_regex(reg, 0)
|
||||
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):
|
||||
|
@ -280,7 +290,7 @@ class Terminal(Gtk.VBox):
|
|||
rboundry = "\\b"
|
||||
|
||||
re = (lboundry + schemes +
|
||||
"//(" + user + "@)?[" + hostchars +".]+(:[0-9]+)?(" +
|
||||
"//(" + user + "@)?[" + hostchars +".]+(:[0-9]+)?(" +
|
||||
urlpath + ")?" + rboundry + "/?")
|
||||
self._add_regex('full_uri', re)
|
||||
|
||||
|
@ -361,8 +371,8 @@ class Terminal(Gtk.VBox):
|
|||
self.cnxids.new(self.vte, 'popup-menu', self.popup_menu)
|
||||
|
||||
srcvtetargets = [("vte", Gtk.TargetFlags.SAME_APP, self.TARGET_TYPE_VTE)]
|
||||
dsttargets = [("vte", Gtk.TargetFlags.SAME_APP, self.TARGET_TYPE_VTE),
|
||||
('text/x-moz-url', 0, self.TARGET_TYPE_MOZ),
|
||||
dsttargets = [("vte", Gtk.TargetFlags.SAME_APP, self.TARGET_TYPE_VTE),
|
||||
('text/x-moz-url', 0, self.TARGET_TYPE_MOZ),
|
||||
('_NETSCAPE_URL', 0, 0)]
|
||||
'''
|
||||
The following should work, but on my system it corrupts the returned
|
||||
|
@ -391,7 +401,7 @@ class Terminal(Gtk.VBox):
|
|||
dbg('Finalised drag targets: %s' % dsttargets)
|
||||
|
||||
for (widget, mask) in [
|
||||
(self.vte, Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.BUTTON3_MASK),
|
||||
(self.vte, Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.BUTTON3_MASK),
|
||||
(self.titlebar, Gdk.ModifierType.BUTTON1_MASK)]:
|
||||
widget.drag_source_set(mask, srcvtetargets, Gdk.DragAction.MOVE)
|
||||
|
||||
|
@ -408,7 +418,7 @@ class Terminal(Gtk.VBox):
|
|||
self.cnxids.new(self.vte, 'drag-data-received',
|
||||
self.on_drag_data_received, self)
|
||||
|
||||
self.cnxids.new(self.vte, 'selection-changed',
|
||||
self.cnxids.new(self.vte, 'selection-changed',
|
||||
lambda widget: self.maybe_copy_clipboard())
|
||||
|
||||
if self.composite_support:
|
||||
|
@ -505,7 +515,7 @@ class Terminal(Gtk.VBox):
|
|||
groupitems = []
|
||||
cnxs = []
|
||||
|
||||
for key, value in list({_('Broadcast _all'):'all',
|
||||
for key, value in list({_('Broadcast _all'):'all',
|
||||
_('Broadcast _group'):'group',
|
||||
_('Broadcast _off'):'off'}.items()):
|
||||
item = Gtk.RadioMenuItem.new_with_mnemonic(groupitems, key)
|
||||
|
@ -621,7 +631,7 @@ class Terminal(Gtk.VBox):
|
|||
if self.config['exit_action'] == 'restart':
|
||||
self.cnxids.new(self.vte, 'child-exited', self.spawn_child, True)
|
||||
elif self.config['exit_action'] in ('close', 'left'):
|
||||
self.cnxids.new(self.vte, 'child-exited',
|
||||
self.cnxids.new(self.vte, 'child-exited',
|
||||
lambda x, y: self.emit('close-term'))
|
||||
|
||||
if self.custom_encoding != True:
|
||||
|
@ -737,7 +747,7 @@ class Terminal(Gtk.VBox):
|
|||
setattr(newcolor, "red", y / 255.0)
|
||||
setattr(newcolor, "green", y / 255.0)
|
||||
setattr(newcolor, "blue", y / 255.0)
|
||||
self.palette_active.append(newcolor)
|
||||
self.palette_active.append(newcolor)
|
||||
self.palette_inactive = []
|
||||
for color in self.palette_active:
|
||||
newcolor = Gdk.RGBA()
|
||||
|
@ -809,7 +819,7 @@ class Terminal(Gtk.VBox):
|
|||
def set_cursor_color(self):
|
||||
"""Set the cursor color appropriately"""
|
||||
if self.config['cursor_color_fg']:
|
||||
self.vte.set_color_cursor(None)
|
||||
self.vte.set_color_cursor(None)
|
||||
else:
|
||||
cursor_color = Gdk.RGBA()
|
||||
cursor_color.parse(self.config['cursor_color'])
|
||||
|
@ -880,7 +890,7 @@ class Terminal(Gtk.VBox):
|
|||
if mapping == "hide_window":
|
||||
return(False)
|
||||
|
||||
if mapping and mapping not in ['close_window',
|
||||
if mapping and mapping not in ['close_window',
|
||||
'full_screen']:
|
||||
dbg('Terminal::on_keypress: lookup found: %r' % mapping)
|
||||
# handle the case where user has re-bound copy to ctrl+<key>
|
||||
|
@ -961,7 +971,7 @@ class Terminal(Gtk.VBox):
|
|||
return(True)
|
||||
|
||||
return(False)
|
||||
|
||||
|
||||
def on_mousewheel(self, widget, event):
|
||||
"""Handler for modifier + mouse wheel scroll events"""
|
||||
SMOOTH_SCROLL_UP = event.direction == Gdk.ScrollDirection.SMOOTH and event.delta_y <= 0.
|
||||
|
@ -1022,7 +1032,7 @@ class Terminal(Gtk.VBox):
|
|||
"""Handle the start of a drag event"""
|
||||
Gtk.drag_set_icon_pixbuf(drag_context, util.widget_pixbuf(self, 512), 0, 0)
|
||||
|
||||
def on_drag_data_get(self, _widget, _drag_context, selection_data, info,
|
||||
def on_drag_data_get(self, _widget, _drag_context, selection_data, info,
|
||||
_time, data):
|
||||
"""I have no idea what this does, drag and drop is a mystery. sorry."""
|
||||
selection_data.set(Gdk.atom_intern('vte', False), info,
|
||||
|
@ -1036,7 +1046,7 @@ class Terminal(Gtk.VBox):
|
|||
# copy text from another widget
|
||||
return
|
||||
srcwidget = Gtk.drag_get_source_widget(drag_context)
|
||||
if(isinstance(srcwidget, Gtk.EventBox) and
|
||||
if(isinstance(srcwidget, Gtk.EventBox) and
|
||||
srcwidget == self.titlebar) or widget == srcwidget:
|
||||
# on self
|
||||
return
|
||||
|
@ -1067,7 +1077,7 @@ class Terminal(Gtk.VBox):
|
|||
elif pos == "left":
|
||||
coord = (topleft, topmiddle, bottommiddle, bottomleft)
|
||||
elif pos == "bottom":
|
||||
coord = (bottomleft, bottomright, middleright , middleleft)
|
||||
coord = (bottomleft, bottomright, middleright , middleleft)
|
||||
|
||||
#here, we define some widget internal values
|
||||
widget._draw_data = { 'color': color, 'coord' : coord }
|
||||
|
@ -1130,11 +1140,11 @@ class Terminal(Gtk.VBox):
|
|||
for term in self.terminator.get_target_terms(self):
|
||||
term.feed(txt)
|
||||
return
|
||||
|
||||
|
||||
widgetsrc = data.terminator.terminals[int(selection_data.get_data())]
|
||||
srcvte = Gtk.drag_get_source_widget(drag_context)
|
||||
#check if computation requireds
|
||||
if (isinstance(srcvte, Gtk.EventBox) and
|
||||
if (isinstance(srcvte, Gtk.EventBox) and
|
||||
srcvte == self.titlebar) or srcvte == widget:
|
||||
return
|
||||
|
||||
|
@ -1864,7 +1874,7 @@ class Terminal(Gtk.VBox):
|
|||
|
||||
def key_insert_number(self):
|
||||
self.emit('enumerate', False)
|
||||
|
||||
|
||||
def key_insert_padded(self):
|
||||
self.emit('enumerate', True)
|
||||
|
||||
|
@ -1877,13 +1887,13 @@ class Terminal(Gtk.VBox):
|
|||
dialog.set_default_response(Gtk.ResponseType.ACCEPT)
|
||||
dialog.set_resizable(False)
|
||||
dialog.set_border_width(8)
|
||||
|
||||
|
||||
label = Gtk.Label(label=_('Enter a new title for the Terminator window...'))
|
||||
name = Gtk.Entry()
|
||||
name.set_activates_default(True)
|
||||
if window.title.text != self.vte.get_window_title():
|
||||
name.set_text(self.get_toplevel().title.text)
|
||||
|
||||
|
||||
dialog.vbox.pack_start(label, False, False, 6)
|
||||
dialog.vbox.pack_start(name, False, False, 6)
|
||||
|
||||
|
|
Loading…
Reference in New Issue