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.thread_executor = ThreadPoolExecutor(1) |
| 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( |
| 49 | shell=self.shell, namespace={}, global_namespace={}, parent=self.shell |
| 50 | ) |
| 51 | # add a completer for all the do_ methods |
| 52 | methods_names = [m[3:] for m in dir(self) if m.startswith("do_")] |
| 53 | |
| 54 | def gen_comp(self, text): |
| 55 | return [m for m in methods_names if m.startswith(text)] |
| 56 | import types |
| 57 | newcomp = types.MethodType(gen_comp, compl) |
| 58 | compl.custom_matchers.insert(0, newcomp) |
| 59 | # end add completer. |
| 60 | |
| 61 | self._ptcomp = IPythonPTCompleter(compl) |
| 62 | |
| 63 | # setup history only when we start pdb |
| 64 | if self.shell.debugger_history is None: |
| 65 | if self.shell.debugger_history_file is not None: |
| 66 | p = Path(self.shell.debugger_history_file).expanduser() |
| 67 | if not p.exists(): |
| 68 | p.touch() |
| 69 | self.debugger_history = FileHistory(os.path.expanduser(str(p))) |
| 70 | else: |
| 71 | self.debugger_history = InMemoryHistory() |
| 72 | else: |
| 73 | self.debugger_history = self.shell.debugger_history |
| 74 | |
| 75 | options = dict( |
| 76 | message=(lambda: PygmentsTokens(get_prompt_tokens())), |
| 77 | editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()), |
| 78 | key_bindings=create_ipython_shortcuts(self.shell), |
| 79 | history=self.debugger_history, |
| 80 | completer=self._ptcomp, |
| 81 | enable_history_search=True, |
| 82 | mouse_support=self.shell.mouse_support, |
| 83 | complete_style=self.shell.pt_complete_style, |
| 84 | style=getattr(self.shell, "style", None), |
| 85 | color_depth=self.shell.color_depth, |
| 86 | ) |
| 87 | |
| 88 | options.update(pt_session_options) |
| 89 | if not _use_simple_prompt: |
| 90 | self.pt_loop = asyncio.new_event_loop() |
| 91 | self.pt_app = PromptSession(**options) |
no test coverage detected