Initialize the prompt session and the prompt loop and store them in self.pt_app and self.pt_loop. Additional keyword arguments for the PromptSession class can be specified in pt_session_options.
(self, pt_session_options=None)
| 32 | self.pt_init(pt_session_options) |
| 33 | |
| 34 | def pt_init(self, pt_session_options=None): |
| 35 | """Initialize the prompt session and the prompt loop |
| 36 | and store them in self.pt_app and self.pt_loop. |
| 37 | |
| 38 | Additional keyword arguments for the PromptSession class |
| 39 | can be specified in pt_session_options. |
| 40 | """ |
| 41 | if pt_session_options is None: |
| 42 | pt_session_options = {} |
| 43 | |
| 44 | def get_prompt_tokens(): |
| 45 | return [(Token.Prompt, self.prompt)] |
| 46 | |
| 47 | if self._ptcomp is None: |
| 48 | compl = IPCompleter(shell=self.shell, |
| 49 | namespace={}, |
| 50 | global_namespace={}, |
| 51 | parent=self.shell, |
| 52 | ) |
| 53 | # add a completer for all the do_ methods |
| 54 | methods_names = [m[3:] for m in dir(self) if m.startswith("do_")] |
| 55 | |
| 56 | def gen_comp(self, text): |
| 57 | return [m for m in methods_names if m.startswith(text)] |
| 58 | import types |
| 59 | newcomp = types.MethodType(gen_comp, compl) |
| 60 | compl.custom_matchers.insert(0, newcomp) |
| 61 | # end add completer. |
| 62 | |
| 63 | self._ptcomp = IPythonPTCompleter(compl) |
| 64 | |
| 65 | options = dict( |
| 66 | message=(lambda: PygmentsTokens(get_prompt_tokens())), |
| 67 | editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()), |
| 68 | key_bindings=create_ipython_shortcuts(self.shell), |
| 69 | history=self.shell.debugger_history, |
| 70 | completer=self._ptcomp, |
| 71 | enable_history_search=True, |
| 72 | mouse_support=self.shell.mouse_support, |
| 73 | complete_style=self.shell.pt_complete_style, |
| 74 | style=self.shell.style, |
| 75 | color_depth=self.shell.color_depth, |
| 76 | ) |
| 77 | |
| 78 | if not PTK3: |
| 79 | options['inputhook'] = self.shell.inputhook |
| 80 | options.update(pt_session_options) |
| 81 | self.pt_loop = asyncio.new_event_loop() |
| 82 | self.pt_app = PromptSession(**options) |
| 83 | |
| 84 | def cmdloop(self, intro=None): |
| 85 | """Repeatedly issue a prompt, accept input, parse an initial prefix |
no test coverage detected