Belle II Software light-2406-ragdoll
interactive.py
1#!/usr/bin/env python3
2
3
10
11"""
12interactive
13-----------
14
15Defines a function embed() that can be used to drop into an interactive python
16shell from within a steering file or python module. If available, IPython will
17be used. Use Ctrl+D to exit the shell.
18
19 >>> import interactive
20 >>> interactive.embed()
21 In [1]:
22
23See framework/examples/interactive_python.py for an example.
24"""
25
26from traitlets.config.loader import Config
27from IPython.terminal.prompts import Prompts, Token
28from IPython import embed # noqa
29
30
31class Basf2IPythonPrompt(Prompts):
32 """Provide slightly customized prompts when running basf2 interactively"""
33
34 def in_prompt_tokens(self, cli=None):
35 """Input prompt"""
36 return [(Token.Prompt, "basf2 in ["),
37 (Token.PromptNum, str(self.shell.execution_count)),
38 (Token.Prompt, ']: ')]
39
41 """Output prompt"""
42 return [(Token.OutPrompt, "basf2 out["),
43 (Token.OutPromptNum, str(self.shell.execution_count)),
44 (Token.OutPrompt, ']: ')]
45
46
47def basf2_shell_config():
48 """Return a config object customizing the shell prompt for basf2"""
49 c = Config()
50 c.TerminalInteractiveShell.prompts_class = Basf2IPythonPrompt
51 return c
def in_prompt_tokens(self, cli=None)
Definition: interactive.py:34