-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomIPython.py
More file actions
47 lines (39 loc) · 1.18 KB
/
customIPython.py
File metadata and controls
47 lines (39 loc) · 1.18 KB
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
import re
import IPython
def escape_ansi(s):
return re.compile(r'''
\x1B # ESC
(?: # 7-bit C1 Fe (except CSI)
[@-Z\\-_]
| # or [ for CSI, followed by a control sequence
\[
[0-?]* # Parameter bytes
[ -/]* # Intermediate bytes
[@-~] # Final byte
)
''', re.VERBOSE).sub('', s)
def myIPython(*args, **kwargs):
def escape_ansi(s):
return re.compile(r'''
\x1B # ESC
(?: # 7-bit C1 Fe (except CSI)
[@-Z\\-_]
| # or [ for CSI, followed by a control sequence
\[
[0-?]* # Parameter bytes
[ -/]* # Intermediate bytes
[@-~] # Final byte
)
''', re.VERBOSE).sub('', s)
def exception_handler(exception_type, exception, traceback):
nonlocal myTB
tb = '\n'.join(escape_ansi(l) for l in traceback)
myTB = "%s" % tb
def getTB():
nonlocal myTB
return myTB
ip = IPython.InteractiveShell(*args, **kwargs)
ip._showtraceback = exception_handler
ip.getTB = getTB
myTB = None
return ip