-
Notifications
You must be signed in to change notification settings - Fork 0
/
textSmartEditor.py
84 lines (54 loc) · 1.94 KB
/
textSmartEditor.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import time
import sys
from textEditor import TextEditor
from core import curses
# import completion
raise Exception
class TextSmartEditor(TextEditor):
'''
option-o to write out
option-q to quit
'''
def __init__(self):
super(TextSmartEditor, self).__init__()
self.marginRight = self.width // 2
def updateDim(self):
super(TextSmartEditor, self).updateDim()
self.width -= self.marginRight
def checkErrors(self):
code = '\n'.join(self.lines)
try:
exec(code)
except Exception as e:
return e # type(e).__name__, e.__traceback__.tb_lineno
return
def updateScreen(self, endLine=True):
super(TextSmartEditor, self).updateScreen(endLine=endLine)
start = self.width + self.getMargin()
for y in range(self.height):
# space available = (self.marginRight - 2)
# msg = str(completion.understandLine(self.lines[y + self.scrollY]))
msg = str(self.checkErrors())
msg = msg[:self.marginRight - 2]
text = '| ' + msg
self.window.addstr(y, start, text, curses.color_pair(0))
if not endLine:
return
#self.print(, self.height - 1, resetX=True, fullLine=True)
msg1 = '<< option-q to quit >>'
msg2 = '<< option-o to save >>'
buf = '-' * ((self.width + self.marginLeft + self.marginRight) - len(msg1) - len(msg2) - 1)
if buf == '':
raise Exception('Make your window bigger (wider)')
text = msg1 + buf + msg2
self.window.addstr(self.height, 0, text, curses.color_pair(0)) # 16
if __name__ == '__main__':
if len(sys.argv) != 2:
print('usage: TextEditor file')
sys.exit(1)
# if not os.path.isfile(sys.argv[1]):
# print('error: file not found')
# sys.exit(1)
with TextSmartEditor() as m:
m.load(sys.argv[1])
m.run()