summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-04-30 07:30:14 +0000
committerZac Medico <zmedico@gentoo.org>2009-04-30 07:30:14 +0000
commite4ce2e72476ed5a25c3ea190a13b4487c44022e1 (patch)
treee4c68fcda1b5e054df4c4cb05886a8516ea50d51
parentBug #267860 - Make JobStatusDisplay respect FEATURES=notitles. (trunk r13409) (diff)
downloadportage-multirepo-e4ce2e72476ed5a25c3ea190a13b4487c44022e1.tar.gz
portage-multirepo-e4ce2e72476ed5a25c3ea190a13b4487c44022e1.tar.bz2
portage-multirepo-e4ce2e72476ed5a25c3ea190a13b4487c44022e1.zip
Make xtermTitle() use a global variable to cache the result of the TERM check.
(trunk r13410) svn path=/main/branches/2.1.6/; revision=13550
-rw-r--r--pym/portage/output.py30
1 files changed, 17 insertions, 13 deletions
diff --git a/pym/portage/output.py b/pym/portage/output.py
index eaca066f..983cbec6 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