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