3131 help = 'specify script to run' )
3232parser .add_argument ('--backend' , '-b' , default = None ,
3333 help = 'specify graphics frontend' )
34+ parser .add_argument ('--color' , '-c' , default = 'neutral' ,
35+ help = 'specify terminal color scheme (neutral, lightbg, nocolor, linux), linux is for dark mode' )
36+ parser .add_argument ('--confirmexit' , '-x' , default = False ,
37+ help = 'confirm exit' )
38+ parser .add_argument ('--prompt' , '-p' , default = '>>> ' ,
39+ help = 'input prompt' )
40+ parser .add_argument ('--resultprefix' , '-r' , default = None ,
41+ help = 'execution result prefix, include {} for execution count number' )
42+ parser .add_argument ('--showassign' , '-a' , default = False ,
43+ help = 'display the result of assignments' )
3444args = parser .parse_args ()
3545
3646if args .backend is not None :
3747 print (f"Using matplotlub backend { args .backend } " )
3848 plt .use (args .backend )
3949
40- # load some models
50+ # load some robot models
4151puma = models .DH .Puma560 ()
4252panda = models .DH .Panda ()
4353
6878## drop into IPython
6979import IPython
7080from traitlets .config import Config
81+ from IPython .terminal .prompts import ClassicPrompts
82+ from IPython .terminal .prompts import Prompts
83+ from pygments .token import Token
84+
85+ class MyPrompt (Prompts ):
86+ def in_prompt_tokens (self , cli = None ):
87+ return [(Token .Prompt , args .prompt )]
88+ def out_prompt_tokens (self , cli = None ):
89+ if args .resultprefix is None :
90+ # traditional behaviour
91+ return [
92+ (Token .OutPrompt , 'Out[' ),
93+ (Token .OutPromptNum , str (self .shell .execution_count )),
94+ (Token .OutPrompt , ']: ' ),
95+ ]
96+ else :
97+ return [(Token .Prompt , args .resultprefix .format (self .shell .execution_count ))]
7198
7299# set configuration options, there are lots, see
73100# https://ipython.readthedocs.io/en/stable/config/options/terminal.html
74101c = Config ()
75- c .InteractiveShellEmbed .colors = "Linux"
76- c .InteractiveShell .colors = 'Neutral'
77- c .InteractiveShell .confirm_exit = False
102+ c .InteractiveShellEmbed .colors = args .color
103+ c .InteractiveShell .confirm_exit = args .confirmexit
104+ # c.InteractiveShell.prompts_class = ClassicPrompts
105+ c .InteractiveShell .prompts_class = MyPrompt
106+ if args .showassign :
107+ c .InteractiveShell .ast_node_interactivity = 'last_expr_or_assign'
78108
79109IPython .embed (config = c )
0 commit comments