Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d183ce0

Browse files
nsmaciejCarreau
authored andcommitted
Only save the initial terminal title
1 parent 71f7729 commit d183ce0

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

IPython/utils/terminal.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,27 @@ def _restore_term_title():
6262
pass
6363

6464

65+
_xterm_term_title_saved = False
66+
67+
6568
def _set_term_title_xterm(title):
6669
""" Change virtual terminal title in xterm-workalikes """
67-
# save the current title to the xterm "stack"
68-
sys.stdout.write('\033[22;0t')
70+
global _xterm_term_title_saved
71+
# Only save the title the first time we set, otherwise restore will only
72+
# go back one title (probably undoing a %cd title change).
73+
if not _xterm_term_title_saved:
74+
# save the current title to the xterm "stack"
75+
sys.stdout.write('\033[22;0t')
76+
_xterm_term_title_saved = True
6977
sys.stdout.write('\033]0;%s\007' % title)
7078

7179

7280
def _restore_term_title_xterm():
81+
# Make sure the restore has at least one accompanying set.
82+
global _xterm_term_title_saved
83+
assert _xterm_term_title_saved
7384
sys.stdout.write('\033[23;0t')
85+
_xterm_term_title_saved = False
7486

7587

7688
if os.name == 'posix':

0 commit comments

Comments
 (0)