Gentoo Archives: gentoo-commits

From: "Zac Medico (zmedico)" <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] portage r13410 - main/trunk/pym/portage
Date: Wed, 29 Apr 2009 18:00:10
Message-Id: E1LzE4l-0008E9-VM@stork.gentoo.org
1 Author: zmedico
2 Date: 2009-04-29 18:00:07 +0000 (Wed, 29 Apr 2009)
3 New Revision: 13410
4
5 Modified:
6 main/trunk/pym/portage/output.py
7 Log:
8 Make xtermTitle() use a global variable to cache the result of the TERM check.
9
10
11 Modified: main/trunk/pym/portage/output.py
12 ===================================================================
13 --- main/trunk/pym/portage/output.py 2009-04-29 17:40:27 UTC (rev 13409)
14 +++ main/trunk/pym/portage/output.py 2009-04-29 18:00:07 UTC (rev 13410)
15 @@ -247,22 +247,26 @@
16 tmp = re.sub(esc_seq + "^m]+m", "", mystr);
17 return len(tmp)
18
19 +_legal_terms_re = re.compile(r'^(xterm|xterm-color|Eterm|aterm|rxvt|screen|kterm|rxvt-unicode|gnome|interix)')
20 +_disable_xtermTitle = None
21 +_max_xtermTitle_len = 253
22 +
23 def xtermTitle(mystr, raw=False):
24 - if dotitles and "TERM" in os.environ and sys.stderr.isatty():
25 + global _disable_xtermTitle
26 + if _disable_xtermTitle is None:
27 + _disable_xtermTitle = not (sys.stderr.isatty() and \
28 + 'TERM' in os.environ and \
29 + _legal_terms_re.match(os.environ['TERM']) is not None)
30 +
31 + if dotitles and not _disable_xtermTitle:
32 # If the title string is too big then the terminal can
33 # misbehave. Therefore, truncate it if it's too big.
34 - max_len = 253
35 - if len(mystr) > max_len:
36 - mystr = mystr[:max_len]
37 - myt=os.environ["TERM"]
38 - legal_terms = ["xterm","xterm-color","Eterm","aterm","rxvt","screen","kterm","rxvt-unicode","gnome","interix"]
39 - for term in legal_terms:
40 - if myt.startswith(term):
41 - if not raw:
42 - mystr = "\x1b]0;%s\x07" % mystr
43 - sys.stderr.write(mystr)
44 - sys.stderr.flush()
45 - break
46 + if len(mystr) > _max_xtermTitle_len:
47 + mystr = mystr[:_max_xtermTitle_len]
48 + if not raw:
49 + mystr = '\x1b]0;%s\x07' % mystr
50 + sys.stderr.write(mystr)
51 + sys.stderr.flush()
52
53 default_xterm_title = None