· 2 years ago · Mar 10, 2023, 01:10 PM
1--Boiler Plate [OpenComputers]
2local component = require("component");
3local filesystem = require("filesystem");
4local sides = require("sides");
5local event = require("event");
6local serialization = require("serialization");
7local term = require("term");
8local thread = require("thread");
9local computer = require("computer");
10local gpu = component.gpu
11local run = true;
12api = {};
13local version = "0.1"
14api["status"] = "Offline";
15
16function closeListener(_, _, key)
17 if key == nil then key = 96; end
18 if key == 96 then
19 print("Killing Program...");
20 run = false;
21 filesystem.setAutorunEnabled(false)
22 event.ignore("key_up", closeListener);
23 end
24end
25event.listen("key_up", closeListener);
26
27function start()
28
29end
30
31function stop()
32
33end
34
35local function indexTime(timeInSeconds)
36 local numberOfSeconds = timeInSeconds % 60;
37 local numberOfMinutes = math.floor(timeInSeconds / 60);
38 local numberOfHours = math.floor(numberOfMinutes / 60);
39 numberOfMinutes = numberOfMinutes % 60;
40 local numberOfDays = math.floor(numberOfHours / 24);
41 numberOfHours = numberOfHours % 24;
42
43 if numberOfSeconds < 10 then numberOfSeconds = "" .. 0 .. numberOfSeconds; end
44 if numberOfMinutes < 10 then numberOfMinutes = "" .. 0 .. numberOfMinutes; end
45 if numberOfHours < 10 then numberOfHours = "" .. 0 .. numberOfHours; end
46 if numberOfDays < 10 then numberOfDays = "" .. 0 .. numberOfDays; end
47 local output = "";
48 if numberOfDays ~= "00" then output = output .. numberOfDays .. ":"; end
49 if numberOfHours ~= "00" then output = output .. numberOfHours .. ":"; end
50 output = output .. numberOfMinutes .. ":" .. numberOfSeconds;
51 return output;
52end
53
54function updateDisplay()
55 term.clear();
56 while run do
57 gpu.set(1,1, string.rep("═", 80));
58 gpu.set(2,2, "Reactor Controller [Version " .. version .. "]");
59 gpu.set(2,3, "Reactor Status: ");
60 local uptime = indexTime(math.floor(computer.uptime()))
61 gpu.set(80 - string.len(uptime), 3, "Uptime: " .. uptime);
62 gpu.set(2,4, "Autostart: ");
63 end
64end
65display = thread.create(updateDisplay);
66
67--Main Loop
68while run do
69 os.sleep(0);
70end
71
72--Program Close