diff --git a/EFI/Full.lua b/EFI/Full.lua index 4cfdbd06..635d0e91 100644 --- a/EFI/Full.lua +++ b/EFI/Full.lua @@ -2,7 +2,7 @@ -- local component, computer, unicode = require("component"), require("computer"), require("unicode") -local stringsMain, stringsBootFromURL, stringsChangeLabel, stringKeyDown, stringsInit, stringsFilesystem, componentProxy, componentList, pullSignal, uptime, tableInsert, mathMax, mathMin, mathHuge = "MineOS EFI", "Internet boot", "Change label", "key_down", "/init.lua", "filesystem", component.proxy, component.list, computer.pullSignal, computer.uptime, table.insert, math.max, math.min, math.huge +local stringsMain, stringsBootFromURL, stringsChangeLabel, stringKeyDown, stringsInit, stringsFilesystem, componentProxy, componentList, pullSignal, uptime, tableInsert, mathMax, mathMin, mathHuge, mathFloor = "MineOS EFI", "Internet recovery", "Change label", "key_down", "/init.lua", "filesystem", component.proxy, component.list, computer.pullSignal, computer.uptime, table.insert, math.max, math.min, math.huge, math.floor local colorsTitle, colorsBackground, colorsText, colorsSelectionBackground, colorsSelectionText, eeprom, gpu, internetAddress = 1, 0, 1, 1, 0, componentProxy(componentList("eeprom")()), componentProxy(componentList("gpu")()), componentList("internet")() gpu.bind(componentList("screen")(), true) @@ -16,7 +16,7 @@ elseif depth == 8 then colorsTitle, colorsBackground, colorsText, colorsSelectionBackground, colorsSelectionText = 0x2D2D2D, 0xE1E1E1, 0x878787, 0x878787, 0xE1E1E1 end -local setBackground, setForeground, round, restrict = +local setBackground, setForeground, restrict = function(color) if color ~= curentBackground then gpu.setBackground(color) @@ -29,9 +29,6 @@ local setBackground, setForeground, round, restrict = currentForeground = color end end, - function(n) - return math.floor(n + 0.5) - end, function(text, limit, skip) if #text < limit then text = text .. string.rep(" ", limit - #text) @@ -48,7 +45,7 @@ local rectangle, centrizedText, menuElement = gpuFill(x, y, width, height, " ") end, function(y, foreground, text) - local x = round(screenWidth / 2 - #text / 2) + local x = mathFloor(screenWidth / 2 - #text / 2) setForeground(foreground) gpuSet(x, y, text) end, @@ -60,24 +57,37 @@ local rectangle, centrizedText, menuElement = } end -local function status(y, titleText, statusText, needWait) - y = y or round(screenHeight / 2 - 1) - +local function title(yHalfer, titleText) + y = mathFloor(screenHeight / 2 - yHalfer / 2) rectangle(1, 1, screenWidth, screenHeight, colorsBackground) centrizedText(y, colorsTitle, titleText) - centrizedText(y + 2, colorsText, statusText or "") - if needWait then - repeat - local event = pullSignal() - until event == stringKeyDown or event == "touch" + + return y + 2 +end + +local function status(titleText, statusText, needWait) + local lines = {} + for line in statusText:gmatch("[^\r\n]+") do + lines[#lines + 1] = line:gsub("\t", " ") + end + + local y = title(#lines, titleText) + + for i = 1, #lines do + centrizedText(y, colorsText, lines[i]) + y = y + 1 end - return y + if needWait then + repeat + needWait = pullSignal() + until needWait == stringKeyDown or needWait == "touch" + end end local loadInit, menuBack, menu, input, netboot = function(proxy) - status(NIL, stringsMain, "Booting from " .. proxy.address) + status(stringsMain, "Booting from " .. proxy.address) local data, chunk, handle, success, reason = "", "", proxy.open(stringsInit, "r") while chunk do @@ -85,7 +95,7 @@ local loadInit, menuBack, menu, input, netboot = end proxy.close(handle) - success, reason = load(data) + success, reason = load(data, "=OS") if success then success, reason = pcall(success) if success then @@ -93,7 +103,7 @@ local loadInit, menuBack, menu, input, netboot = end end - status(NIL, stringsMain, "Failed to run init file: " .. reason, 1) + status(stringsMain, reason, 1) end, function() return menuElement("Back", NIL, 1) @@ -105,13 +115,13 @@ local loadInit, menuBack, menu, input, netboot = end while 1 do - local y, x, eventData = status(round(screenHeight / 2 - (#elements + 2) / 2), titleText) + 2 + local y, x, eventData = title(#elements + 2, titleText) for i = 1, #elements do - x = round(screenWidth / 2 - #elements[i].s / 2) + x = mathFloor(screenWidth / 2 - #elements[i].s / 2) if i == selectedElement then - rectangle(round(screenWidth / 2 - maxLength / 2) - 2, y, maxLength + 4, 1, colorsSelectionBackground) + rectangle(mathFloor(screenWidth / 2 - maxLength / 2) - 2, y, maxLength + 4, 1, colorsSelectionBackground) setForeground(colorsSelectionText) gpuSet(x, y, elements[i].s) else @@ -146,7 +156,8 @@ local loadInit, menuBack, menu, input, netboot = while 1 do eblo = prefix .. text gpuFill(1, y, screenWidth, 1, " ") - gpuSet(round(screenWidth / 2 - #eblo / 2), y, eblo .. (state and "█" or "")) + gpuSetForeground(colorsText) + gpuSet(mathFloor(screenWidth / 2 - #eblo / 2), y, eblo .. (state and "█" or "")) eventData = {pullSignal(0.5)} if eventData[1] == stringKeyDown then @@ -172,13 +183,13 @@ local loadInit, menuBack, menu, input, netboot = function(url) local runReason, data, handle, result, reason = function(text) - status(NIL, stringsBootFromURL, "Internet boot failed: " .. text, 1) + status(stringsBootFromURL, "Internet boot failed: " .. text, 1) end, "", componentProxy(internetAddress).request(url) if handle then - status(NIL, stringsBootFromURL, "Downloading script...") + status(stringsBootFromURL, "Downloading script...") while 1 do result, reason = handle.read(mathHuge) if result then @@ -211,7 +222,7 @@ local loadInit, menuBack, menu, input, netboot = end end -status(NIL, stringsMain, "Hold Alt to show boot options menu") +status(stringsMain, "Hold Alt to show boot options menu") local deadline, eventData = uptime() + 1 while uptime() < deadline do @@ -239,23 +250,21 @@ while uptime() < deadline do if not isReadOnly then tableInsert(filesystemOptions, 1, menuElement(stringsChangeLabel, function() - proxy.setLabel(input(status(NIL, stringsChangeLabel) + 2, "Enter new name: ")) + proxy.setLabel(input(title(2, stringsChangeLabel), "Enter new name: ")) end, 1)) tableInsert(filesystemOptions, 2, menuElement("Format", function() - status(NIL, stringsMain, "Formatting filesystem " .. address) + status(stringsMain, "Formatting filesystem " .. address) for _, file in ipairs(proxy.list("/")) do proxy.remove(file) end - status(NIL, stringsMain, "Formatting finished", 1) + status(stringsMain, "Formatting finished", 1) end, 1)) end - if proxy.exists(stringsInit) then - tableInsert(filesystemOptions, 1, menuElement("Set as startup", function() - eepromSetData(address) - end, 1)) - end + tableInsert(filesystemOptions, 1, menuElement("Set as startup", function() + eepromSetData(address) + end, 1)) menu(label .. " (" .. address .. ")", filesystemOptions) end @@ -263,7 +272,7 @@ while uptime() < deadline do ) end - menu("Select filesystem to show options", filesystems) + menu("Select filesystem", filesystems) end), menuElement("Shutdown", function() @@ -275,7 +284,7 @@ while uptime() < deadline do if internetAddress then tableInsert(utilities, 2, menuElement(stringsBootFromURL, function() - netboot(input(status(NIL, stringsBootFromURL) + 2, "Enter URL: ")) + netboot(input(title(2, stringsBootFromURL), "Enter URL: ")) end)) end @@ -288,6 +297,7 @@ if data:sub(1, 1) == "#" then netboot(data:sub(2, -1)) else proxy = componentProxy(data) + if proxy and proxy.exists(stringsInit) then loadInit(proxy) else @@ -303,28 +313,9 @@ else end if not proxy then - status(NIL, stringsMain, "No bootable mediums found", 1) + status(stringsMain, "No bootable mediums found", 1) end end end shutdown() - - - - - - - - - - - - - - - - - - - diff --git a/EFI/Minified.lua b/EFI/Minified.lua index c72aa1de..17e4d617 100644 --- a/EFI/Minified.lua +++ b/EFI/Minified.lua @@ -1 +1 @@ -local a,b,c,d,e,f,g,h,i,j,k,l,m,n="MineOS EFI","Internet boot","Change label","key_down","/init.lua","filesystem",component.proxy,component.list,computer.pullSignal,computer.uptime,table.insert,math.max,math.min,math.huge;local o,p,q,r,s,t,u,v=1,0,1,1,0,g(h("eeprom")()),g(h("gpu")()),h("internet")()u.bind(h("screen")(),true)local w,x,y,z,A,B,C,D,E,F,G=computer.shutdown,u.set,u.fill,t.setData,t.getData,u.getDepth(),u.getResolution()computer.getBootAddress,computer.setBootAddress=A,z;if B==4 then o,p,q,r,s=0x333333,0xFFFFFF,0x333333,0x333333,0xFFFFFF elseif B==8 then o,p,q,r,s=0x2D2D2D,0xE1E1E1,0x878787,0x878787,0xE1E1E1 end;local H,I,J,K=function(L)if L~=E then u.setBackground(L)E=L end end,function(L)if L~=F then u.setForeground(L)F=L end end,function(M)return math.floor(M+0.5)end,function(N,O,P)if#N1 then ah=ah-1 elseif ak[4]==208 and ah<#af then ah=ah+1 elseif ak[4]==28 then if af[ah].c then af[ah].c()end;if af[ah].b then return end end end end end,function(U,al)local N,am,an,ak,ao="",true;while 1 do an=al..N;y(1,U,C,1," ")x(J(C/2-#an/2),U,an..(am and"█"or""))ak={i(0.5)}if ak[1]==d then if ak[4]==28 then return N elseif ak[4]==14 then N=N:sub(1,-2)else ao=unicode.char(ak[3])if ao:match("^[%w%d%p%s]+")then N=N..ao end end;am=true elseif ak[1]=="clipboard"then N=N..ak[3]elseif not ak[1]then am=not am end end end,function(ap)local aq,aa,ac,ar,ae=function(N)_(G,b,"Internet boot failed: "..N,1)end,"",g(v).request(ap)if ac then _(G,b,"Downloading script...")while 1 do ar,ae=ac.read(n)if ar then aa=aa..ar else ac:close()if ae then aq(ae)else ar,ae=load(aa)if ar then z("#"..ap)ar,ae=pcall(ar)if ar then return else aq(ae)end else aq(ae)end end;break end end else aq("invalid URL-address")end end;_(G,a,"Hold Alt to show boot options menu")local as,ak=j()+1;while j() "or" ")..K(ax,10)..K(a9.spaceTotal()>1048576 and"HDD"or a9.spaceTotal()>65536 and"FDD"or"SYS",3)..K(ay and"R"or"R/W",3)..aw:sub(1,8).." "..K(string.format("%.2f",a9.spaceUsed()/a9.spaceTotal()*100).."%",6,1),function()local az={a5()}if not ay then k(az,1,S(c,function()a9.setLabel(a7(_(G,c)+2,"Enter new name: "))end,1))k(az,2,S("Format",function()_(G,a,"Formatting filesystem "..aw)for aA,aB in ipairs(a9.list("/"))do a9.remove(aB)end;_(G,a,"Formatting finished",1)end,1))end;if a9.exists(e)then k(az,1,S("Set as startup",function()z(aw)end,1))end;a6(ax.." ("..aw..")",az)end,1))end;a6("Select filesystem to show options",au)end),S("Shutdown",function()w()end),a5()}if v then k(at,2,S(b,function()a8(a7(_(G,b)+2,"Enter URL: "))end))end;a6(a,at)end end;local aa,a9=A()if aa:sub(1,1)=="#"then a8(aa:sub(2,-1))else a9=g(aa)if a9 and a9.exists(e)then a4(a9)else for aw in h(f)do a9=g(aw)if a9.exists(e)then z(aw)a4(a9)break else a9=nil end end;if not a9 then _(G,a,"No bootable mediums found",1)end end end;w() \ No newline at end of file +local a,b,c,d,e,f,g,h,i,j,k,l,m,n,o="MineOS EFI","Internet recovery","Change label","key_down","/init.lua","filesystem",component.proxy,component.list,computer.pullSignal,computer.uptime,table.insert,math.max,math.min,math.huge,math.floor;local p,q,r,s,t,u,v,w=1,0,1,1,0,g(h("eeprom")()),g(h("gpu")()),h("internet")()v.bind(h("screen")(),true)local x,z,A,B,C,D,E,F,G,H,I=computer.shutdown,v.set,v.fill,u.setData,u.getData,v.getDepth(),v.getResolution()computer.getBootAddress,computer.setBootAddress=C,B;if D==4 then p,q,r,s,t=0x333333,0xFFFFFF,0x333333,0x333333,0xFFFFFF elseif D==8 then p,q,r,s,t=0x2D2D2D,0xE1E1E1,0x878787,0x878787,0xE1E1E1 end;local J,K,L=function(M)if M~=G then v.setBackground(M)G=M end end,function(M)if M~=H then v.setForeground(M)H=M end end,function(N,O,P)if#N1 then ak=ak-1 elseif am[4]==208 and ak<#ai then ak=ak+1 elseif am[4]==28 then if ai[ak].c then ai[ak].c()end;if ai[ak].b then return end end end end end,function(y,an)local N,ao,ap,am,aq="",true;while 1 do ap=an..N;A(1,y,E,1," ")gpuSetForeground(r)z(o(E/2-#ap/2),y,ap..(ao and"█"or""))am={i(0.5)}if am[1]==d then if am[4]==28 then return N elseif am[4]==14 then N=N:sub(1,-2)else aq=unicode.char(am[3])if aq:match("^[%w%d%p%s]+")then N=N..aq end end;ao=true elseif am[1]=="clipboard"then N=N..am[3]elseif not am[1]then ao=not ao end end end,function(ar)local as,ad,af,at,ah=function(N)a1(b,"Internet boot failed: "..N,1)end,"",g(w).request(ar)if af then a1(b,"Downloading script...")while 1 do at,ah=af.read(n)if at then ad=ad..at else af:close()if ah then as(ah)else at,ah=load(ad)if at then B("#"..ar)at,ah=pcall(at)if at then return else as(ah)end else as(ah)end end;break end end else as("invalid URL-address")end end;a1(a,"Hold Alt to show boot options menu")local au,am=j()+1;while j() "or" ")..L(az,10)..L(ac.spaceTotal()>1048576 and"HDD"or ac.spaceTotal()>65536 and"FDD"or"SYS",3)..L(aA and"R"or"R/W",3)..ay:sub(1,8).." "..L(string.format("%.2f",ac.spaceUsed()/ac.spaceTotal()*100).."%",6,1),function()local aB={a8()}if not aA then k(aB,1,S(c,function()ac.setLabel(aa(Z(2,c),"Enter new name: "))end,1))k(aB,2,S("Format",function()a1(a,"Formatting filesystem "..ay)for aC,aD in ipairs(ac.list("/"))do ac.remove(aD)end;a1(a,"Formatting finished",1)end,1))end;k(aB,1,S("Set as startup",function()B(ay)end,1))a9(az.." ("..ay..")",aB)end,1))end;a9("Select filesystem",aw)end),S("Shutdown",function()x()end),a8()}if w then k(av,2,S(b,function()ab(aa(Z(2,b),"Enter URL: "))end))end;a9(a,av)end end;local ad,ac=C()if ad:sub(1,1)=="#"then ab(ad:sub(2,-1))else ac=g(ad)if ac and ac.exists(e)then a7(ac)else for ay in h(f)do ac=g(ay)if ac.exists(e)then B(ay)a7(ac)break else ac=nil end end;if not ac then a1(a,"No bootable mediums found",1)end end end;x() \ No newline at end of file