· 6 years ago · Nov 20, 2019, 04:08 PM
1isColor == false then
2 term.clear()
3 term.setCursorPos(1,1)
4 print("ZLR can only run on advanced/color computers!")
5end
6
7
8function setVariables()
9 width, height = term.getSize()
10 version = "1.1"
11 stopProgramPending = false
12end
13function clearScreen()
14 term.clear()
15 term.setCursorPos(1,1)
16end
17function printM(text, heightMod)
18 if heightMod == nil then
19 heightMod = 0
20 end
21
22 newLen = string.len(text) / 2
23 newWidth = width / 2
24 newWidth = newWidth - newLen
25 newWidth = math.floor(newWidth)
26 term.setCursorPos(newWidth, height / 2 + heightMod)
27 term.write(text)
28 term.setCursorPos(1,1)
29end
30setVariables()
31
32clearScreen()
33
34term.setTextColor(colors.red)
35printM("Please wait...", -1)
36term.setTextColor(colors.lime)
37printM("Loading FizzOS...", 1)
38
39sleep(math.random(1.0,2.0))
40
41clearScreen()
42
43--Set this variable to how many menu items there are in total:
44local menuItems = 6
45
46--Default menu item:
47local selectedItem = 1
48
49-- Main Operating System Loop!
50menuItemsBackup = menuItems - 1
51clearScreen()
52term.setTextColor(colors.lime)
53print("ZLR "..version)
54term.setTextColor(colors.white)
55
56
57
58function menuDraw()
59
60 clearScreen()
61 term.setTextColor(colors.lime)
62 print("ZLR "..version)
63 term.setTextColor(colors.white)
64
65 term.setCursorPos(3,3)
66 term.write("Programs")
67 if selectedItem == 1 then
68 term.setCursorPos(2,3)
69 term.write(">")
70 else
71 term.setCursorPos(2,3)
72 term.write(" ")
73 end
74 yLevel = 4
75
76 term.setCursorPos(3,yLevel)
77 term.write("Terminal")
78 if selectedItem == 2 then
79 term.setCursorPos(2,yLevel)
80 term.write(">")
81 else
82 term.setCursorPos(2,yLevel)
83 term.write(" ")
84 end
85 yLevel = yLevel + 1
86
87 term.setCursorPos(3,yLevel)
88 term.write("Help")
89 if selectedItem == 3 then
90 term.setCursorPos(2,yLevel)
91 term.write(">")
92 else
93 term.setCursorPos(2,yLevel)
94 term.write(" ")
95 end
96 yLevel = yLevel + 1
97
98 term.setCursorPos(3,yLevel)
99 term.write("ZLR")
100 if selectedItem == 4 then
101 term.setCursorPos(2,yLevel)
102 term.write(">")
103 else
104 term.setCursorPos(2,yLevel)
105 term.write(" ")
106 end
107 yLevel = yLevel + 1
108
109 term.setCursorPos(3,yLevel)
110 term.write("Shutdown")
111 if selectedItem == 5 then
112 term.setCursorPos(2,yLevel)
113 term.write(">")
114 else
115 term.setCursorPos(2,yLevel)
116 term.write(" ")
117 end
118 yLevel = yLevel + 3
119
120 --if peripheral.getType("right") == "drive" or peripheral.getType("left") == "drive" or peripheral.getType("back") == "drive" or peripheral.getType("front") == "drive" or peripheral.getType("bottom") == "drive" or peripheral.getType("top") == "drive" then
121 -- showDiskdrive = true
122 -- menuItems = menuItemsBackup + 1
123 --else
124 -- showDiskdrive = false
125 -- menuItems = menuItemsBackup
126 --end
127
128 showDiskdrive = false
129
130 local tSides = rs.getSides()
131 for n,sSide in ipairs( tSides ) do
132 if peripheral.getType(sSide) == "drive" then
133 disk = peripheral.wrap(sSide)
134 if disk.hasData() then
135 sDrive = sSide
136 showDiskdrive = true
137 break
138 end
139 end
140 end
141
142 showModem = false
143 for n,sSide in ipairs( tSides ) do
144 if peripheral.getType(sSide) == "modem" then
145 sDrive = sSide
146 showModem = true
147 break
148 end
149 end
150
151 if showDiskdrive == false and showModem == true then
152 term.setCursorPos(1,height)
153 term.write("You must have a floppy connected to use networking!")
154 showModem = false
155 menuItems = menuItemsBackup
156 end
157
158 if showDiskdrive then
159 term.setCursorPos(3,yLevel)
160 term.write("Diskdrive")
161 if selectedItem == 6 then
162 term.setCursorPos(2,yLevel)
163 term.write(">")
164 else
165 term.setCursorPos(2,yLevel)
166 term.write(" ")
167 end
168 yLevel = yLevel + 1
169 end
170
171 if showModem then
172 term.setCursorPos(3,yLevel)
173 term.write("Network")
174 if selectedItem == 7 then
175 term.setCursorPos(2,yLevel)
176 term.write(">")
177 else
178 term.setCursorPos(2,yLevel)
179 term.write(" ")
180 end
181 yLevel = yLevel + 1
182 end
183
184 if showModem and showDiskdrive then
185 menuItems = menuItemsBackup + 2
186 elseif showDiskdrive or showModem then
187 menuItems = menuItemsBackup + 1
188 end
189 if showDiskdrive == false and showModem == true then
190 term.setCursorPos(1,height)
191 term.write("You must have a floppy connected to use networking!")
192 showModem = false
193 end
194
195 event, parm = os.pullEvent()
196 parm = tostring(parm)
197
198 if event == "key" and parm == "200" and selectedItem > 1 then
199 selectedItem = selectedItem - 1
200 end
201
202 if event == "key" and parm == "208" and selectedItem < menuItems then
203 selectedItem = selectedItem + 1
204 end
205
206 if event == "key" and parm == "28" then
207 --- Old programs menu item.
208 --if selectedItem == 1 then
209 -- clearScreen()
210 -- local tPrograms = shell.programs( bAll )
211 -- clearScreen()
212 -- textutils.pagedTabulate( tPrograms )
213 -- term.setCursorPos(1,height)
214 -- term.write("Press any key to continue...")
215 -- os.pullEvent("char")
216 -- clearScreen()
217 --end
218
219 -- New programs menu item
220 if selectedItem == 1 then
221 clearScreen()
222 local programList = shell.programs()
223 local selectedProgram = 1
224 local blocked = false
225
226 function isBlocked(programName)
227 local fBlocked = false
228 if programName == "alias" then
229 fBlocked = true
230 end
231 if programName == "cd" then
232 fBlocked = true
233 end
234 if programName == "shell" then
235 fBlocked = true
236 end
237 if programName == "lua" then
238 fBlocked = true
239 end
240 if programName == "clear" then
241 fBlocked = true
242 end
243 if programName == "ZLR" then
244 fBlocked = true
245 end
246 if programName == "startup" then
247 fBlocked = true
248 end
249 return fBlocked
250 end
251
252 while true do
253 clearScreen()
254 term.setTextColor(colors.lightBlue)
255 print("Programs:")
256 term.setTextColor(colors.red)
257 term.setCursorPos(width - string.len("Press Backspace to go back!"), 1)
258 term.write("Press Backspace to go back!")
259 term.setCursorPos(3,3)
260 term.setTextColor(colors.purple)
261 if isBlocked(programList[selectedProgram]) == false then
262 term.setTextColor(colors.magenta)
263 else
264 term.setTextColor(colors.red)
265 end
266 term.write(programList[selectedProgram])
267
268 term.setCursorPos(5,4)
269 term.setTextColor(colors.pink)
270 term.write("#"..selectedProgram)
271
272
273 event, parm = os.pullEvent()
274 parm = tostring(parm)
275
276 if event == "key" and parm == "205" then
277 if selectedProgram < table.maxn(programList) then
278 selectedProgram = selectedProgram + 1
279 end
280 end
281
282 if event == "key" and parm == "203" then
283 if selectedProgram > 1 then
284 selectedProgram = selectedProgram - 1
285 end
286 end
287
288 if event == "key" and parm == "14" then
289 clearScreen()
290 break
291 end
292
293 if event == "key" and parm == "28" and not isBlocked(programList[selectedProgram]) then
294 local tArgs = {}
295 local curArg = "arg"
296 while not curArg == "" do
297 curArg = table.remove(tArgs,1)
298 end
299 clearScreen()
300 term.setTextColor(colors.blue)
301 print("Enter arguments:")
302 local input = "arg"
303 while true do
304 if table.maxn(tArgs) == 10 then
305 term.setTextColor(colors.red)
306 print("Max arguments reached! Moving on...")
307 sleep(2)
308 break
309 end
310
311 term.setTextColor(colors.white)
312 input = read()
313 if input == "" then
314 break
315 else
316 table.insert(tArgs, input)
317 term.setTextColor(colors.lightBlue)
318 print("Next argument (enter nothing to continue)")
319 end
320 end
321 clearScreen()
322
323 term.setTextColor(colors.white)
324
325 shell.run(programList[selectedProgram], tArgs[1], tArgs[2], tArgs[3], tArgs[4], tArgs[5], tArgs[6], tArgs[7], tArgs[8], tArgs[9], tArgs[10])
326 term.setTextColor(colors.white)
327 term.setBackgroundColor(colors.black)
328 term.setCursorPos(width - string.len("Program finished! Press any key to continue!"), height)
329 term.write("Program finished! Press any key to continue!")
330 os.pullEvent("char")
331 end
332
333
334 end
335 end
336
337 if selectedItem == 2 then
338 clearScreen()
339 term.setTextColor(colors.white)
340 shell.run("lua")
341 end
342 if selectedItem == 4 then
343 clearScreen()
344 term.setTextColor(colors.red)
345 printM("Logging off to MineOS...")
346 sleep(math.random(1.0,2.5))
347 clearScreen()
348 term.setTextColor(colors.white)
349 stopProgramPending = true
350 end
351 if selectedItem == 3 then
352 clearScreen()
353 term.setTextColor(colors.cyan)
354 print("FizzOS & ComputerCraft Help - Credits:")
355 term.setTextColor(colors.white)
356 term.setCursorPos(1,2)
357 print("ZLR BY St_17 (me).")
358 print("ComputerCraft by Daniel (dan200). His twitter: @DanTwoHundred")
359 print("Some assitance in ComputerCraft by Aaron (cloudy). His twitter: @CloudHunter")
360 print("The community on the forums and espernet for beta testing and support.")
361 print("Thanks to nitrogenfingers for the paint program.")
362 print("Thanks to deadlystrike for hosting www.computercraft.info")
363 print("Thanks to Eloraam for permission to interface with Redpower2")
364 print("Thanks to Mojang, the Forge team, the MCP team amd the LUA team.")
365 clearScreen()
366 term.setTextColor(colors.cyan)
367 print("FizzOS & ComputerCraft Help - ComputerCraft:")
368 term.setTextColor(colors.white)
369 term.setCursorPos(1,2)
370 end
371 if selectedItem == 5 then
372 clearScreen()
373 term.setTextColor(colors.red)
374 printM("Shutting down ZLR...")
375 sleep(math.random(1.0,3.0))
376 clearScreen()
377 term.setTextColor(colors.white)
378 os.shutdown()
379 end
380
381 if selectedItem == 6 then
382 clearScreen()
383 printM("Incomplete.")
384 printM("Press any key", 1)
385 os.pullEvent("char")
386 end
387
388 if selectedItem == 7 then
389 local tSides = rs.getSides()
390 for n,sSide in ipairs( tSides ) do
391 if peripheral.getType(sSide) == "modem" then
392 sModem = sSide
393 break
394 end
395 end
396
397 clearScreen()
398 rednet.open(sModem)
399 rednet.broadcast("ZLR.PING")
400 term.setTextColor(colors.red)
401 printM("Sent a ping message.", -1)
402 term.setTextColor(colors.lightBlue)
403 printM("Press any key to continue!", 1)
404 term.setTextColor(colors.white)
405 sText = "More networking funtionality coming soon!"
406 term.setCursorPos(width - string.len(sText), height)
407 term.write(sText)
408 os.pullEvent("char")
409 rednet.close(sModem)
410 end
411
412 end
413
414end
415
416function drawMenu_extras()
417 timeString = textutils.formatTime(os.time(), false)
418 oldX, oldY = term.getCursorPos()
419 term.setCursorPos(width - string.len(timeString), height)
420 term.write(timeString)
421end
422
423while true do
424
425 ------- Can't work out the parallel API properly. :( -------
426
427 --parallel.waitForAll(menuDraw(), drawMenu_extras())
428 --if stopProgramPending == true then
429 -- break
430 --end
431
432 menuDraw()
433 if stopProgramPending == true then
434 break
435 end
436
437 --drawMenu_extras()
438end