-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtedit.src
More file actions
123 lines (95 loc) · 2.84 KB
/
tedit.src
File metadata and controls
123 lines (95 loc) · 2.84 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import_code("./utils/argv.src")
import_code("./utils/state.src")
import_code("./utils/enrichedUserInput.src")
import_code("./utils/router.src")
import_code("./utils/localConfig.src")
import_code("./utils/highlighter.src")
import_code("./utils/basicEditor.src")
import_code("./utils/codeEditorPlugin.src")
parseArgs = function()
argDefinitions = []
argDefinitions.push((new Argv.Arg).constructor("h", "help", Argv.ArgType.FLAG, "Print help"))
helpBlock = []
helpBlock.push("TEdit CLI")
helpBlock.push("Example: <b>tedit file</b>")
helpBlock.push("")
for argDefinition in argDefinitions
helpBlock.push(argDefinition.toString())
end for
help = helpBlock.join(char(10))
argv = (new Argv).constructor(argDefinitions, help)
argv.parse()
return argv
end function
showPlugins = function()
availableEditors = [BasicEditor] + editorPlugins
index = 0
print("<b><u>Available editors</u></b>")
for availableEditor in availableEditors
print(char(9) + "(" + index + ") <b>" + availableEditor.name + "</b>")
print((char(9) * 2) + availableEditor.description)
index = index + 1
end for
pluginIndex = UserInput.prompt(char(10) + "Select plugin:" + char(10) + "> ")
pluginIndex = pluginIndex.raw.val
if (availableEditors.hasIndex(pluginIndex)) then
return availableEditors[pluginIndex]
else
clear_screen
print("<color=red>Invalid choice</color>")
showPlugins()
end if
end function
openEditor = function(file)
//custom menus
BasicEditor.getCustomMainCmds = function()
return {
":plugin": "switchPlugin"
}
end function
BasicEditor.mainCustomInteractEval = function(command, value)
me = self
if (command == "switchPlugin") then
editor = showPlugins()
activeEditor.saveQuit()
activeEditor = (new editor).constructor(file, localShell, config)
activeEditor.open()
else
me.exception("<color=red>Command is not yet implemented</color>")
end if
end function
//plugins
editorPlugins.push(CodeEditorPlugin)
//init
if (typeof(file) == "file") then
file = file.path
end if
foundSupport = false
for EditorPlugin in editorPlugins
if (EditorPlugin.supports(file)) then
activeEditor = (new EditorPlugin).constructor(file, localShell, config)
activeEditor.open()
foundSupport = true
break
end if
end for
if (not foundSupport) then
activeEditor = (new BasicEditor).constructor(file, localShell, config)
activeEditor.open()
end if
end function
argv = parseArgs()
if (argv.getWithKey("help") == true) then
exit(help)
end if
globals.activeEditor = null
globals.editorPlugins = []
globals.config = (new LocalConfig).constructor(get_shell.host_computer, "/tedit.cfg")
globals.targetFile = argv.get(0, true)
globals.appRouter = (new Router).constructor()
globals.localShell = get_shell
onMain = function(args, stdin)
openEditor(targetFile)
end function
appRouter.register("main", @onMain)
appRouter.route("main")