Skip to content

Commit dff60bd

Browse files
Set terminal title.
1 parent 62e08d3 commit dff60bd

5 files changed

Lines changed: 16 additions & 4 deletions

File tree

ptpython/entry_points/run_ptipython.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ def configure(repl):
5858
run_config(repl, path)
5959

6060
# Run interactive shell.
61-
embed(vi_mode=vi_mode,
61+
embed(vi_mode=vi_mode,
6262
history_filename=os.path.join(config_dir, 'history'),
6363
configure=configure,
64-
user_ns=user_ns)
64+
user_ns=user_ns,
65+
title='IPython REPL (ptipython)')
6566

6667

6768
if __name__ == '__main__':

ptpython/entry_points/run_ptpython.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def configure(repl):
6565
embed(vi_mode=vi_mode,
6666
history_filename=os.path.join(config_dir, 'history'),
6767
configure=configure,
68-
startup_paths=startup_paths)
68+
startup_paths=startup_paths,
69+
title='Python REPL (ptpython)')
6970

7071
if __name__ == '__main__':
7172
run()

ptpython/ipython.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ def __init__(self, *a, **kw):
169169
vi_mode = kw.pop('vi_mode', False)
170170
history_filename = kw.pop('history_filename', None)
171171
configure = kw.pop('configure', None)
172+
title = kw.pop('title', None)
172173

173174
super(InteractiveShellEmbed, self).__init__(*a, **kw)
174175

@@ -181,6 +182,9 @@ def get_globals():
181182
get_globals=get_globals, vi_mode=vi_mode,
182183
history_filename=history_filename)
183184

185+
if title:
186+
ipython_input.terminal_title = title
187+
184188
if configure:
185189
configure(ipython_input)
186190

ptpython/python_input.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def __init__(self,
164164

165165
self.show_sidebar = False # Currently show the sidebar.
166166
self.show_exit_confirmation = False # Currently show 'Do you really want to exit?'
167+
self.terminal_title = None # The title to be displayed in the terminal. (None or string.)
167168

168169
#: Load styles.
169170
self.code_styles = get_all_code_styles()
@@ -402,6 +403,7 @@ def create_application(self):
402403
on_abort=AbortAction.RETRY,
403404
on_exit=self._on_exit,
404405
get_style=lambda: self._current_style,
406+
get_title=lambda: self.terminal_title,
405407
on_start=self._on_start,
406408
on_input_timeout=Callback(self._on_input_timeout))
407409

ptpython/repl.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def enter_to_continue():
244244

245245

246246
def embed(globals=None, locals=None, configure=None,
247-
vi_mode=False, history_filename=None,
247+
vi_mode=False, history_filename=None, title=None,
248248
startup_paths=None, patch_stdout=False, return_asyncio_coroutine=False):
249249
"""
250250
Call this to embed Python shell at the current point in your program.
@@ -256,6 +256,7 @@ def embed(globals=None, locals=None, configure=None,
256256
:param vi_mode: Boolean. Use Vi instead of Emacs key bindings.
257257
:param configure: Callable that will be called with the `PythonRepl` as a first
258258
argument, to trigger configuration.
259+
:param title: Title to be displayed in the terminal titlebar. (None or string.)
259260
"""
260261
assert configure is None or callable(configure)
261262

@@ -287,6 +288,9 @@ def get_locals():
287288
history_filename=history_filename,
288289
startup_paths=startup_paths)
289290

291+
if title:
292+
repl.terminal_title = title
293+
290294
if configure:
291295
configure(repl)
292296

0 commit comments

Comments
 (0)