| 1 |
"""This is an example that shows how to create new prompts for IPython""" |
| 2 |
|
| 3 |
from IPython.terminal.prompts import Prompts, Token |
| 4 |
import os |
| 5 |
|
| 6 |
|
| 7 |
class MyPrompt(Prompts): |
| 8 |
def in_prompt_tokens(self): |
| 9 |
return [(Token, os.getcwd()), (Token.Prompt, ">>>")] |
| 10 |
|
| 11 |
|
| 12 |
def load_ipython_extension(shell): |
| 13 |
new_prompts = MyPrompt(shell) |
| 14 |
new_prompts.old_prompts = shell.prompts |
| 15 |
shell.prompts = new_prompts |
| 16 |
|
| 17 |
|
| 18 |
def unload_ipython_extension(shell): |
| 19 |
if not hasattr(shell.prompts, "old_prompts"): |
| 20 |
print("cannot unload") |
| 21 |
else: |
| 22 |
shell.prompts = shell.prompts.old_prompts |