-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprompt.py
55 lines (37 loc) · 1.12 KB
/
prompt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
"""
import code
import readline
import rlcompleter
import os
import sys
from . import interactivenamespace
def init_readline():
import atexit
history = "/tmp/oahistory"
readline.set_history_length(20000)
def save_history():
readline.write_history_file(history)
if os.path.exists(history):
readline.read_history_file(history)
atexit.register(save_history)
namespace = vars(interactivenamespace)
readline.set_completer(rlcompleter.Completer(namespace).complete)
readline.parse_and_bind("tab: complete")
def init_prompt():
sys.ps1 = '\x01\x1b[36m\x02>>>\x01\x1b[m\x02 '
sys.ps2 = '\x01\x1b[36m\x02...\x01\x1b[m\x02 '
if readline.get_current_history_length():
# it seems like this was launched froma n interactive session,
# and already has a histfile...
pass
else:
init_readline()
init_prompt()
def interact():
code.interact("", local=vars(interactivenamespace))
def handle_args():
import argparse
cli = argparse.ArgumentParser()
cli.add_argument('--thatnumber', type=int, default=17)
return cli.parse_args()