Belle II Software  release-08-01-10
interactive.py
1 #!/usr/bin/env python3
2 
3 
10 
11 """
12 interactive
13 -----------
14 
15 Defines a function embed() that can be used to drop into an interactive python
16 shell from within a steering file or python module. If available, IPython will
17 be used. Use Ctrl+D to exit the shell.
18 
19  >>> import interactive
20  >>> interactive.embed()
21  In [1]:
22 
23 See framework/examples/interactive_python.py for an example.
24 """
25 
26 from traitlets.config.loader import Config
27 from IPython.terminal.prompts import Prompts, Token
28 from IPython import embed # noqa
29 
30 
31 class 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 
40  def out_prompt_tokens(self):
41  """Output prompt"""
42  return [(Token.OutPrompt, "basf2 out["),
43  (Token.OutPromptNum, str(self.shell.execution_count)),
44  (Token.OutPrompt, ']: ')]
45 
46 
47 def 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