-
Notifications
You must be signed in to change notification settings - Fork 0
/
preload.js
162 lines (142 loc) · 3.18 KB
/
preload.js
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
let promptHead = global.sysEval ? "#" : ">"
if(global.sysEval){
print(`${color.reset}you are running with ${color.warn}sandbox disabled${color.reset}`)
}
charms.noAutosave = show=>autosave ? null : show("warn","nosave")
charms.add(charms.noAutosave)
{ //helpsys
let htxt;htxt = function(cmd,help) {
htxt[cmd] = help
}
global.helptxt = htxt
func("help word",(done,cmd,shownCmd)=>{
if(!shownCmd)return done(print("try: help <command>;\nto list all commands try: cmds"));
print(htxt[shownCmd] || "no help for this command")
done()
})
}
helptxt("set","sets the value of a node")
func("set path value",(done,cmd,path,...value)=>{
//let s2 = path.pop()
let val = [...value].join(" ")
let numOf = Number(val.trim())
if(!isNaN(numOf))val = numOf;
assertFile(path).value = val
done()
})
func("mkobj path",(done,cmd,path,value)=>{
assertFile(path).value = {}
done()
})
func("cd path",(done,cmd,path)=>{
cd(path)
done()
})
func("nosave",(done,cmd,path)=>{
global.noSave = true
print("your changes will not be saved")
done()
})
func("dosave",(done,cmd,path)=>{
global.noSave = false
print("your changes will be saved")
done()
})
func("save",(done,cmd,path)=>{
global.noSave = true
save()
print("saved")
done()
})
func("exit",(done,cmd,path)=>{
global.noSave = true
print("goodbye! ")
done()
exit()
})
func("json path",(done,cmd,path)=>{
let f = assertFile(path)
ask('edit> ',JSON.stringify(f.value),rst=>{
if(!rst || rst.length == 0){
print("no changes made")
return done()
}
f.trustedValue = JSON.parse(rst)
print("changed")
return done()
})
done()
})
func("mkarr path",(done,cmd,path,value)=>{
assertFile(path).value = []
done()
})
func("get path",(done,cmd,path)=>{
let l = file(path)
done(l ? l.preview : null)
})
func("dump path",(done,cmd,path)=>{
let l = file(path)
done(l ? l.value : null)
})
func("stod path",(done,cmd,path)=>{ //storage dump
let l = file(path)
done(l ? l.storage : null)
})
func("ls path",(done,cmd,path)=>{
let l = file((path))
done(l ? l.list.map(m=>m.name) : null)
})
func("rm path",(done,cmd,path)=>{
let l = file(path)
l.value = null
done()
})
func("resolve-path path",(done,cmd,path)=>{
print(pathResolve(path))
done()
})
func("jsh",(done,cmd,path)=>{
let promptText = "jsh"+promptHead
function prompt() {
ask(promptText,"",ans=>{
ans = ans.trim()
if(ans == "exit")return done();
try {
print(eval(ans))
} catch (e) {
print(e)
}
prompt()
})
}
prompt()
})
func("debug",done=>{
func("charm word value",(done,cmd,color,...text)=>{
text = text.join(" ")
charms.add( show=> show(color,text) )
done()
})
func("killer",(done,cmd)=>{
let killer;
killer = show=>{
show("warn","(we are waching you)")
charms.remove(killer)
}
charms.add(killer)
done()
})
func("evfire word",(done,cmd,ev,...args)=>{
event(ev).fire(...args)
done()
})
func("evawait word",(done,cmd,ev)=>{
event(ev).addListener(print)
done()
})
print("loaded debug commands")
done()
})
func("load word",(done,cmd,key)=> done(require(key)) )
print("ljsoned v1.0");