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