Hi, I have a program
os.loadAPI("Apis/DesignUtil")
os.loadAPI("Apis/AccountSytem")
os.loadAPI("Apis/windowSystem")
DesignUtil.setDesign("whiteLightGray")
local background,topBar =DesignUtil.getDesign()
local showOS1Menu = false;
local routine=nil;
programCache={}
table.insert(programCache,function() shell.run("OSCore/aboutW.app") end)
function updateCache()
for i=1, #programCache,1 do
routine=coroutine.create(programCache[i])
ok, err=coroutine.resume(routine)
end
end
term.setTextColor(colors.gray)
function registerClickEvent(x,y)
if x >=0 and x <=1+3-1 and y >=0 and y <=1+1-1 then
showOS1Menu= not showOS1Menu
end
end
function printOS1Menu()
if showOS1Menu then
term.setBackgroundColor(colors.lightGray)
term.setCursorPos(1,2)
print("About this device")
term.setCursorPos(1,3)
print("Software update ")
term.setCursorPos(1,4)
print("Restart device ")
term.setCursorPos(1,5)
print("Shut down ")
end
end
while true do
paintutils.drawImage(background,1,1)
paintutils.drawImage(topBar,1,1)
updateCache()
printOS1Menu()
term.setCursorPos(1,1)
term.setBackgroundColor(colors.lightGray)
print("O1|")
event, button, xPos, yPos = os.pullEvent("mouse_click")
registerClickEvent(xPos,yPos)
sleep(0.15)
end
which runs this program as a coroutine
os.loadAPI("Apis/windowSystem")
local afData = {}
local x,y=0;
function exit()
print(programCache[1])
end
local SysU=
{
text="Software update";
x=22;
y=7;
W=15;
H=1;
}
function loadAbout()
local abF=fs.open("data/osInfo","r")
local line = abF.readLine()
repeat
table.insert(afData,line) -- Puts the value of the current line into the table we have.
line = abF.readLine() -- read the next line
until line == nil -- readLine() returns nil when the end of the file is reached.
abF.close() -- Close up the file ready for use again.
end
loadAbout()
function registerClick(xPos,yPos)
shell.run("OSCore/loginUtil")
if xPos==window.x+window.W+1 and yPos==window.y then
exit()
end
if xPos >= SysU.x and xPos <= SysU.x + SysU.W - 1 and yPos >= SysU.y and yPos <= SysU.y + SysU.H then
shell.run("OSCore/updateManager.app")
end
end
local window=windowSystem.createWindow("About this Device",21,3,18,13,true,"Version:"..afData[1].." \n \n \n System: "..afData[2])
while true do
windowSystem.drawWindow(window)
term.setBackgroundColor(colors.white)
local event, button, XPos, YPos=os.pullEvent("mouse_click")
registerClick(XPos,YPos)
sleep(0.15)
end
It uses apis:
windowSystem:
local window=nil;
function createWindow(title,x,y,w,h,closeable,text)
window=
{
titlew=title;
x=x;
y=y;
W=w;
H=h;
ca=closeable;
text=text;
}
return window
end
function drawWindow(windowp)
term.setCursorPos(window.x,window.y)
term.setBackgroundColor(colors.lightGray)
for i=0, windowp.W do
term.setCursorPos(windowp.x+i,windowp.y)
print(" ")
term.setCursorPos(windowp.x+i,windowp.y+windowp.H)
print(" ")
end
for j=0, windowp.H do
term.setCursorPos(windowp.x,windowp.y+j)
print(" ")
term.setCursorPos(windowp.x+windowp.W,windowp.y+j)
print(" ")
end
term.setCursorPos(windowp.x+windowp.W/2-string.len(windowp.titlew)/2,windowp.y)
term.setTextColor(colors.gray)
print(windowp.titlew)
if(windowp.ca) then
term.setBackgroundColor(colors.red)
term.setCursorPos(windowp.x+windowp.W+1,windowp.y)
print("X")
term.setBackgroundColor(colors.white)
end
term.setCursorPos(windowp.x+2,windowp.y+2)
for i in string.gmatch(windowp.text,"[^\n]+") do
print(i)
x,y=term.getCursorPos()
if i== " " then
term.setCursorPos(windowp.x+1,y)
end
end
sleep(0.1)
end
and DesignUtil
local fileColorConfig=nil
local topBar=nil
local backGround=nil
local fileData = {}
function getDesign()
fileColorConfig=fs.open("data/colorCombos/current","r");
local line = fileColorConfig.readLine()
repeat
table.insert(fileData,line)
line = fileColorConfig.readLine()
until line == nil
fileColorConfig.close()
local fileColorSetting=fs.open("data/colorCombos/"..fileData[1],"r");
local fileDataSetting = {}
local lineSetting = fileColorSetting.readLine()
repeat
table.insert(fileDataSetting,lineSetting)
lineSetting = fileColorSetting.readLine()
until lineSetting == nil
fileColorSetting.close()
if fileDataSetting[1]=="0" then backGround=paintutils.loadImage("graphics/backgrounds/whiteBack.nfp") end
if fileDataSetting[1]=="1" then backGround=paintutils.loadImage("graphics/backgrounds/orangeBack.nfp") end
if fileDataSetting[1]=="2" then backGround=paintutils.loadImage("graphics/backgrounds/darkPinkBack.nfp") end
if fileDataSetting[1]=="3" then backGround=paintutils.loadImage("graphics/backgrounds/lightBlueBack.nfp") end
if fileDataSetting[1]=="4" then backGround=paintutils.loadImage("graphics/backgrounds/goldenBack.nfp") end
if fileDataSetting[1]=="5" then backGround=paintutils.loadImage("graphics/backgrounds/limeBack.nfp") end
if fileDataSetting[1]=="6" then backGround=paintutils.loadImage("graphics/backgrounds/pinkBack.nfp") end
if fileDataSetting[1]=="7" then backGround=paintutils.loadImage("graphics/backgrounds/grayBack.nfp") end
if fileDataSetting[1]=="9" then backGround=paintutils.loadImage("graphics/backgrounds/cyanBack.nfp") end --because 8 is topbar color
if fileDataSetting[1]=="a" then backGround=paintutils.loadImage("graphics/backgrounds/purpleBack.nfp") end
if fileDataSetting[1]=="b" then backGround=paintutils.loadImage("graphics/backgrounds/blueBack.nfp") end
if fileDataSetting[1]=="c" then backGround=paintutils.loadImage("graphics/backgrounds/brownBack.nfp") end
if fileDataSetting[1]=="d" then backGround=paintutils.loadImage("graphics/backgrounds/greenBack.nfp") end
if fileDataSetting[1]=="e" then backGround=paintutils.loadImage("graphics/backgrounds/redBack.nfp") end
if fileDataSetting[2]=="8"then topBar=paintutils.loadImage("graphics/topBars/topBarLightGray.nfp") end
fileColorConfig.close()
return backGround, topBar;
end
function setDesign(design)
fileColorConfig=fs.open("data/colorCombos/current","w");
fileColorConfig.write(design)
fileColorConfig.close()
end
What I would really like is for the coroutine program to be able to register the click and run exit(), not return control back to the program that called it, how could I do this?