-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
text_editor.py
executable file
·68 lines (58 loc) · 2.23 KB
/
text_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
import config
from util.text_editor_checkup import *
import argparse, sys, os
from util.TextEditorUtility import TextEditorUtility
from util.terminal_text_editor import TextEditor
class StartEditor:
def multilineEditor(self, text="", placeholder="", filepath="", newFile=False, wd=""):
config.textEditor = TextEditor(config.mainWindow, working_directory=wd)
if newFile:
return config.textEditor.newFile()
elif filepath:
return config.textEditor.openFile(filepath)
return config.textEditor.multilineEditor(text, placeholder)
if __name__ == "__main__":
config.terminalColors = {
"ansidefault": "ansidefault",
"ansiblack": "ansiwhite",
"ansired": "ansibrightred",
"ansigreen": "ansibrightgreen",
"ansiyellow": "ansibrightyellow",
"ansiblue": "ansibrightblue",
"ansimagenta": "ansibrightmagenta",
"ansicyan": "ansibrightcyan",
"ansigray": "ansibrightblack",
"ansiwhite": "ansiblack",
"ansibrightred": "ansired",
"ansibrightgreen": "ansigreen",
"ansibrightyellow": "ansiyellow",
"ansibrightblue": "ansiblue",
"ansibrightmagenta": "ansimagenta",
"ansibrightcyan": "ansicyan",
"ansibrightblack": "ansigray",
}
# make sure relative path of plugins folder works
thisFile = os.path.realpath(__file__)
wd = os.path.dirname(thisFile)
# make utilities available to plugins
config.mainWindow = TextEditorUtility(working_directory=wd)
# startup
startup = StartEditor()
parser = argparse.ArgumentParser()
parser.add_argument('file', nargs='?')
parser.add_argument('--filename', '-f', nargs='?')
parser.add_argument('--text', '-t', nargs='?')
args = parser.parse_args()
if args.file:
startup.multilineEditor(filepath=args.file, wd=wd)
elif args.filename:
startup.multilineEditor(filepath=args.filename, wd=wd)
elif args.text:
startup.multilineEditor(text=args.text, wd=wd)
elif not sys.stdin.isatty():
#text = sys.stdin.read()
#startup.multilineEditor(text=text, wd=wd)
parser.print_help()
else:
startup.multilineEditor(newFile=True, wd=wd)