diff options
author | Zac Medico <zmedico@gentoo.org> | 2009-04-29 18:00:07 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2009-04-29 18:00:07 +0000 |
commit | 780eb764c82defb7418ba614479be363f9eb2572 (patch) | |
tree | 3ca6ea263332f10dc0c5a8964880266fc0fb659a | |
parent | 437a7e7db45ccce2cf1427cc1eb995ce4a95c6fb (diff) | |
download | portage-780eb764c82defb7418ba614479be363f9eb2572.tar.gz portage-780eb764c82defb7418ba614479be363f9eb2572.tar.bz2 portage-780eb764c82defb7418ba614479be363f9eb2572.zip |
Make xtermTitle() use a global variable to cache the result of the TERM check.
svn path=/main/trunk/; revision=13410
-rw-r--r-- | pym/portage/output.py | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/pym/portage/output.py b/pym/portage/output.py index eaca066f4..983cbec60 100644 --- a/pym/portage/output.py +++ b/pym/portage/output.py @@ -247,22 +247,26 @@ def nc_len(mystr): tmp = re.sub(esc_seq + "^m]+m", "", mystr); return len(tmp) +_legal_terms_re = re.compile(r'^(xterm|xterm-color|Eterm|aterm|rxvt|screen|kterm|rxvt-unicode|gnome|interix)') +_disable_xtermTitle = None +_max_xtermTitle_len = 253 + def xtermTitle(mystr, raw=False): - if dotitles and "TERM" in os.environ and sys.stderr.isatty(): + global _disable_xtermTitle + if _disable_xtermTitle is None: + _disable_xtermTitle = not (sys.stderr.isatty() and \ + 'TERM' in os.environ and \ + _legal_terms_re.match(os.environ['TERM']) is not None) + + if dotitles and not _disable_xtermTitle: # If the title string is too big then the terminal can # misbehave. Therefore, truncate it if it's too big. - max_len = 253 - if len(mystr) > max_len: - mystr = mystr[:max_len] - myt=os.environ["TERM"] - legal_terms = ["xterm","xterm-color","Eterm","aterm","rxvt","screen","kterm","rxvt-unicode","gnome","interix"] - for term in legal_terms: - if myt.startswith(term): - if not raw: - mystr = "\x1b]0;%s\x07" % mystr - sys.stderr.write(mystr) - sys.stderr.flush() - break + if len(mystr) > _max_xtermTitle_len: + mystr = mystr[:_max_xtermTitle_len] + if not raw: + mystr = '\x1b]0;%s\x07' % mystr + sys.stderr.write(mystr) + sys.stderr.flush() default_xterm_title = None |