-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdemo-editor.py
48 lines (36 loc) · 1.04 KB
/
demo-editor.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
#!/usr/bin/env python3
"""
Demo editor
"""
import argparse
from tui_editor import TuiEditor
def main():
"""main"""
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument("file", help="File content to edit (nothing will be written)", default=__file__, nargs="?")
arg_parser.add_argument("--height", type=int, default=20)
args = arg_parser.parse_args()
with open(args.file) as f:
content = f.read().split('\n')
print("Hello editor! Ctrl+S to quit.")
e = TuiEditor()
e.set_text_lines(content)
e.height = args.height
e.show_line_numbers = True
e.on_cursor_pos_change = (
lambda: e.set_status_lines([
"line: %d/%d" % (e.cur_line_idx + 1, e.total_lines),
"col: %d" % e.col,
]))
e.edit()
print("Good bye!")
if __name__ == "__main__":
try:
import better_exchook # noqa
better_exchook.install()
except ImportError:
pass
try:
main()
except KeyboardInterrupt:
print("KeyboardInterrupt")