forked from ipython/ipython
-
Notifications
You must be signed in to change notification settings - Fork 0
Trash: Cookbook Defining prompts via hooks
Brian Granger edited this page Feb 13, 2013
·
1 revision
The following example code shows how to define input and output prompts via hooks:
def myinputprompt(self, cont): ip = self.api count = str(len(ip.user_ns["_ih"])) colors = Prompts.PromptColors[""].colors pwd = os.getcwd() if cont: return "%s%s%s: " % ( \ colors.in_prompt2, "."*(4+len(pwd)+1+len(count)+1), colors.normal) else: return "%sIn [%s|%s%s%s]: %s" % ( \ colors.in_prompt, pwd, colors.out_number, count, colors.in_prompt, colors.normal) def myoutputprompt(self): ip = self.api count = str(len(ip.user_ns["_ih"])) colors = Prompts.PromptColors[""].colors pwd = os.getcwd() prompt = "%sOut[%s|%s%s%s]: %s" % ( \ colors.out_prompt, pwd, colors.out_number, count, colors.out_prompt, colors.normal) return prompt ipapi.get().set_hook("generate_prompt", myinputprompt) ipapi.get().set_hook("generate_output_prompt", myoutputprompt)