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