Override our `PythonCommandLineInterface` to add IPython specific stuff.
| 177 | |
| 178 | |
| 179 | class IPythonInput(PythonInput): |
| 180 | """ |
| 181 | Override our `PythonCommandLineInterface` to add IPython specific stuff. |
| 182 | """ |
| 183 | |
| 184 | def __init__(self, ipython_shell, *a, **kw): |
| 185 | kw["_completer"] = create_completer( |
| 186 | kw["get_globals"], |
| 187 | kw["get_globals"], |
| 188 | ipython_shell.magics_manager, |
| 189 | ipython_shell.alias_manager, |
| 190 | lambda: self.enable_dictionary_completion, |
| 191 | ) |
| 192 | kw["_lexer"] = create_lexer() |
| 193 | kw["_validator"] = IPythonValidator(get_compiler_flags=self.get_compiler_flags) |
| 194 | |
| 195 | super().__init__(*a, **kw) |
| 196 | self.ipython_shell = ipython_shell |
| 197 | |
| 198 | self.all_prompt_styles["ipython"] = IPythonPrompt(ipython_shell.prompts) |
| 199 | self.prompt_style = "ipython" |
| 200 | |
| 201 | # UI style for IPython. Add tokens that are used by IPython>5.0 |
| 202 | style_dict = {} |
| 203 | style_dict.update(default_ui_style) |
| 204 | style_dict.update( |
| 205 | { |
| 206 | "pygments.prompt": "#009900", |
| 207 | "pygments.prompt-num": "#00ff00 bold", |
| 208 | "pygments.out-prompt": "#990000", |
| 209 | "pygments.out-prompt-num": "#ff0000 bold", |
| 210 | } |
| 211 | ) |
| 212 | |
| 213 | self.ui_styles = {"default": Style.from_dict(style_dict)} |
| 214 | self.use_ui_colorscheme("default") |
| 215 | |
| 216 | def get_compiler_flags(self): |
| 217 | flags = super().get_compiler_flags() |
| 218 | if self.ipython_shell.autoawait: |
| 219 | flags |= PyCF_ALLOW_TOP_LEVEL_AWAIT |
| 220 | return flags |
| 221 | |
| 222 | |
| 223 | class InteractiveShellEmbed(_InteractiveShellEmbed): |