View difference between Paste ID: NFrPqKQd and ANzmpXA5
SHOW: | | - or go back to the newest paste.
1
local shell = _G.shell
2
os.loadAPI("uap")
3
local sx,sy = term.getSize()
4
local function mainButton()
5
  while true do
6
  if uap.getU() == true then
7
  term.setTextColor(colors.white)
8
  term.setBackgroundColor(colors.black)
9
  for i=1,sx do
10
    term.setCursorPos(i,1)
11
    term.write(" ")
12
  end
13
  term.setCursorPos(1,1)
14
  local time = os.time()
15
  local formattedTime = textutils.formatTime(time, false)
16
  write(formattedTime)
17
  local isRO = false
18
  for k,v in pairs(redstone.getSides()) do
19
    if (rednet.isOpen(v)) then
20
      isRO = true
21
    end
22
  end
23
  local texxt = nil
24
  if (isRO) then
25
    texxt = "Rednet: OK"
26
  else
27
    texxt = "Rednet: OFF"
28
  end
29
  term.setCursorPos(sx-string.len(texxt),1)
30
  term.write(texxt)
31
  for i=1,sx do
32
    term.setCursorPos(i,sy)
33
    term.write(" ")
34
  end
35
  term.setCursorPos(sx/2+1,sy)
36
  write("O")
37
  uap.setU(false)
38
  end
39-
  os.sleep(1)
39+
  os.sleep(0.1)
40
  end
41
end
42
local function click()
43
  while true do
44
    local event, button, x, y = os.pullEvent( "mouse_click")
45-
    if (y == sy) then
45+
    if (y == sy and uap.getU() ~= "terminate") then
46
      os.reboot()
47
    end
48
  end
49
end
50
local namev = nil
51-
function sopen(names)
51+
function sopen(name)
52-
  shell.run(names)
52+
    local file = fs.open(name, "r")
53
    if file then
54
      local env = setmetatable({},{__index=_G})
55-
  name = namev
55+
      print(name)
56-
  sopen(name)
56+
      local ok, msg = pcall(loadfile(name,env))
57
      if not ok then
58-
function openFile(name)
58+
    	term.setBackgroundColor(colors.red)
59
    	term.clear()
60
    	term.setCursorPos(2,2)
61
    	term.write("CODE ERROR OCCURED!")
62
    	term.setCursorPos(3,5)
63
    	term.write(name.." crashed! Message: ")
64
    	term.setCursorPos(2,7)
65
        msg = msg:gsub("tos:56:", name..":")
66
    	print(msg)
67
    	term.setCursorPos(2,15)
68
    	term.write("Any key to restart...")
69
    	os.pullEvent("char")
70
    	os.reboot()
71
  	  end
72
    else
73
      term.clear()
74
        term.setBackgroundColor(colors.blue)
75
    	term.clear()
76
    	term.setCursorPos(2,2)
77
    	term.write("FILE ERROR OCCURED!")
78
    	term.setCursorPos(3,5)
79
    	term.write("There is no such app!")
80
    	term.setCursorPos(2,7)
81
    	print("Fix solution: Use Updater to download it!")
82
    	term.setCursorPos(2,15)
83
    	term.write("Any key to go back...")
84
    	os.pullEvent("char")
85
    	os.reboot()
86
    end
87
end
88
local function open()
89
  sopen(namev)
90
end
91
function openFile(name,safe)
92
  namev = name
93
  if safe then open() else
94
  parallel.waitForAny(click,open,mainButton)
95
  end
96
end
97
function writePersistentVariable(variable,value)
98
  local f = fs.open(".variables/"..variable,"w")
99
  f.write(value)
100
  f.close()
101
end
102
function getPersistentVariable(variable)
103
  local f = fs.open(".variables/"..variable,"r")
104
  if f then
105
  value = f.readAll()
106
  f.close()
107
  return value
108
  else return nil end
109
end