2009-08-10 23:42:39 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# Terminator by Chris Jones <cmsj@tenshu.net>
|
|
|
|
# GPL v2 only
|
|
|
|
"""terminal.py - classes necessary to provide Terminal widgets"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import pygtk
|
|
|
|
pygtk.require('2.0')
|
|
|
|
import gobject
|
|
|
|
import gtk
|
|
|
|
import pango
|
|
|
|
|
2009-08-18 11:55:37 +00:00
|
|
|
from cwd import get_pid_cwd, get_default_cwd
|
|
|
|
from util import dbg, err, gerr
|
|
|
|
from config import Config
|
2009-08-18 12:44:41 +00:00
|
|
|
from titlebar import Titlebar
|
2009-08-18 12:47:46 +00:00
|
|
|
from searchbar import Searchbar
|
2009-08-18 11:55:37 +00:00
|
|
|
|
2009-08-10 23:42:39 +00:00
|
|
|
try:
|
|
|
|
import vte
|
|
|
|
except ImportError:
|
2009-08-18 11:55:37 +00:00
|
|
|
gerr('You need to install python bindings for libvte')
|
2009-08-10 23:42:39 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
class Terminal(gtk.VBox):
|
|
|
|
"""Class implementing the VTE widget and its wrappings"""
|
|
|
|
|
2009-08-11 22:27:56 +00:00
|
|
|
vte = None
|
2009-08-18 12:44:41 +00:00
|
|
|
titlebar = None
|
|
|
|
searchbar = None
|
|
|
|
|
2009-08-18 11:55:37 +00:00
|
|
|
matches = None
|
|
|
|
config = None
|
2009-08-18 12:44:41 +00:00
|
|
|
default_encoding = None
|
2009-08-11 22:27:56 +00:00
|
|
|
|
2009-08-10 23:42:39 +00:00
|
|
|
def __init__(self):
|
|
|
|
"""Class initialiser"""
|
2009-08-11 22:27:56 +00:00
|
|
|
gtk.VBox.__init__(self)
|
2009-08-18 11:55:37 +00:00
|
|
|
self.matches = {}
|
|
|
|
|
|
|
|
self.config = Config()
|
2009-08-11 22:27:56 +00:00
|
|
|
|
|
|
|
self.vte = vte.Terminal()
|
2009-08-11 22:48:19 +00:00
|
|
|
self.vte.set_size(80, 24)
|
|
|
|
self.vte._expose_data = None
|
|
|
|
self.vte.show()
|
2009-08-18 12:44:41 +00:00
|
|
|
self.default_encoding = self.vte.get_encoding()
|
2009-08-18 11:55:37 +00:00
|
|
|
self.update_url_matches(self.config['try_posix_regexp'])
|
|
|
|
|
2009-08-18 12:44:41 +00:00
|
|
|
self.titlebar = Titlebar()
|
|
|
|
self.searchbar = Searchbar()
|
|
|
|
|
|
|
|
self.show()
|
|
|
|
self.pack_start(self.titlebar, False)
|
|
|
|
self.pack_start(self.terminalbox)
|
|
|
|
self.pack_end(self.searchbar)
|
|
|
|
|
2009-08-18 11:55:37 +00:00
|
|
|
def update_url_matches(self, posix = True):
|
|
|
|
"""Update the regexps used to match URLs"""
|
|
|
|
userchars = "-A-Za-z0-9"
|
|
|
|
passchars = "-A-Za-z0-9,?;.:/!%$^*&~\"#'"
|
|
|
|
hostchars = "-A-Za-z0-9"
|
|
|
|
pathchars = "-A-Za-z0-9_$.+!*(),;:@&=?/~#%'\""
|
|
|
|
schemes = "(news:|telnet:|nntp:|file:/|https?:|ftps?:|webcal:)"
|
|
|
|
user = "[" + userchars + "]+(:[" + passchars + "]+)?"
|
|
|
|
urlpath = "/[" + pathchars + "]*[^]'.}>) \t\r\n,\\\"]"
|
|
|
|
|
|
|
|
if posix:
|
|
|
|
dbg ('update_url_matches: Trying POSIX URL regexps. Set \
|
|
|
|
try_posix_regexp = False in config to only try GNU \
|
|
|
|
if you get (harmless) VTE warnings.')
|
|
|
|
lboundry = "[[:<:]]"
|
|
|
|
rboundry = "[[:>:]]"
|
|
|
|
else: # GNU
|
|
|
|
dbg ('update_url_matches: Trying GNU URL regexps. Set \
|
|
|
|
try_posix_regexp = True in config if URLs are not \
|
|
|
|
detected.')
|
|
|
|
lboundry = "\\<"
|
|
|
|
rboundry = "\\>"
|
|
|
|
|
|
|
|
self.matches['full_uri'] = self._vte.match_add(lboundry + schemes +
|
|
|
|
"//(" + user + "@)?[" + hostchars +".]+(:[0-9]+)?(" +
|
|
|
|
urlpath + ")?" + rboundry + "/?")
|
|
|
|
|
|
|
|
if self.matches['full_uri'] == -1:
|
|
|
|
if posix:
|
|
|
|
err ('update_url_matches: POSIX match failed, trying GNU')
|
|
|
|
self.update_url_matches(posix = False)
|
|
|
|
else:
|
|
|
|
err ('update_url_matches: Failed adding URL match patterns')
|
|
|
|
else:
|
|
|
|
self.matches['voip'] = self._vte.match_add(lboundry +
|
|
|
|
'(callto:|h323:|sip:)' + "[" + userchars + "+][" +
|
|
|
|
userchars + ".]*(:[0-9]+)?@?[" + pathchars + "]+" +
|
|
|
|
rboundry)
|
|
|
|
self.matches['addr_only'] = self._vte.match_add (lboundry +
|
|
|
|
"(www|ftp)[" + hostchars + "]*\.[" + hostchars +
|
|
|
|
".]+(:[0-9]+)?(" + urlpath + ")?" + rboundry + "/?")
|
|
|
|
self.matches['email'] = self._vte.match_add (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)
|
|
|
|
self.matches['nntp'] = self._vte.match_add (lboundry +
|
|
|
|
'''news:[-A-Z\^_a-z{|}~!"#$%&'()*+,./0-9;:=?`]+@[-A-Za-z0-9.]+(:[0-9]+)?''' + rboundry)
|
|
|
|
# if the url looks like a Launchpad changelog closure entry
|
|
|
|
# LP: #92953 - make it a url to http://bugs.launchpad.net
|
|
|
|
self.matches['launchpad'] = self._vte.match_add (
|
|
|
|
'\\bLP:? #?[0-9]+\\b')
|
|
|
|
|
2009-08-10 23:42:39 +00:00
|
|
|
# vim: set expandtab ts=4 sw=4:
|