-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
69 lines (61 loc) · 2.39 KB
/
test.py
File metadata and controls
69 lines (61 loc) · 2.39 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from blessed import Terminal
from tifer import FileEditor
from sys import argv
term = Terminal()
if len(argv) < 2:
print('Missing required file argument')
exit(1)
file_path = argv[1]
editor = FileEditor(open(file_path, encoding='utf-8').read())
def utf8len(s):
return len(s.encode('utf-8'))
with term.fullscreen(), term.hidden_cursor():
oy = 0
while True:
render = ''
for i in range(oy, term.height - 1 + oy):
if i >= len(editor.text):
render += term.bold_grey(f'{len(editor.text)} line(s)')
break
chars = '◜◝◞◟'
if i%len(chars) == 0:
render += term.red(chars[i%len(chars)])
else:
render += term.blue(chars[i%len(chars)])
for j in range(len(editor.text[i])):
if j > term.width:
break
if editor.cursor == [i, j]:
render += term.on_white
render += editor.text[i][j] + term.normal
if editor.cursor[0] == i and editor.cursor[1] >= len(editor.text[i]):
render += term.on_white(' ')
render += '\n'
render += term.move_xy(0, term.height - 1) + term.on_blue(file_path) + ' ' + term.bold_blue(f'L{editor.cursor[0] + 1}, C{editor.cursor[1] + 1}') + ' ' + term.green(str(utf8len(str(editor))) + ' B')
print(term.home+term.clear+render, end='', flush=True)
with term.cbreak():
key = term.inkey()
if key.name == u'KEY_ESCAPE':
exit()
elif key.name == u'KEY_LEFT':
editor.move_xy(-1, 0)
elif key.name == u'KEY_RIGHT':
editor.move_xy(1, 0)
elif key.name == u'KEY_DOWN':
editor.move_xy(0, 1)
if editor.cursor[0] - oy >= term.height - 1:
oy += 1
elif key.name == u'KEY_UP':
editor.move_xy(0, -1)
if editor.cursor[0] - oy < 0:
oy -= 1
elif key.name == u'KEY_ENTER':
editor.write('\n')
if editor.cursor[0] - oy >= term.height - 1:
oy += 1
elif key.name == u'KEY_BACKSPACE':
if editor.cursor[0] - oy < 0:
oy -= 1
editor.backspace()
else:
editor.write(str(key))