Show More
@@ -8,7 +8,7 b' from warnings import warn' | |||||
8 | from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC |
|
8 | from IPython.core.interactiveshell import InteractiveShell, InteractiveShellABC | |
9 | from IPython.utils import io |
|
9 | from IPython.utils import io | |
10 | from IPython.utils.py3compat import input |
|
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 | from IPython.utils.process import abbrev_cwd |
|
12 | from IPython.utils.process import abbrev_cwd | |
13 | from traitlets import ( |
|
13 | from traitlets import ( | |
14 | Bool, Unicode, Dict, Integer, observe, Instance, Type, default, Enum, Union, |
|
14 | Bool, Unicode, Dict, Integer, observe, Instance, Type, default, Enum, Union, | |
@@ -238,6 +238,10 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
238 | else: |
|
238 | else: | |
239 | toggle_set_term_title(False) |
|
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 | def init_display_formatter(self): |
|
245 | def init_display_formatter(self): | |
242 | super(TerminalInteractiveShell, self).init_display_formatter() |
|
246 | super(TerminalInteractiveShell, self).init_display_formatter() | |
243 | # terminal only supports plain text |
|
247 | # terminal only supports plain text | |
@@ -507,6 +511,9 b' class TerminalInteractiveShell(InteractiveShell):' | |||||
507 | if hasattr(self, '_eventloop'): |
|
511 | if hasattr(self, '_eventloop'): | |
508 | self._eventloop.stop() |
|
512 | self._eventloop.stop() | |
509 |
|
513 | |||
|
514 | self.restore_term_title() | |||
|
515 | ||||
|
516 | ||||
510 | _inputhook = None |
|
517 | _inputhook = None | |
511 | def inputhook(self, context): |
|
518 | def inputhook(self, context): | |
512 | if self._inputhook is not None: |
|
519 | if self._inputhook is not None: |
@@ -58,14 +58,26 b' def _set_term_title(*args,**kw):' | |||||
58 | pass |
|
58 | pass | |
59 |
|
59 | |||
60 |
|
60 | |||
|
61 | def _restore_term_title(): | |||
|
62 | pass | |||
|
63 | ||||
|
64 | ||||
61 | def _set_term_title_xterm(title): |
|
65 | def _set_term_title_xterm(title): | |
62 | """ Change virtual terminal title in xterm-workalikes """ |
|
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 | sys.stdout.write('\033]0;%s\007' % title) |
|
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 | if os.name == 'posix': |
|
76 | if os.name == 'posix': | |
66 | TERM = os.environ.get('TERM','') |
|
77 | TERM = os.environ.get('TERM','') | |
67 | if TERM.startswith('xterm'): |
|
78 | if TERM.startswith('xterm'): | |
68 | _set_term_title = _set_term_title_xterm |
|
79 | _set_term_title = _set_term_title_xterm | |
|
80 | _restore_term_title = _restore_term_title_xterm | |||
69 | elif sys.platform == 'win32': |
|
81 | elif sys.platform == 'win32': | |
70 | try: |
|
82 | try: | |
71 | import ctypes |
|
83 | import ctypes | |
@@ -100,6 +112,13 b' def set_term_title(title):' | |||||
100 | _set_term_title(title) |
|
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 | def freeze_term_title(): |
|
122 | def freeze_term_title(): | |
104 | warnings.warn("This function is deprecated, use toggle_set_term_title()") |
|
123 | warnings.warn("This function is deprecated, use toggle_set_term_title()") | |
105 | global ignore_termtitle |
|
124 | global ignore_termtitle |
General Comments 0
You need to be logged in to leave comments.
Login now