##// END OF EJS Templates
Merge pull request #11910 from pasenor/restore-terminal-title-xterm...
Matthias Bussonnier -
r25198:314c1a36 merge
parent child Browse files
Show More
@@ -8,7 +8,7 b' from warnings import warn'
8 8 from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC
9 9 from IPython.utils import io
10 10 from IPython.utils.py3compat import input
11 from IPython.utils.terminal import toggle_set_term_title, set_term_title
11 from IPython.utils.terminal import toggle_set_term_title, set_term_title, restore_term_title
12 12 from IPython.utils.process import abbrev_cwd
13 13 from traitlets import (
14 14 Bool, Unicode, Dict, Integer, observe, Instance, Type, default, Enum, Union,
@@ -238,6 +238,10 b' class TerminalInteractiveShell(InteractiveShell):'
238 238 else:
239 239 toggle_set_term_title(False)
240 240
241 def restore_term_title(self):
242 if self.term_title:
243 restore_term_title()
244
241 245 def init_display_formatter(self):
242 246 super(TerminalInteractiveShell, self).init_display_formatter()
243 247 # terminal only supports plain text
@@ -507,6 +511,9 b' class TerminalInteractiveShell(InteractiveShell):'
507 511 if hasattr(self, '_eventloop'):
508 512 self._eventloop.stop()
509 513
514 self.restore_term_title()
515
516
510 517 _inputhook = None
511 518 def inputhook(self, context):
512 519 if self._inputhook is not None:
@@ -58,14 +58,26 b' def _set_term_title(*args,**kw):'
58 58 pass
59 59
60 60
61 def _restore_term_title():
62 pass
63
64
61 65 def _set_term_title_xterm(title):
62 66 """ Change virtual terminal title in xterm-workalikes """
67 # save the current title to the xterm "stack"
68 sys.stdout.write('\033[22;0t')
63 69 sys.stdout.write('\033]0;%s\007' % title)
64 70
71
72 def _restore_term_title_xterm():
73 sys.stdout.write('\033[23;0t')
74
75
65 76 if os.name == 'posix':
66 77 TERM = os.environ.get('TERM','')
67 78 if TERM.startswith('xterm'):
68 79 _set_term_title = _set_term_title_xterm
80 _restore_term_title = _restore_term_title_xterm
69 81 elif sys.platform == 'win32':
70 82 try:
71 83 import ctypes
@@ -100,6 +112,13 b' def set_term_title(title):'
100 112 _set_term_title(title)
101 113
102 114
115 def restore_term_title():
116 """Restore, if possible, terminal title to the original state"""
117 if ignore_termtitle:
118 return
119 _restore_term_title()
120
121
103 122 def freeze_term_title():
104 123 warnings.warn("This function is deprecated, use toggle_set_term_title()")
105 124 global ignore_termtitle
General Comments 0
You need to be logged in to leave comments. Login now