{ { text = "{\ [ \"edit.default_extension\" ] = \"lua\",\ [ \"paint.default_extension\" ] = \"nfp\",\ [ \"shell.autocomplete\" ] = true,\ [ \"list.show_hidden\" ] = false,\ [ \"shell.allow_disk_startup\" ] = false,\ [ \"shell.allow_startup\" ] = true,\ [ \"bios.use_multishell\" ] = true,\ [ \"lua.autocomplete\" ] = true,\ [ \"edit.autocomplete\" ] = true,\ }", path = ".settings", }, { text = "--Advanced read API\ --0.8\ \ function read(trm, x,y, xSize, text, char)\ local pointer = 1\ local posS = 1\ local posE = xSize-1\ if text then\ pointer = #text+1\ if #text > xSize then\ posS = #text-xSize+2\ posE = #text\ end\ end\ local text = text or \"\"\ local textCleaner = \"\"\ for i=1,xSize do\ textCleaner = textCleaner..\" \"\ end\ \ local function redrawText()\ \ trm.setCursorPos(x,y)\ trm.write(textCleaner)\ \ local txt = text\ if #text >= xSize-4 then\ txt = string.sub(text, posS, posE)\ end\ trm.setCursorPos(x,y)\ if not char then\ trm.write(txt)\ else\ for i=1, #txt do\ trm.write(char)\ end\ end\ if posS > 1 then\ trm.setCursorPos(x,y)\ trm.write(\"..\")\ end\ if posE < #text then\ trm.setCursorPos(x+xSize-2,y)\ trm.write(\"..\")\ end\ end\ \ redrawText()\ \ while true do\ local ev, sd, mx, my = os.pullEvent()\ -- trm.setCursorPos(x+pointer-posS, y)\ -- trm.setCursorBlink(true)\ if ev == 'key' then\ if sd == keys.enter then\ trm.setCursorBlink(false)\ return text\ elseif sd == keys.backspace and pointer > 1 then\ if pointer > #text then\ text = string.sub(text, 0, #text-1)\ else\ text = string.sub(text, 0, pointer-2)..string.sub(text, pointer, #text)\ end\ pointer = pointer-1\ if x+pointer-posS < x+xSize-3 and posS > 1 then\ posS = posS-1\ if #text < xSize-4 then\ posS = 1\ end\ posE = posS+xSize-2\ end\ elseif sd == keys[\"end\"] then\ pointer = #text + 1\ \ if x+pointer-posS > x+xSize-3 then\ posS = #text-xSize+3\ posE = #text\ end\ elseif sd == keys.home then\ pointer = 1\ \ posS = 1\ posE = xSize-2\ elseif sd == keys.delete then\ if pointer <= #text then\ text = string.sub(text, 0, pointer-1)..string.sub(text, pointer+1, #text)\ if #text < xSize-4 then\ posE = xSize-2\ end\ end\ elseif sd == keys.left then\ if pointer > 1 then\ pointer = pointer - 1\ if x+pointer-posS < x+math.floor(xSize/2) and posS > 1 then\ posS = posS-1\ if #text < xSize-4 then\ posS = 1\ end\ posE = posS+xSize-2\ end\ end\ elseif sd == keys.right then\ if pointer < #text+1 then\ pointer = pointer + 1\ if x+pointer-posS > x+math.floor(xSize/2) then\ posS = posS+1\ posE = posS+xSize-1\ end\ end\ end\ elseif ev == 'char' and sd ~= nil then\ text = string.sub(text, 0, pointer-1)..sd..string.sub(text, pointer, #text)\ pointer = pointer + 1\ if x+pointer-posS > x+xSize-2 then\ posS = posS+1\ posE = posS+xSize-2\ end\ elseif ev == \"paste\" then\ text = text..sd\ pointer = #text + 1\ if #text > xSize then\ posS = #text-xSize+2\ posE = #text\ else\ posS = 1\ posE = #text\ end\ elseif ev == \"mouse_click\" then\ trm.setCursorBlink(false)\ return text\ elseif ev == \"mouse_scroll\" then\ trm.setCursorBlink(false)\ return text\ end\ \ redrawText()\ trm.setCursorPos(x+pointer-posS, y)\ trm.setCursorBlink(true)\ end\ end", path = "System/APIs/advanced_read", }, { text = "--Contexts\ --2.0\ \ local xSize, ySize = term.getSize()\ local comp = false\ \ local function usualText(string,xPos,yPos, trm)\ \009local trm = trm or term\ \009trm.setCursorPos(xPos,yPos)\ \009trm.write(string)\ end\ \ function main(...)\ \009local arg = {...}\ \009local waitFor = true\ \009local x = arg[1]\ \009local y = arg[2]\ \009local color = colors.gray\ \009local textColor = colors.white\ \009local maxLenth = 3\ \009local align = \"center\"\ \009local lenth\ \009local output\ \009local vertical_inverted\ \ \009if type(arg[3]) == \"table\" then\ \009\009if arg[3].color then\ \009\009\009color = arg[3].color\ \009\009end\ \009\009if arg[3].textColor then\ \009\009\009textColor = arg[3].textColor\ \009\009end\ \009\009if arg[3].lenth then\ \009\009\009lenth = arg[3].lenth\ \009\009end\ \009\009if arg[3].minLenth then\ \009\009\009maxLenth = arg[3].minLenth\ \009\009end\ \009\009if arg[3].align then\ \009\009\009align = arg[3].align\ \009\009end\ \009\009if arg[3].verticalInverted then\ \009\009\009vertical_inverted = arg[3].verticalInverted\ \009\009end\ \009\009table.remove(arg, 3)\ \009end\ \ \009if not lenth then\ \009\009for i=3,#arg do\ \009\009\009if #arg[i] > maxLenth then\ \009\009\009\009maxLenth = #arg[i]\ \009\009\009end\ \009\009end\ \009\009maxLenth = maxLenth + 2\ \009else\ \009\009maxLenth = lenth\ \009end\ \ \009local xend = x+maxLenth\ \009local yend = y+#arg-1\ \009if x+maxLenth > xSize then\ \009\009xend = x\ \009\009x = x-maxLenth+1\ \009end\ \009if y+#arg-1 > ySize then\ \009\009yend = y\ \009\009y = y-#arg\ \009\009vertical_inverted = true\ \009end\ \ \009local body = window.create(term.current(),x,y,maxLenth,0)\ \009body.setBackgroundColor(color)\ \009body.setTextColor(textColor)\ \009body.clear()\ \ \009local function drawItem(id)\ \009\009if align == \"center\" then\ \009\009\009usualText(arg[id+2],math.floor((maxLenth)/2)-math.floor(#arg[id+2]/2)+1,id+1, body)\ \009\009elseif align == \"left\" then\ \009\009\009usualText(arg[id+2],2,id+1, body)\ \009\009elseif align == \"right\" then\ \009\009\009usualText(arg[id+2],maxLenth-#arg[id+2],id+1, body)\ \009\009end\ \009end\ \ \009for i=3,#arg do\ \009\009if vertical_inverted then\ \009\009\009body.reposition(x,y+#arg-i,maxLenth,i)\ \009\009else\ \009\009\009body.reposition(x,y,maxLenth,i)\ \009\009end\ \009\009drawItem(i-2)\ \009\009sleep(0)\ \009end\ \ \009while waitFor do\ \009\009event, side, xp, yp = os.pullEvent()\ \009\009if event == 'mouse_click' then\ \009\009\009for i=1,#arg-2 do\ \009\009\009\009if xp >= x and xp <= xend and yp >= y and yp <= yend then\ \009\009\009\009\009if yp == y+i then\ \009\009\009\009\009\009local bk = term.redirect(body)\ \009\009\009\009\009\009paintutils.drawFilledBox(1,i+1,maxLenth,i+1,colors.lightGray)\ \009\009\009\009\009\009term.redirect(bk)\ \009\009\009\009\009\009drawItem(i)\ \009\009\009\009\009\009sleep(0.1)\ \009\009\009\009\009\009output = arg[i+2]\ \009\009\009\009\009\009body.setVisible(false)\ \009\009\009\009\009end\ \009\009\009\009end\ \009\009\009end\ \009\009\009return output\ \009\009end\ \009end\ end", path = "System/APIs/contexts", }, { text = "--Image drawer API\ --1.1\ \ local Colors = {\ [\"0\"] = 1,\ [\"1\"] = 2,\ [\"2\"] = 4,\ [\"3\"] = 8,\ [\"4\"] = 16,\ [\"5\"] = 32,\ [\"6\"] = 64,\ [\"7\"] = 128,\ [\"8\"] = 256,\ [\"9\"] = 512,\ [\"a\"] = 1024,\ [\"b\"] = 2048,\ [\"c\"] = 4096,\ [\"d\"] = 8192,\ [\"e\"] = 16384,\ [\"f\"] = 32768\ }\ \ local function convert(mode,color)\ if mode == \"from cc\" then\ for key,value in pairs(Colors) do\ if color == value then\ return key\ end\ end\ else\ if color == \"#\" then\ return \"0\"\ else\ return Colors[color]\ end\ end\ end\ \ function loadImage(path, format)\ local Pixels = {}\ local file\ if type(path) == \"string\" then\ file = fs.open(path,\"r\")\ else\ file = path\ end\ if file == nil then\ file = fs.open('#SysRes/Images/imgerror.png','r')\ end\ local lineCounter = 1\ while true and file do\ local line = file.readLine()\ Pixels[lineCounter]={}\ if line ~= nil then\ for i=1,#line,3 do\ Pixels[lineCounter][(i+2)/3]={[\"symbol\"] = string.sub(line,i,i),[\"textColor\"] = convert(\"to cc\",string.sub(line,i+1,i+1)),[\"backColor\"] = convert(\"to cc\",string.sub(line,i+2,i+2))}\ end\ lineCounter = lineCounter + 1\ else\ break\ end\ end\ if file then\ file.close()\ end\ \ return Pixels\ end\ \ function draw(image,startX,startY,trm,cutX,cutY, threads)\ if not trm then\ trm = term\ end\ local threads = threads or 16\ \ if type(image) == \"string\" then\ image = loadImage(image)\ elseif type(image) == \"table\" then\ else\ image = loadImage(\"#SysRes/Images/noicon.png\")\ end\ \ if not image or not image[1] then return end\ \ if cutX == nil or cutY == nil then\ cutX = #image[1]\ cutY = #image-1\ else\ if cutY >= #image then cutY = #image-1 end\ if cutX > #image[1] then cutX = #image[1] end\ end\ \ local drawfuncs = {}\ if threads > cutX then\ threads = cutX\ end\ if threads > cutY then\ threads = cutY\ end\ local div = math.floor(math.sqrt(threads))\ \ local verSize = math.floor(cutY/div)\ local horSize = math.floor(cutX/div)\ \ for ver=1,div do\ for hor=1,div do\ table.insert(drawfuncs, function()\ for y=verSize*ver - verSize, verSize*ver do\ if image[y] then\ for x=horSize*hor - horSize, horSize*hor do\ if image[y][x] and image[y][x][\"symbol\"] ~= \"#\" then\ trm.setTextColor(image[y][x][\"textColor\"])\ trm.setBackgroundColor(image[y][x][\"backColor\"])\ trm.setCursorPos(startX+x-1,startY+y-1)\ trm.write(image[y][x][\"symbol\"])\ end\ end\ end\ end\ end)\ end\ end\ \ parallel.waitForAll(unpack(drawfuncs))\ end", path = "System/APIs/images", }, { text = "--ScreenWorks API\ --0.4\ \ local args = {...}\ local xSize, ySize = term.getSize()\ local screens = {}\ \ local function textToTable(text)\ local words = {}\ \009local pos = 1\ \ \009for i = 1, #text do\ if string.sub(text,i,i) == '\\\ ' then\ pos = pos + 1\ words[pos] = '\\\ '\ \009\009elseif string.sub(text,i,i) ~= \" \" then\ \009\009\009if words[pos] == nil then\ \009\009\009\009words[pos] = \"\"\ \009\009\009end\ \009\009\009words[pos] = words[pos]..string.sub(text,i,i)\ \009\009else\ if string.sub(text,i-1,i-1) ~= \" \" then\ \009\009\009 pos = pos + 1\ else\ if words[pos] == nil then\ \009\009\009\009words[pos] = \"\"\ \009\009\009end\ \009\009\009words[pos] = words[pos]..\" \"\ end\ \009\009end\ \009end\ return words\ end\ \ local function printText(trm, text, x, y, size, align, color)\ if color then\ trm.setTextColor(color)\ end\ if not text then\ text = \"\"\ end\ \ local words = textToTable(text)\ if not words then\ words = {\"\"}\ elseif not words[1] then\ words[1] = \"\"\ end\ local lines = {}\ local pos = x+#words[1]\ local elms = 1\ \ lines[1] = words[1]..\" \"\ for i=2, #words do\ if words[i] == \"\\n\" or words[i] == \"\\\ \" then\ elms = elms + 1\ lines[elms] = \"\"\ pos = x\ elseif words[i] then\ pos = pos + #words[i]\ if pos <= size+x-1 then\ lines[elms] = lines[elms]..words[i]..\" \"\ pos = pos+1\ else\ lines[elms] = string.sub(lines[elms],1,#lines[elms]-1)\ elms = elms + 1\ lines[elms] = words[i]..\" \"\ pos = x + #words[i]\ end\ end\ end\ \ lines[#lines] = string.sub(lines[#lines],1,#lines[#lines]-1)\ \ if align == 'justify' then\ local dim = size+2\ for i=1,#lines do\ if #lines[i] < dim-3 and #lines[i] > math.floor(dim/2 + dim/5) then\ local j = 1\ local space = 0\ while j < #lines[i] and #lines[i] <= dim-3 do\ if j < #lines[i] and string.sub(lines[i],j,j) == ' ' then\ lines[i] = string.sub(lines[i],1,j)..string.sub(lines[i],j,#lines[i])\ j = j + 3 + space\ else\ j = j + 1\ end\ if j >= #lines[i] then\ j = 1\ space = space + 1\ end\ end\ end\ end\ end\ \ for i=1, #lines do\ for j=x,size+x-1 do\ trm.setCursorPos(j,i+y-1)\ trm.write(\" \")\ end\ if align == 'center' then\ trm.setCursorPos(math.floor(size/2-#lines[i]/2)+x,i+y-1)\ elseif align == 'right' then\ trm.setCursorPos(size-#lines[i]+x,i+y-1)\ else\ trm.setCursorPos(x,i+y-1)\ end\ trm.write(lines[i])\ end\ return elms\ end\ \ local startInput = os.advancedRead\ \ function newScreen(textColor, backgroundColor, headerTextColor, headerColor, header, act, _X, _Y, _SizeX, _SizeY, _HeaderSizeY)\ local obj = {}\ \ local _HeaderSizeY = _HeaderSizeY or 2\ local _X = _X or 1\ local _Y = _Y or 1\ local _SizeX = _SizeX or xSize\ local _SizeY = _SizeY or ySize-_HeaderSizeY\ \ obj.header = window.create(term.current(), _X, _Y, _SizeX, _HeaderSizeY)\ obj.background = window.create(term.current(), _X, _Y + _HeaderSizeY, _SizeX, _SizeY)\ obj.body = window.create(obj.background, 1, 1, _SizeX-1, _SizeY)\ \ obj.scroller = window.create(obj.background, _SizeX, 1, 1, _SizeY)\ obj.scrollerB = window.create(obj.scroller, 1, 1, 1, _SizeY)\ \ local steping = 0\ local scr_size\ obj.buttons = {}\ \ obj.setActive = function(state)\ local state = state or false\ obj.active = state\ obj.header.setVisible(state)\ obj.background.setVisible(state)\ obj.body.setVisible(state)\ obj.scroller.setVisible(state)\ end\ \ if act == nil then\ obj.active = true\ else\ obj.setActive(act)\ end\ \ obj.redraw = function()\ obj.background.redraw()\ obj.body.redraw()\ obj.header.redraw()\ obj.scroller.redraw()\ end\ \ obj.remove = function()\ for i=1, #screens do\ if screens[i] == obj then\ table.remove(screens, i)\ break\ end\ end\ \ obj.header.setVisible(false)\ obj.body.setVisible(false)\ obj.scroller.setVisible(false)\ \ obj.header = nil\ obj.body = nil\ obj.scroller = nil\ \ obj = nil\ end\ \ local function drawMenuDot()\ obj.header.setCursorPos(xSize-5,1)\ obj.header.write(\" ... \")\ end\ \ local function drawBackBtn()\ obj.header.setCursorPos(1,1)\ obj.header.write(\" < \")\ obj.header.setCursorPos(1,2)\ obj.header.write(\" \")\ end\ \ obj.createMenu = function(...)\ local args = {...}\ obj.header.hasMenu = true\ drawMenuDot()\ os.loadAPI(\"#API/contexts\")\ \ local menu = {}\ menu.check = function(x,y)\ if obj.active and y >= 1 and y <= 2 and x >= xSize-5 and x <= xSize-1 then\ return true\ end\ end\ \ menu.open = function()\ obj.header.setBackgroundColor(colors.gray)\ obj.header.setTextColor(colors.white)\ drawMenuDot()\ local answer = contexts.main(xSize-1,2,unpack(args))\ obj.header.setBackgroundColor(headerColor)\ obj.header.setTextColor(headerTextColor)\ drawMenuDot()\ obj.redraw()\ return answer\ end\ \ return menu\ end\ \ obj.createBackBtn = function()\ obj.header.hasBackBtn = true\ drawBackBtn()\ \ local btn = {}\ btn.check = function(x,y)\ if obj.active and y >= 1 and y <= 2 and x >= 1 and x <= 3 then\ obj.header.setBackgroundColor(colors.gray)\ obj.header.setTextColor(colors.lightGray)\ drawBackBtn()\ sleep(0)\ obj.header.setBackgroundColor(headerColor)\ obj.header.setTextColor(headerTextColor)\ drawBackBtn()\ return true\ end\ end\ \ return btn\ end\ \ obj.scrollPos = 1\ obj.scroll = function(n)\ local xPos, yPos = obj.body.getPosition()\ local sizeX, sizeY = obj.body.getSize()\ local xx, yy = obj.scrollerB.getPosition()\ if sizeY >= _SizeY+1 then\ if n > 0 and yPos < 1 then\ obj.body.reposition(1,yPos+n)\ obj.scroller.clear()\ obj.scrollPos = obj.scrollPos-steping*n\ if obj.scrollPos < 1 then\ obj.scrollPos = 1\ end\ if obj.scrollPos > _SizeY-scr_size+1 then\ obj.scrollPos = _SizeY-scr_size+1\ end\ obj.scrollerB.reposition(1,math.ceil(obj.scrollPos))\ -- if obj.scrollPos > _SizeY+1-scr_size then\ -- obj.scrollerB.reposition(1,_SizeY+1-scr_size)\ -- obj.scrollPos = _SizeY+1-scr_size\ -- end\ -- if yPos+n > 1 then\ -- obj.body.reposition(1,1)\ -- end\ elseif n < 0 and yPos+sizeY > _SizeY+1 then\ obj.body.reposition(1,yPos+n)\ obj.scroller.clear()\ obj.scrollPos = obj.scrollPos-steping*n\ if obj.scrollPos < 1 then\ obj.scrollPos = 1\ end\ if obj.scrollPos > ySize-scr_size-1 then\ obj.scrollPos = ySize-scr_size-1\ end\ obj.scrollerB.reposition(1,math.ceil(obj.scrollPos))\ -- if obj.scrollPos < 1 then\ -- obj.scrollerB.reposition(1,1)\ -- obj.scrollPos = 1\ -- end\ -- if yPos+n+sizeY < _SizeY then\ -- obj.body.reposition(1,yPos+sizeY)\ -- end\ end\ -- obj.header.redraw()\ end\ end\ \ obj.resize = function(size)\ local xPos, yPos = obj.body.getPosition()\ local cX, cY = obj.body.getSize()\ if size >= cY then\ obj.body.reposition(xPos,yPos,_SizeX-1 ,size)\ else\ obj.body.reposition(1,1,_SizeX-1,size)\ obj.scrollerB.reposition(1,1)\ end\ local xx, yy = obj.scrollerB.getPosition()\ obj.scroller.reposition(_SizeX,1)\ obj.scroller.clear()\ \ scr_size = math.floor((_SizeY)/size * (_SizeY))\ steping = ((_SizeY))/(size-1)\ \ obj.scrollerB.reposition(1,yy,1,scr_size)\ end\ \ obj.setHeader = function(text)\ header = text\ obj.header.setTextColor(headerTextColor)\ obj.header.setBackgroundColor(headerColor)\ obj.header.clear()\ obj.header.setCursorPos(math.floor(xSize/2)-math.floor(#tostring(header))/2+1,math.floor(_HeaderSizeY/2))\ obj.header.write(header)\ if obj.header.hasMenu then\ drawMenuDot()\ end\ if obj.header.hasBackBtn then\ drawBackBtn()\ end\ end\ \ obj.writeLine = function(text, x,y, color, trm)\ if not trm or (trm ~= obj.body and trm ~= obj.header) then\ trm = obj.body\ end\ if not text then\ text = \"\"\ end\ \ if not color then\ trm.setTextColor(textColor)\ else\ trm.setTextColor(color)\ end\ trm.setCursorPos(x,y)\ trm.write(text)\ end\ \ obj.writeText = function(text, x,y, size, align, color)\ if not color then\ color = textColor\ end\ return printText(obj.body, text, x, y, size, align, color)\ end\ \ obj.drawImage = function(x,y, path, sizeX,sizeY, threads)\ local img = {}\ img.x = x\ img.y = y\ \ if not sizeX or not sizeY then\ sizeX, sizeY = os.getImageSize(path)\ end\ \ img.body = window.create(obj.body, x,y, sizeX,sizeY)\ img.body.setBackgroundColor(backgroundColor)\ img.body.clear()\ \ os.drawImage(path, 1,1, img.body, sizeX, sizeY, threads)\ \ img.setPosition = function(nx,ny)\ img.x = nx\ img.y = ny\ img.body.reposition(nx, ny)\ obj.redraw()\ end\ \ return img\ end\ \ obj.newButton = function(x,y, sizeX, sizeY, textColor, backgroundColor, text, align)\ \ local btn = {}\ \ btn.body = window.create(obj.body, x,y, sizeX,sizeY)\ btn.x = x\ btn.y = y\ \ local function wrtText()\ if text then\ if not align then\ align = \"center\"\ end\ \ if align == \"center\" then\ btn.body.setCursorPos(math.floor(sizeX/2)-math.floor(#text/2)+1,math.floor(sizeY/2)+1)\ elseif align == \"left\" then\ btn.body.setCursorPos(1,math.floor(sizeY/2)+1)\ elseif align == \"right\" then\ btn.body.setCursorPos(sizeX-#text+1,math.floor(sizeY/2)+1)\ end\ btn.body.write(text)\ end\ end\ \ local anim\ local function animate()\ local xPos, yPos = obj.body.getPosition()\ local xPos2, yPos2 = obj.background.getPosition()\ anim = window.create(term.current(),x+xPos+xPos2-2,y+yPos+yPos2-2,sizeX,sizeY)\ anim.setBackgroundColor(colors.lightGray)\ anim.clear()\ sleep(0)\ anim.setVisible(false)\ anim.reposition(0,0,0,0)\ btn.body.clear()\ obj.body.redraw()\ obj.header.redraw()\ wrtText()\ end\ \ btn.body.setBackgroundColor(backgroundColor)\ btn.body.clear()\ btn.body.setTextColor(textColor)\ wrtText()\ \ btn.check = function(nx,ny, anime)\ if anime == nil then\ anime = true\ end\ local xPos, yPos = obj.body.getPosition()\ local xPos2, yPos2 = obj.background.getPosition()\ if obj.active and nx >= btn.x+xPos+xPos2-2 and nx <= btn.x+sizeX+xPos+xPos2-3 and ny-yPos-yPos2+2 >= btn.y and ny-yPos-yPos2+2 <= btn.y+sizeY-1 then\ if anime then\ animate()\ end\ return true\ end\ end\ return btn\ end\ \ obj.newDropDownList = function(x,y,size, values, default, txtColor, backColor1, backColor2)\ local menu = {}\ os.loadAPI(\"#API/contexts\")\ local txtColor = txtColor or headerTextColor\ local backColor1 = backColor1 or colors.lightGray\ local backColor2 = backColor2 or colors.gray\ local default = default or \"\"\ local size = size or 12\ \ menu.x = x\ menu.y = y\ menu.opened = false\ \ menu.values = values\ \ if type(default) == \"number\" then\ default = values[default]\ end\ menu.selected = default\ \ menu.body = window.create(obj.body, x,y, size,1)\ menu.body.setBackgroundColor(backColor1)\ menu.body.setTextColor(txtColor)\ menu.body.clear()\ \ local function redraw()\ menu.body.setBackgroundColor(backColor1)\ menu.body.setTextColor(txtColor)\ menu.body.clear()\ menu.body.setCursorPos(2,1)\ menu.body.write(menu.selected)\ menu.body.setCursorPos(size-2,1)\ if not menu.opened then\ menu.body.setTextColor(backColor2)\ else\ menu.body.setTextColor(backColor1)\ menu.body.write(\" \"..string.char(7)..\" \")\ sleep(0.1)\ menu.body.setCursorPos(size-2,1)\ menu.body.setBackgroundColor(backColor2)\ end\ menu.body.write(\" \"..string.char(7)..\" \")\ end\ redraw()\ \ menu.set = function(val)\ if type(val) == \"number\" and menu.values[val] then\ menu.selected = menu.values[val]\ elseif type(val) == \"string\" then\ menu.selected = val\ end\ redraw()\ end\ \ menu.open = function()\ menu.opened = true\ redraw()\ local xPos, yPos = obj.body.getPosition()\ local xPos2, yPos2 = obj.background.getPosition()\ local yp, xp = menu.y + yPos + yPos2 - 2, menu.x + xPos + xPos2 - 2\ local inv\ if #menu.values+2 + yp > ySize then\ yp = yp - (#menu.values+2)\ inv = true\ else\ yp = yp + 1\ end\ local answer = contexts.main(xp ,yp ,{color = backColor2, lenth = size, align = \"left\", verticalInverted = inv}, unpack(menu.values))\ obj.redraw()\ if answer then\ menu.selected = answer\ end\ menu.opened = false\ redraw()\ return answer\ end\ \ menu.check = function(nx,ny)\ local xPos, yPos = obj.body.getPosition()\ local xPos2, yPos2 = obj.background.getPosition()\ if obj.active and nx >= menu.x+xPos+xPos2-2 and nx <= menu.x+size+xPos+xPos2-3 and ny-yPos-yPos2+2 == menu.y then\ return true\ end\ end\ \ return menu\ end\ \ obj.newSwitch = function(x,y,color,state)\ if not color then\ color = headerColor\ end\ if not state then\ state = false\ end\ local switch = {}\ local bColor = colors.gray\ local offColor = colors.lightGray\ if backgroundColor == bColor then\ bColor = colors.lightGray\ offColor = colors.white\ end\ \ local size = 6\ \ switch.x = x\ switch.y = y\ switch.body = window.create(obj.body,x,y,size,1)\ switch.body.setBackgroundColor(bColor)\ switch.body.clear()\ switch.state = state\ \ switch.getState = function()\ return switch.state\ end\ \ switch.toggle = function()\ switch.body.setBackgroundColor(bColor)\ switch.body.clear()\ if switch.state then\ switch.state = false\ switch.body.setCursorPos(1,1)\ switch.body.setBackgroundColor(offColor)\ else\ switch.state = true\ switch.body.setCursorPos(math.floor(size/2)+1,1)\ switch.body.setBackgroundColor(color)\ end\ switch.body.write(\" \")\ end\ \ switch.toggle()\ switch.toggle()\ \ switch.check = function(nx,ny)\ local xPos, yPos = obj.body.getPosition()\ local xPos2, yPos2 = obj.background.getPosition()\ if obj.active and nx >= switch.x+xPos+xPos2-2 and nx <= switch.x+size+xPos+xPos2-3 and ny-yPos-yPos2+2 == switch.y then\ switch.toggle()\ return true\ end\ end\ \ return switch\ end\ \ obj.newRange = function(x,y,size,default,color)\ local range = {}\ range.body = window.create(obj.body,x,y,size,1)\ range.body.setBackgroundColor(backgroundColor)\ range.body.clear()\ range.x = x\ range.y = y\ \ if not default then\ default = 50\ end\ \ range.percent = default\ local pos = math.floor(size*range.percent/100)+1\ if pos > size then\ pos = size\ end\ \ if not color then\ color = headerColor\ end\ \ local function redraw()\ range.body.setTextColor(color)\ \ for i=1,pos do\ range.body.setCursorPos(i,1)\ range.body.write(string.char(140))\ end\ \ -- range.body.setBackgroundColor(color)\ range.body.setCursorPos(pos,1)\ range.body.write(string.char(8))\ -- range.body.setBackgroundColor(backgroundColor)\ \ range.body.setTextColor(colors.lightGray)\ for i=pos+1,size do\ range.body.setCursorPos(i,1)\ range.body.write(string.char(140))\ end\ end\ \ redraw()\ \ range.set = function(per)\ range.percent = per\ pos = math.floor(size*range.percent/100)+1\ if pos > size then\ pos = size\ end\ redraw()\ end\ \ range.check = function(nx,ny)\ local xPos, yPos = obj.body.getPosition()\ local xPos2, yPos2 = obj.background.getPosition()\ if obj.active and nx >= range.x+xPos+xPos2-2 and nx <= range.x+size+xPos+xPos2-3 and ny-yPos-yPos2+2 == range.y then\ range.percent = (nx-xPos+1-range.x)/size*100\ if range.percent < 50 then\ range.percent = math.ceil((nx-xPos+1-range.x)/size*100)\ elseif range.percent > 50 then\ range.percent = math.floor((nx-xPos+2-range.x)/size*100)\ end\ pos = math.floor(size*range.percent/100)+1\ \ if pos > size then\ pos = size\ end\ redraw()\ return true\ end\ end\ \ return range\ end\ \ obj.newRadioSet = function(x,y, texts, default, size, txColor)\ if not default then\ default = 1\ end\ \ local radio = {}\ radio.selectedNum = default\ radio.x = x\ radio.y = y\ radio.selected = texts[default]\ \ if not size then\ size = 0\ for i=1,#texts do\ if #texts[i] > size then\ size = #texts[i]\ end\ end\ size = size+2\ end\ \ radio.body = window.create(obj.body,x,y,size,#texts*2-1)\ radio.body.setBackgroundColor(backgroundColor)\ radio.body.clear()\ \ local function redraw()\ for i=1,#texts do\ radio.body.setTextColor(txColor or textColor)\ radio.body.setCursorPos(1,i*2-1)\ radio.body.write(texts[i])\ radio.body.setCursorPos(size,i*2-1)\ radio.body.setTextColor(textColor)\ radio.body.write(string.char(186))\ end\ radio.body.setTextColor(headerColor)\ radio.body.setCursorPos(size,radio.selectedNum*2-1)\ radio.body.write(string.char(7))\ end\ \ redraw()\ \ radio.check = function(nx,ny)\ local xPos, yPos = obj.body.getPosition()\ local xPos2, yPos2 = obj.background.getPosition()\ if obj.active and nx >= radio.x+xPos+xPos2-2 and nx <= radio.x+size+xPos+xPos2-3 and ny-yPos-yPos2+2 >= radio.y and ny-yPos-yPos2+2 <= radio.y+#texts*2-2 then\ radio.selectedNum = math.floor((ny-yPos-yPos2+2-radio.y+1)/2)+1\ radio.selected = texts[radio.selectedNum]\ redraw()\ return true\ end\ end\ \ radio.set = function(num)\ local num = num or default\ if type(num) == \"string\" then\ for i=1, #texts do\ if texts[i] == num then\ radio.selectedNum = i\ radio.selected = texts[i]\ break\ end\ end\ elseif type(num) == \"number\" then\ radio.selectedNum = num\ radio.selected = texts[num]\ end\ redraw()\ end\ \ return radio\ end\ \ obj.newProgressBar = function(x,y,size,default,color, waiting)\ if not default then\ default = 0\ end\ local bar = {}\ bar.waiting = waiting\ bar.percent = default\ bar.body = window.create(obj.body,x,y,size,1)\ bar.x = x\ bar.y = y\ \ local pos = math.floor(size*bar.percent/100)\ if pos > size then\ pos = size\ end\ \ if not color then\ color = headerColor\ end\ \ bar.body.setBackgroundColor(backgroundColor)\ bar.body.clear()\ local function redraw()\ bar.body.setTextColor(color)\ \ for i=1,pos do\ bar.body.setCursorPos(i,1)\ bar.body.write(string.char(140))\ end\ \ bar.body.setTextColor(colors.lightGray)\ \ if bar.waiting then\ for i=1,pos-math.floor(size/2.5) do\ bar.body.setCursorPos(i,1)\ bar.body.write(string.char(140))\ end\ end\ \ for i=pos+1,size do\ bar.body.setCursorPos(i,1)\ bar.body.write(string.char(140))\ end\ end\ \ redraw()\ \ bar.setPercent = function(n)\ if n >= 0 and ((n <= 100) or (n <= 142 and bar.waiting)) then\ bar.percent = n\ pos = math.floor(size*bar.percent/100)\ redraw()\ end\ end\ \ return bar\ end\ \ obj.newInput = function(x,y,size,default,description, align,char, slim)\ local input = {}\ local align = align or \"left\"\ local size = size or 12\ local sizeY = (not slim and 3) or 1\ input.body = window.create(obj.body,x,y,size,sizeY)\ input.x = x\ input.y = y\ \ --[[if backgroundColor == colors.lightGray then\ input.body.setBackgroundColor(colors.white)\ else\ input.body.setBackgroundColor(backgroundColor)\ end]]\ input.body.setBackgroundColor(textColor)\ input.body.setTextColor(backgroundColor)\ \ local default = tostring(default) or \"\"\ local description = description\ input.text = default\ \ local function redraw()\ input.body.clear()\ if align == \"left\" then\ input.body.setCursorPos(2,math.floor((sizeY+1)/2))\ elseif align == \"center\" then\ input.body.setCursorPos(math.floor(size/2) - math.floor(#tostring(input.text)/2)+1,math.floor((sizeY+1)/2))\ elseif align == \"right\" then\ input.body.setCursorPos(math.floor(size - #tostring(input.text)),math.floor((sizeY+1)/2))\ end\ if char and input.text ~= default then\ for i=1,#input.text do\ input.body.write(char)\ end\ elseif input.text ~= \"\" then\ input.body.write(input.text)\ else\ -- input.body.setTextColor(colors.gray)\ input.body.write(description)\ -- input.body.setTextColor(backgroundColor)\ end\ if #input.text > size-1 then\ input.body.setCursorPos(size-2,math.floor((sizeY+1)/2))\ input.body.write(\".. \")\ end\ end\ \ redraw()\ \ input.set = function(txt)\ input.text = tostring(txt) or \"\"\ redraw()\ end\ \ input.check = function(nx,ny)\ local xPos, yPos = obj.body.getPosition()\ local xPos2, yPos2 = obj.background.getPosition()\ if obj.active and nx >= input.x+xPos+xPos2-2 and nx <= input.x+size+xPos+xPos2-3 and ny-yPos-yPos2+2 >= input.y and ny-yPos-yPos2+2 <= input.y+sizeY-1 then\ input.body.setCursorPos(input.x+1,math.floor((sizeY+1)/2))\ input.body.clear()\ input.body.setBackgroundColor(textColor)\ input.body.setTextColor(backgroundColor)\ local bt = term.redirect(input.body)\ input.text = startInput(input.body, 2, math.floor((sizeY+1)/2), size-2, input.text, char) --read(char)\ term.redirect(bt)\ redraw()\ return true\ end\ end\ \ return input\ end\ \ -- obj.header.setTextColor(headerTextColor)\ -- obj.header.setBackgroundColor(headerColor)\ -- obj.header.clear()\ -- obj.header.write(\" \"..header)\ obj.setHeader(header)\ \ obj.body.setTextColor(textColor)\ obj.body.setBackgroundColor(backgroundColor)\ obj.body.clear()\ \ if backgroundColor == colors.lightGray then\ obj.scroller.setBackgroundColor(colors.white)\ else\ obj.scroller.setBackgroundColor(colors.lightGray)\ end\ obj.scroller.clear()\ \ obj.scrollerB.setBackgroundColor(backgroundColor)\ obj.scrollerB.clear()\ \ table.insert(screens, obj)\ return obj\ end\ \ \ -------------------------------------------------------------------\ ---------------------------DIALOGS--------------------------------\ \ local function createDialog(header, text, size)\ local dialog = newScreen(colors.gray, colors.white, colors.white, colors.gray, \"\", true, -1, -1, 2, 0, 0)\ dialog.opened = false\ dialog.active = false\ dialog.header.setVisible(false)\ dialog.header.reposition(-1,-1,0,0)\ \ if not text then text = \" \" end\ if not header then header = \" \" end\ if not size then size = 0 end\ \ local sizeX = 28\ local posX = math.floor(xSize/2)-math.floor(sizeX/2)+1\ \ local linesNum = printText(dialog.header, text, 2, 4, sizeX-2, \"center\", colors.gray)\ if linesNum < 1 then\ linesNum = 1\ end\ local sizeY = 5+linesNum+size\ dialog.background.reposition(posX, -sizeY, sizeX, sizeY)\ dialog.body.reposition(1, 1, sizeX, sizeY)\ \ os.drawImage(\"#SysRes/Images/dialog_top.png\",1,1, dialog.body)\ dialog.body.setCursorPos(math.floor(sizeX/2)-math.floor(#header/2), 2)\ dialog.body.setTextColor(colors.white)\ dialog.body.write(header)\ for i=1,sizeY-1 do\ os.drawImage(\"#SysRes/Images/dialog_middle.png\",1,3+i, dialog.body)\ end\ os.drawImage(\"#SysRes/Images/dialog_bottom.png\",1,sizeY-1, dialog.body)\ \ \ dialog.body.setBackgroundColor(colors.white)\ printText(dialog.body, text, 2, 4, sizeX-2, \"center\", colors.gray)\ \ dialog.pos = posX\ dialog.sizeX = sizeX\ dialog.sizeY = sizeY\ \ return dialog\ end\ \ local function showDialog(diag)\ diag.opened = true\ diag.active = true\ for i=1,math.floor(diag.sizeY/2) do\ diag.background.reposition(diag.pos, -diag.sizeY+i*2+1)\ sleep(0)\ end\ diag.background.reposition(diag.pos, 1)\ end\ \ local function closeDialog(diag)\ diag.opened = false\ diag.active = false\ for i=1,math.floor(diag.sizeY/2)+1 do\ term.current().redraw()\ for i,scr in ipairs(screens) do\ if scr.active then\ scr.redraw()\ end\ end\ diag.background.reposition(diag.pos, -i*2-1)\ -- sleep(0)\ end\ end\ \ local function animate(trm, x,y, txt)\ trm.setCursorPos(x,y)\ trm.setTextColor(colors.white)\ trm.setBackgroundColor(colors.gray)\ trm.write(\" \"..txt..\" \")\ sleep(0.1)\ trm.setCursorPos(x,y)\ trm.setTextColor(colors.gray)\ trm.setBackgroundColor(colors.white)\ trm.write(\" \"..txt..\" \")\ end\ \ \ \ function alert(header, text)\ local dialog = createDialog(header, text)\ \ local okbtn = dialog.newButton(dialog.sizeX-5,dialog.sizeY,4,1, colors.gray,colors.white, \"ok\")\ \ dialog.close = function()\ if dialog.opened then\ closeDialog(dialog)\ end\ end\ \ dialog.show = function()\ if not dialog.opened then\ showDialog(dialog)\ while true do\ local event, side, x, y = os.pullEvent()\ if event == \"mouse_click\" then\ if okbtn.check(x,y) then\ dialog.close()\ break\ end\ end\ end\ end\ end\ \ return dialog\ end\ \ function select(header, text, btn1, btn2, cancel)\ local dialog = createDialog(header, text)\ \ local btn_1 = dialog.newButton(dialog.sizeX-#tostring(btn1)-#tostring(btn2)-6,dialog.sizeY,#tostring(btn1)+2,1, colors.gray,colors.white, btn1)\ local btn_2 = dialog.newButton(dialog.sizeX-#tostring(btn2)-3,dialog.sizeY,#tostring(btn2)+2,1, colors.gray,colors.white, btn2)\ if cancel then\ btn_cancel = dialog.newButton(3,dialog.sizeY,3,1, colors.gray,colors.white, \"x\")\ end\ \ dialog.close = function()\ if dialog.opened then\ closeDialog(dialog)\ end\ end\ \ dialog.show = function()\ if not dialog.opened then\ showDialog(dialog)\ while true do\ local event, side, x, y = os.pullEvent()\ if event == \"mouse_click\" then\ if btn_1.check(x,y) then\ dialog.close()\ return btn1\ elseif btn_2.check(x,y) then\ dialog.close()\ return btn2\ elseif btn_cancel.check(x,y) then\ dialog.close()\ break\ end\ end\ end\ end\ end\ \ return dialog\ end\ \ function inputDialog(header, text, btn1, btn2, cancel, ...)\ local fields = {...}\ local inputs = {}\ local dialog = createDialog(header, text, #fields*2)\ \ local btn_1 = dialog.newButton(dialog.sizeX-#tostring(btn1)-#tostring(btn2)-6,dialog.sizeY,#tostring(btn1)+2,1, colors.gray,colors.white, btn1)\ local btn_2 = dialog.newButton(dialog.sizeX-#tostring(btn2)-3,dialog.sizeY,#tostring(btn2)+2,1, colors.gray,colors.white, btn2)\ if cancel then\ btn_cancel = dialog.newButton(3,dialog.sizeY,3,1, colors.gray,colors.white, \"x\")\ end\ \ for i,field in ipairs(fields) do\ table.insert(inputs, dialog.newInput(3,dialog.sizeY-#fields*2+i*2-2,dialog.sizeX-4,\"\",field,nil,nil,true))\ end\ \ dialog.close = function()\ if dialog.opened then\ closeDialog(dialog)\ end\ end\ \ dialog.getInputData = function()\ local out = {}\ for i,inp in ipairs(inputs) do\ out[fields[i]] = inp.text\ end\ \ return out\ end\ \ dialog.show = function()\ if not dialog.opened then\ showDialog(dialog)\ while true do\ local event, side, x, y = os.pullEvent()\ if event == \"mouse_click\" then\ if btn_1.check(x,y) then\ dialog.close()\ return btn1, dialog.getInputData()\ elseif btn_2.check(x,y) then\ dialog.close()\ return btn2, dialog.getInputData()\ elseif btn_cancel.check(x,y) then\ dialog.close()\ break\ else\ for i,inp in ipairs(inputs) do\ if inp.check(x,y) then\ break\ end\ end\ end\ end\ end\ end\ end\ \ return dialog\ end\ \ function getName()\ return name\ end\ \ function getVersion()\ return version\ end", path = "System/APIs/screenworks", }, { text = " 90 90 90 90 90 90\ 90\14700\14090\14090\14700 90\ 90 90O90S90 90 90\ 90 90 90 90 90 90", path = "System/Apps/Launcher/App.ico", }, { text = "{\ name = \"Simple Launcher\",\ version = \"0.2\",\ developer = \"DECE\",\ hidden = true,\ }", path = "System/Apps/Launcher/App.info", }, { text = "os.printLog(\"Running\")\ \ local xSize, ySize = term.getSize()\ local selector = 1\ \ local clear = function(color)\ \009term.setBackgroundColor(color)\ \009term.clear()\ \009term.setCursorPos(1,1)\ end\ \ local text = function(string,xPos,yPos)\ \009term.setCursorPos(xPos,yPos)\ \009term.write(string)\ end\ \ local about = fs.open(shell.resolve(\"App.info\"), \"r\")\ about = textutils.unserialize(about.readAll())\ \ local apps = os.getAppsList()\ local appsInfo = {}\ for i,app in ipairs(apps) do\ \009appsInfo[i] = os.getAppInfo(app)\ end\ \ local function redraw()\ clear(colors.white)\ \ for i=1,#apps do\ \009\009if i == selector then\ \009\009\009term.setTextColor(colors.cyan)\ \009\009else\ \009\009\009term.setTextColor(colors.lightGray)\ \009\009end\ \009\009-- appInfo = os.getAppInfo(apps[i])\ \009\009if appsInfo[i] and appsInfo[i].name then\ \009text(i..' '..appsInfo[i].name,2,i+1)\ \009\009else\ \009\009\009text(i..' '..apps[i],2,i+1)\ \009\009end\ end\ \ \009term.setTextColor(colors.lightGray)\ text(about.name..\" v\"..about.version,2,ySize)\ end\ \ redraw()\ \ while true do\ \009local event, side, x, y = os.pullEvent()\ \ \009if event == \"char\" then\ \009\009if side >= '1' and side <= '9' then\ \009\009\009os.runApp(apps[tonumber(side)])\ \009\009elseif side == \"r\" then\ \009\009\009apps = os.getAppsList()\ \009\009\009appsInfo = {}\ \009\009\009for i,app in ipairs(apps) do\ \009\009\009\009appsInfo[i] = os.getAppInfo(app)\ \009\009\009end\ \009\009\009redraw()\ \009\009end\ \009elseif event == \"key\" then\ \009\009if side == keys.up and selector > 1 then\ \009\009\009selector = selector - 1\ \009\009\009redraw()\ \009\009elseif side == keys.down and selector < #apps then\ \009\009\009selector = selector + 1\ \009\009\009redraw()\ \009\009elseif side == keys.enter then\ \009\009\009os.runApp(apps[tonumber(selector)])\ \009\009end\ \009elseif event == \"mouse_click\" then\ \009\009os.runApp(apps[tonumber(selector)])\ \009elseif event == \"mouse_scroll\" then\ \009\009if side == -1 and selector > 1 then\ \009\009\009selector = selector - 1\ \009\009\009redraw()\ \009\009elseif side == 1 and selector < #apps then\ \009\009\009selector = selector + 1\ \009\009\009redraw()\ \009\009end\ \009end\ \ --redraw()\ end", path = "System/Apps/Launcher/Start.x", }, { text = " 90 90 90 90 90 90\ 90\14700\14090\14090\14700 90\ 90 90O90S90 90 90\ 90 90 90 90 90 90", path = "System/Apps/LegacyUI/App.ico", }, { text = "{\ name = \"Legacy UI\",\ version = \"0.1\",\ developer = \"DECE\",\ hidden = true,\ }", path = "System/Apps/LegacyUI/App.info", }, { text = "local xSize, ySize = term.getSize()\ local centerX = math.floor(xSize/2)\ local centerY = math.floor(ySize/2)\ \ local showApps = false\ local showNoti = false\ \ local show_float_noti = false\ local float_timer = 0\ local float_timer_limit = os.getFloatingTime()/os.getSystemDelay()\ \ local notifications = {}\ \ local first = term.current()\ local origin = window.create(term.native(),1,1,xSize,ySize)\ local currentTask\ \ local recApps = window.create(origin,centerX-14,1,30,ySize-1)\ local recApps_scroll = window.create(recApps,3,1,26,5)\ recApps_scroll.setBackgroundColor(colors.black)\ recApps_scroll.clear()\ recApps.setVisible(false)\ \ local btn_animation = window.create(term.native(),-1,-1,1,1)\ btn_animation.setTextColor(colors.lightGray)\ \ local noti_screen = window.create(term.native(),xSize+1,1,20,ySize)\ local noti_screen_background = window.create(noti_screen,1,1,20,ySize-3)\ local noti_screen_scroll = window.create(noti_screen_background,1,1,20,ySize-3)\ \ local float_noti_window = window.create(term.native(),xSize+1,ySize-6,20,5)\ float_noti_window.setVisible(false)\ \ local errorBuffer\ local tasks = os.getRunningTasks()\ coroutine.yield(1, 1, xSize, ySize-1)\ \ \ \ local clear = function(color)\ \009term.setBackgroundColor(color)\ \009term.clear()\ \009term.setCursorPos(1,1)\ end\ \ local text = function(string,xPos,yPos,trm)\ \009if not trm then\ \009\009trm = term\ \009end\ \009trm.setCursorPos(xPos,yPos)\ \009trm.write(string)\ end\ \ \ local function redrawNotifications()\ local pos\ noti_screen_scroll.reposition(1,1, 20, ySize-3)\ noti_screen_scroll.clear()\ \009local sizeX, sizeY = noti_screen_scroll.getSize()\ \009local posX, posY = noti_screen_scroll.getPosition()\ \009notifications = os.getNotifications()\ \ for i, noti in ipairs(notifications) do\ if noti then\ pos = i*5-4\ \ if pos + 4 > sizeY then\ noti_screen_scroll.reposition(posX, posY, sizeX, pos+5)\ end\ \ noti_screen_scroll.setBackgroundColor(colors.lightGray)\ noti_screen_scroll.setTextColor(colors.gray)\ noti_screen_scroll.setCursorPos(1,pos)\ noti_screen_scroll.write(\" \")\ noti_screen_scroll.setCursorPos(1,pos)\ noti_screen_scroll.write(\" \"..noti.icon..\" \"..noti.header)\ noti_screen_scroll.setCursorPos(20,pos)\ noti_screen_scroll.write(\"x\")\ \ noti_screen_scroll.setBackgroundColor(colors.gray)\ noti_screen_scroll.setTextColor(colors.lightGray)\ noti_screen_scroll.setCursorPos(2,pos+2)\ noti_screen_scroll.write(noti.text)\ noti_screen_scroll.setCursorPos(2,pos+3)\ noti_screen_scroll.write(noti.text2)\ end\ end\ os.applyColorPalette(currentPalette)\ end\ \ local function removeNotification(num)\ \009notifications = os.getNotifications()\ if notifications[num] then\ os.printLog(\"Removing notification #\"..num, \"SystemUI\")\ os.removeNotification(num)\ end\ end\ \ local function clearNotifications()\ \009os.printLog(\"Clearing notifications\", \"SystemUI\")\ os.clearNotifications()\ \009local posX, posY = noti_screen_scroll.getPosition()\ \009if #notifications > 0 then\ \009\009local sizeX, sizeY = noti_screen_scroll.getSize()\ \009\009for i=1, sizeX/3+1 do\ \009\009\009noti_screen_background.clear()\ \009\009\009noti_screen_scroll.reposition(i*3, posY)\ \009\009\009sleep(0)\ \009\009end\ \009end\ \009redrawNotifications()\ \009noti_screen_scroll.reposition(posX, posY)\ end\ \ term.redirect(noti_screen_background)\ clear(colors.gray)\ term.redirect(noti_screen_scroll)\ clear(colors.gray)\ term.redirect(noti_screen)\ clear(colors.gray)\ term.setTextColor(colors.lightGray)\ text(\"Clear\",2,ySize-1)\ \ \ local function drawBar()\ \009term.redirect(origin)\ \009local barText = --[[string.char(17)..\" \"..string.char(7)..\" \"..]]string.char(140)\ \009local clr = colors.black\ \009local tx_clr = colors.lightGray\ \ \009if tasks[currentTask] and not showApps then\ \009\009if tasks[currentTask].style then\ \009\009\009clr = tasks[currentTask].style\ \009\009\009if tasks[currentTask].style >= colors.orange and tasks[currentTask].style <= colors.red then\ \009\009\009\009tx_clr = colors.white\ \009\009\009end\ \009\009end\ \009end\ \ \009if showNoti then\ \009\009paintutils.drawLine(5,ySize,xSize-20,ySize,clr)\ \009\009paintutils.drawLine(xSize-19,ySize,xSize,ySize,colors.gray)\ \009else\ \009\009paintutils.drawLine(5,ySize,xSize-2,ySize,clr)\ \009end\ \ \009term.setTextColor(tx_clr)\ \009if not show_float_noti then\ \009\009text(string.char(7)..\" \",xSize-1,ySize)\ \009elseif not showNoti then\ \009\009text(string.char(19)..\" \",xSize-1,ySize)\ \009end\ \ \009term.setBackgroundColor(clr)\ \009text(\" \"..barText..\" \",1,ySize)\ \009if currentTask > 1 then\ \009\009text(string.char(30),4,ySize)\ \009end\ \009time = textutils.formatTime(os.time(),true)\ \009text(time,centerX-#time/2+2,ySize)\ end\ \ local function animate(x1,y1,x2,y2, color, redrTerm)\ btn_animation.reposition(x1,y1,x2,y2)\ \009os.applyColorPalette(currentPalette)\ if color then\ btn_animation.setBackgroundColor(color)\ else\ btn_animation.setBackgroundColor(colors.gray)\ end\ btn_animation.clear()\ sleep(0.1)\ btn_animation.reposition(-1,-1)\ \009os.applyColorPalette(currentPalette)\ \009local redrTerm = redrTerm or origin\ redrTerm.redraw()\ \009if not showApps and not showNoti and tasks[currentTask] then\ \009\009tasks[currentTask].screen.redraw()\ \009\009os.applyColorPalette(currentPalette)\ \009end\ end\ \ local function openNoti()\ \009setDidState(true)\ \009if show_float_noti then\ \009\009show_float_noti = false\ \009\009float_timer = 0\ \009\009float_noti_window.reposition(xSize+1,ySize-6)\ \009\009float_noti_window.setVisible(false)\ \009end\ \009for i=1,5 do\ \009\009noti_screen.reposition(xSize-i*4+1,1)\ \009\009os.applyColorPalette(currentPalette)\ \009\009sleep(0)\ \009end\ \009showNoti = true\ end\ \ local function closeNoti()\ \009showNoti = false\ \009drawBar()\ \009for i=1,7 do\ \009\009origin.redraw()\ \009\009if not showApps and tasks[currentTask] then\ \009\009\009tasks[currentTask].screen.redraw()\ \009\009end\ \009\009noti_screen.reposition(xSize-19+i*3,1)\ \009\009os.applyColorPalette(currentPalette)\ \009\009sleep(0)\ \009end\ \009setDidState(false)\ end\ \ local function redrawTasks()\ \009tasks = os.getRunningTasks()\ \009currentTask = os.getCurrentTask()\ \ \009local pos\ \009local sizeX, sizeY = recApps_scroll.getSize()\ \009local posX, posY = recApps_scroll.getPosition()\ \ \009recApps_scroll.setBackgroundColor(colors.black)\ \009recApps_scroll.clear()\ \ \009recApps_scroll.reposition(posX,1,sizeX,#tasks*5)\ \ \009for i=1,#tasks do\ \009\009-- tasks[i] = tasks[i+1]\ \ \009\009pos = i*5-3\ \009\009term.redirect(recApps_scroll)\ \ \009\009paintutils.drawFilledBox(1,pos,26,pos+3,colors.white)\ \009\009recApps_scroll.setTextColor(colors.lightGray)\ \009\009text(tasks[i].name,8,pos+1,recApps_scroll)\ \ \009\009if i > 1 then\ \009\009\009paintutils.drawFilledBox(24,pos,26,pos+3,colors.red)\ \009\009\009recApps_scroll.setTextColor(colors.white)\ \009\009\009text(\"x\",25,pos+1,recApps_scroll)\ \009\009end\ \ \009\009os.drawImage(os.getAppIcon(tasks[i].path),1,pos,recApps_scroll,6,4)\ \ \009\009-- recApps_scroll.reposition(posX,1,sizeX,sizeY-5)\ \009end\ end\ \ local function openShowApps()\ \009setDidState(true)\ \009redrawTasks()\ \009os.applyColorPalette(currentPalette)\ \009os.printLog(\"Trying to open Recent apps\", \"SystemUI\")\ \ \009tasks = os.getRunningTasks()\ \009currentTask = os.getCurrentTask()\ \ \009for i=1,#tasks do\ \009\009tasks[i].screen.setVisible(false)\ \009end\ \ \009recApps.setVisible(true)\ \009tasks[currentTask].screen.setVisible(true)\ \009drawBar()\ \ \009for i=1,math.floor(ySize/3) do\ \009\009recApps.redraw()\ \009\009tasks[currentTask].screen.reposition(1,ySize-(ySize-i*3+1))\ \009\009drawBar()\ \009\009sleep(0)\ \009end\ \009tasks[currentTask].screen.reposition(1,ySize+1)\ \009showApps = true\ \009recApps.redraw()\ \009drawBar()\ \009os.applyColorPalette(currentPalette)\ end\ \ local function changeApp(name)\ tasks = os.getRunningTasks()\ currentTask = os.getCurrentTask()\ \ \009if tasks[name] then\ \009\009recApps.setVisible(false)\ \009\009drawBar()\ \009\009tasks[name].screen.reposition(1,ySize+1)\ \009\009tasks[name].screen.setVisible(true)\ \ \009\009for i=1,math.floor(ySize/4) do\ \009\009\009tasks[name].screen.reposition(1,ySize-i*4+1)\ \009\009\009drawBar()\ \009\009\009sleep(0)\ \009\009end\ \ \009\009tasks[name].screen.reposition(1,1)\ \009\009drawBar()\ \009\009showApps = false\ \009\009showNoti = false\ \009end\ \009setDidState(false)\ \009drawBar()\ end\ \ local function closeApp(name)\ \009redrawTasks()\ \ \009if not showApps or #tasks == 1 then\ \009\009showApps = false\ \009\009os.changeApp(1)\ \009\009os.printLog(\"Open Launcher\", \"SystemUI\")\ \009end\ end\ \ local function runApp(info, args)\ \009redrawTasks()\ \ \009local error\ \009local path = info.path\ \009local findApp = info.access\ \009local name = info.name\ \ \009if findApp ~= nil then\ \009\009term.redirect(origin)\ \009\009if tasks[currentTask].coroutine and not error then\ \009\009\009local pos = #tasks*5-3\ \009\009\009local sizeX, sizeY = recApps_scroll.getSize()\ \009\009\009local posX, posY = recApps_scroll.getPosition()\ \ \009\009\009if pos + 4 > sizeY then\ \009\009\009\009if (pos+4) >= ySize-1 then\ \009\009\009\009\009recApps_scroll.reposition(posX,posY+(ySize-(pos+4)-1),sizeX,pos+4)\ \009\009\009\009else\ \009\009\009\009\009recApps_scroll.reposition(posX,1,sizeX,pos+4)\ \009\009\009\009end\ \009\009\009end\ \009\009\009term.redirect(recApps_scroll)\ \ \009\009\009paintutils.drawFilledBox(1,pos,26,pos+3,colors.white)\ \009\009\009recApps_scroll.setTextColor(colors.lightGray)\ \009\009\009text(tasks[currentTask].name,8,pos+1,recApps_scroll)\ \ \009\009\009if currentTask > 1 then\ \009\009\009\009paintutils.drawFilledBox(24,pos,26,pos+3,colors.red)\ \009\009\009\009recApps_scroll.setTextColor(colors.white)\ \009\009\009\009text(\"x\",25,pos+1,recApps_scroll)\ \009\009\009end\ \ \009\009\009os.drawImage(os.getAppIcon(tasks[currentTask].path),1,pos,recApps_scroll,6,4)\ \009\009\009recApps_scroll.setBackgroundColor(colors.black)\ \009\009\009drawBar()\ \009\009end\ \009end\ end\ \ local function input()\ \009os.printLog(\"Started\", \"SystemUI\")\ while true do\ local event, side, x, y, z = os.pullEvent()\ tasks = os.getRunningTasks()\ currentTask = os.getCurrentTask()\ \ \009\009if show_float_noti and os.getFloatingEnabled() then\ \009\009\009float_noti_window.redraw()\ \009\009\009if float_timer > float_timer_limit then\ \009\009\009\009show_float_noti = false\ \009\009\009\009float_timer = 0\ \009\009\009\009local xp, yp = float_noti_window.getPosition()\ \009\009\009\009for i=1,3 do\ \009\009\009\009\009if showApps then\ \009\009\009\009\009\009first.redraw()\ \009\009\009\009\009\009recApps.redraw()\ \009\009\009\009\009else\ \009\009\009\009\009\009tasks[currentTask].screen.redraw()\ \009\009\009\009\009end\ \009\009\009\009\009float_noti_window.reposition(xp, ySize-6+i*2+1)\ \009\009\009\009\009sleep(0)\ \009\009\009\009end\ \009\009\009\009float_noti_window.setVisible(false)\ \009\009\009else\ \009\009\009\009float_timer = float_timer + 1\ \009\009\009end\ \009\009elseif show_float_noti then\ \009\009\009if float_timer > float_timer_limit then\ \009\009\009\009show_float_noti = false\ \009\009\009\009float_timer = 0\ \009\009\009else\ \009\009\009\009float_timer = float_timer + 1\ \009\009\009end\ \009\009end\ \009\009drawBar()\ \ \009\009errorBuffer = os.getErrorBuffer()\ \009\009if errorBuffer then\ \009\009\009local errMsg = screenworks.alert(\"Error in \"..errorBuffer.app, errorBuffer.error)\ \009\009\009errMsg.show()\ \009\009\009if errorBuffer.app == \"System UI\" then\ \009\009\009\009os.reboot()\ \009\009\009end\ \009\009\009errorBuffer = nil\ \009\009\009os.clearErrorBuffer()\ \009\009end\ \ \009\009if event == \"system.closeApp\" then\ \009\009\009closeApp(side)\ \009\009elseif event == \"system.runApp\" then\ \009\009\009runApp(side, x)\ \009\009elseif event == \"system.changeApp\" then\ \009\009\009changeApp(side)\ \009\009elseif event == \"system.sendNotification\" or event == \"system.removeNotification\" or event == \"system.clearNotifications\" then\ \009\009\009redrawNotifications()\ \009\009\009float_timer_limit = os.getFloatingTime()/os.getSystemDelay()\ \009\009\009show_float_noti = true\ \009\009\009float_timer = 0\ \009\009\009drawBar()\ \009\009\009if event == \"system.sendNotification\" and not showNoti and os.getFloatingEnabled() then\ \009\009\009\009float_noti_window.setBackgroundColor(colors.gray)\ \009\009\009\009float_noti_window.clear()\ \ \009\009\009\009float_noti_window.setTextColor(colors.lightGray)\ \009\009\009\009float_noti_window.setCursorPos(2,3)\ \009\009\009\009float_noti_window.write(side.text)\ \009\009\009\009float_noti_window.setCursorPos(2,4)\ \009\009\009\009float_noti_window.write(side.text2)\ \ \009\009\009\009float_noti_window.setBackgroundColor(colors.lightGray)\ \009 float_noti_window.setTextColor(colors.gray)\ \009 float_noti_window.setCursorPos(1,1)\ \009 float_noti_window.write(\" \")\ \009 float_noti_window.setCursorPos(1,1)\ \009 float_noti_window.write(\" \"..side.icon..\" \"..side.header)\ \ \009\009\009\009float_noti_window.setVisible(true)\ \009\009\009\009for i=1,5 do\ \009\009\009\009\009float_noti_window.reposition(xSize-i*4+1,ySize-6)\ \009\009\009\009\009sleep(0)\ \009\009\009\009end\ \009\009\009end\ \009\009elseif event == \"mouse_click\" then\ if y == ySize then\ \009\009\009\009coroutine.yield(true)\ if x >= xSize-1 and x <= xSize then\ animate(xSize-2,ySize,3,1)\ if showNoti then\ closeNoti()\ else\ openNoti()\ end\ elseif x >= 1 and x <= 2 then\ animate(1,ySize,3,1)\ \009\009\009\009\009if showNoti then\ \009\009\009\009\009\009closeNoti()\ \009\009\009\009\009end\ if tasks[currentTask] and not showApps then\ openShowApps()\ \009\009\009\009\009elseif showApps then\ \009\009\009\009\009\009os.changeApp(currentTask)\ end\ \009\009\009\009elseif currentTask > 1 and x >= 4 and x <= 5 then\ \009\009\009\009\009animate(3,ySize,3,1)\ \009\009\009\009\009if showNoti then\ \009\009\009\009\009\009closeNoti()\ \009\009\009\009\009end\ \009\009\009\009\009os.changeApp(1)\ end\ \009\009\009elseif showNoti then\ \009\009\009\009if x >= xSize - 19 and y < ySize then\ \009\009\009\009\009local posX, posY = noti_screen_scroll.getPosition()\ \009\009\009\009\009local notiNum = math.floor((y-posY+5)/5)\ \ \009\009\009\009\009if x == xSize and (y-posY+5)%5 == 0 then\ \009\009\009\009\009\009removeNotification(notiNum)\ \009\009\009\009\009elseif x >= xSize-19 and x <= xSize-13 and y == ySize-1 then\ \009\009\009\009\009\009animate(xSize-19,ySize-1,7,1, colors.lightGray, noti_screen)\ \009\009\009\009\009\009clearNotifications()\ \009\009\009\009\009\009closeNoti()\ \009\009\009\009\009elseif notiNum and #notifications > 0 and notifications[notiNum] then\ \009\009\009\009\009\009os.runApp(notifications[notiNum].app)\ \009\009\009\009\009\009removeNotification(notiNum)\ \009\009\009\009\009\009closeNoti()\ \009\009\009\009\009end\ \009\009\009\009else\ \009\009\009\009\009closeNoti()\ \009\009\009\009end\ \009\009\009else\ \009\009\009\009if showApps and not showNoti then\ \009\009\009\009\009local posX, posY = recApps_scroll.getPosition()\ \009\009\009\009\009local app = math.floor((y-posY+4)/5)\ \ \009\009\009\009\009if x>=centerX-12 and x<=centerX+10 then\ \009\009\009\009\009\009if app > 0 and app <= #tasks then\ \009\009\009\009\009\009\009os.changeApp(app)\ \009\009\009\009\009\009end\ \009\009\009\009\009elseif x >= centerX+11 and x <= centerX+13 then\ \009\009\009\009\009\009if app > 1 and app <= #tasks then\ \009\009\009\009\009\009\009os.closeApp(app)\ \009\009\009\009\009\009end\ \009\009\009\009\009end\ \009\009\009\009end\ end\ \009\009elseif event == \"mouse_drag\" and y == ySize and x < centerX-3 and not showNoti then\ \009\009\009coroutine.yield(true)\ \009\009\009animate(centerX-5,ySize,13,1)\ \009\009\009if currentTask < #tasks then\ \009\009\009\009os.changeApp(currentTask + 1)\ \009\009\009elseif currentTask ~= 1 then\ \009\009\009\009os.changeApp(1)\ \009\009\009end\ \009\009elseif event == \"mouse_drag\" and y == ySize and x > centerX+4 and not showNoti then\ \009\009\009coroutine.yield(true)\ \009\009\009animate(centerX-5,ySize,13,1)\ \009\009\009if currentTask > 1 then\ \009\009\009\009os.changeApp(currentTask - 1)\ \009\009\009elseif currentTask ~= #tasks then\ \009\009\009\009os.changeApp(#tasks)\ \009\009\009end\ \009\009elseif event == \"mouse_scroll\" and showNoti then\ \009\009\009local posX, posY = noti_screen_scroll.getPosition()\ \009\009\009local sx, sy = noti_screen_scroll.getSize()\ \009\009\009if side == 1 and posY > -(sy - ySize) then\ \009\009\009\009noti_screen_scroll.reposition(posX,posY-1)\ \009\009\009elseif side == -1 and posY < 1 then\ \009\009\009\009noti_screen_scroll.reposition(posX,posY+1)\ \009\009\009end\ \009\009\009os.applyColorPalette(currentPalette)\ \009\009elseif event == \"mouse_scroll\" and showApps then\ \009\009\009local posX, posY = recApps_scroll.getPosition()\ \009\009\009local sx, sy = recApps_scroll.getSize()\ \009\009\009if side == 1 and posY > -(sy - ySize) then\ \009\009\009\009recApps_scroll.reposition(posX,posY-1)\ \009\009\009elseif side == -1 and posY < 1 then\ \009\009\009\009recApps_scroll.reposition(posX,posY+1)\ \009\009\009end\ \009\009\009os.applyColorPalette(currentPalette)\ end\ end\ end\ \ input()", path = "System/Apps/LegacyUI/Start.x", }, { text = " 90 90 90 90 90 90\ 90\14700\14090\14090\14700 90\ 90 90O90S90 90 90\ 90 90 90 90 90 90", path = "System/Apps/NotificationsDemo/App.ico", }, { text = "{\ name = \"Notification Demo\",\ version = \"1.0\",\ developer = \"DECE\",\ }", path = "System/Apps/NotificationsDemo/App.info", }, { text = "local xSize, ySize = term.getSize()\ os.loadAPI(\"#API/screenworks\")\ \ os.setBarColor(colors.white)\ \ local screen = screenworks.newScreen(colors.lightGray,colors.white, colors.white,colors.cyan, \"Notification Demo\")\ \ local textFieldHeader = screen.newInput(2, 2, xSize-3, \"\", \"Notification header\")\ local textField1 = screen.newInput(2, 6, xSize-3, \"\", \"Notification line 1\")\ local textField2 = screen.newInput(2, 10, xSize-3, \"\", \"Notification line 2\")\ \ local btnSend = screen.newButton(math.floor(xSize/2)-9, 14, 19, 3, colors.white, colors.gray, \"Send notification\", \"center\")\ \ if ySize-3 < 17 then\ \009screen.resize(17)\ end\ \ while true do\ \009local event, side, x, y = os.pullEvent()\ \ \009if event == \"mouse_click\" then\ \009\009if btnSend.check(x,y) then\ \009\009\009os.sendNotification(nil, textFieldHeader.text, textField1.text, textField2.text)\ \009\009elseif textFieldHeader.check(x,y) or textField1.check(x,y) or textField2.check(x,y) then\ \009\009end\ \009elseif event == \"mouse_scroll\" then\ \009\009screen.scroll(-side)\ \009end\ \ end", path = "System/Apps/NotificationsDemo/Start.x", }, { text = "{\ name = \"Packet Manager\",\ version = \"0.1\",\ developer = \"DECE\",\ hidden = true,\ }", path = "System/Apps/PacketManager/App.info", }, { text = "local args = {...}\ os.loadAPI(\"#API/screenworks\")\ \ local screen = screenworks.newScreen(colors.black, colors.white, colors.cyan, colors.white, \"Packet Manager\")\ local xSize, ySize = screen.body.getSize()\ \ local function getPackInfo(path)\ local file = fs.open(path, \"r\")\ if file then\ local info = file.readAll()\ info = textutils.unserialize(info)\ file.close()\ \ return info\ end\ end\ \ local function unpackApp(packInfo)\ local Massiv = packInfo.files\ local progressBar = screen.newProgressBar(xSize/4+2, ySize/2+3, xSize/2, 0, colors.cyan)\ local path = \"/User/Apps/\"..packInfo.path\ \009for i=1,#Massiv do\ \009\009if Massiv[i][\"text\"] == \"@empty@empty\" then\ \009\009\009fs.makeDir(path..\"/\"..Massiv[i][\"path\"])\ \009\009else\ \009\009\009local file = fs.open(path..\"/\"..Massiv[i][\"path\"],\"w\")\ \009\009\009file.write(Massiv[i][\"text\"])\ \009\009\009file.close()\ \009\009end\ progressBar.setPercent((i/#Massiv)*100)\ sleep(0)\ \009end\ local file = fs.open(path..\"/\"..\"App.info\", \"w\")\ file.write(textutils.serialize(packInfo.info))\ file.close()\ end\ \ local function packApp(path, output, name)\ local file = fs.open(path..\"/App.info\", \"r\")\ \ if file then\ local info = file.readAll()\ info = textutils.unserialize(info)\ file.close()\ \ local progressBar = screen.newProgressBar(xSize/4+2, ySize/2+3, xSize/2, 0, colors.cyan)\ \ local out = {}\ out.info = info\ \ local Massiv2 = {}\ local function FileList(path, fPath)\ local Massiv = fs.list(path)\ if #Massiv==0 then\ local Massiv2Id = #Massiv2 + 1\ Massiv2[Massiv2Id] = {}\ Massiv2[Massiv2Id][\"path\"] = path\ Massiv2[Massiv2Id][\"text\"] = \"@empty@empty\"\ else\ for i=1,#Massiv do\ if fs.isDir(path..\"/\"..Massiv[i]) and Massiv[i] ~= \"/rom\" and Massiv[i] ~= \"rom\" and Massiv[i] ~= \"Data\" then\ FileList(path..\"/\"..Massiv[i], fPath..\"/\"..Massiv[i])\ elseif not fs.isDir(path..\"/\"..Massiv[i]) and Massiv[i] ~= \"/rom\" and Massiv[i] ~= \"rom\" and Massiv[i] ~= \"App.info\" then\ local Massiv2Id = #Massiv2 + 1\ Massiv2[Massiv2Id] = {}\ Massiv2[Massiv2Id][\"path\"] = fPath..\"/\"..Massiv[i]\ local file = fs.open(path..\"/\"..Massiv[i],\"r\")\ Massiv2[Massiv2Id][\"text\"] = file.readAll()\ file.close()\ end\ progressBar.setPercent((i/#Massiv)*100)\ sleep(0)\ end\ end\ end\ FileList(path, \"\")\ \ out.files = Massiv2\ out.path = name\ \ file=fs.open(output..\"/\"..name..\".lca\",\"w\")\ file.write(textutils.serialise(out))\ file.close()\ end\ end\ \ local function getAppInfo(packInfo)\ return packInfo.info\ end\ \ if not args[1] then\ screen.writeText(\"Unknown command\", 1,ySize/3+1, xSize, \"center\")\ elseif string.lower(args[1]) == \"install\" and args[2] then\ screen.setHeader(\"Installing app\")\ \ local pack = getPackInfo(args[2])\ local info = pack and getAppInfo(pack)\ \ if fs.exists(args[2]) and pack and info then\ screen.writeText(\"\"..info.name, 1,ySize/3+1, xSize, \"center\")\ screen.writeText(\"Version: \"..info.version, 1,ySize/3+2, xSize, \"center\", colors.lightGray)\ unpackApp(pack)\ screen.writeText(\"Complete\", 1,ySize/2+3, xSize, \"center\", colors.cyan)\ else\ screen.writeText(\"Packet not found\", 1,ySize/3+1, xSize, \"center\")\ end\ \ elseif string.lower(args[1]) == \"create\" and args[2] and args[3] and args[4] then\ screen.setHeader(\"Creating app packet\")\ \ if fs.exists(args[2]) then\ screen.writeText(\"\"..args[4], 1, ySize/3+1, xSize, \"center\")\ packApp(args[2], args[3], args[4])\ screen.writeText(\"Complete\", 1,ySize/2+3, xSize, \"center\", colors.cyan)\ else\ screen.writeText(\"Project not found\", 1,ySize/3+1, xSize, \"center\")\ end\ \ elseif string.lower(args[1]) == \"remove\" and args[2] then\ screen.setHeader(\"Removing app\")\ \ if fs.exists(\"/User/Apps/\"..args[2]) then\ local app = os.getAppInfo(args[2])\ screen.writeText(\"\"..app.name, 1,ySize/3+1, xSize, \"center\")\ screen.writeText(\"Version: \"..app.version, 1,ySize/3+2, xSize, \"center\", colors.lightGray)\ fs.delete(\"/User/Apps/\"..args[2])\ screen.writeText(\"Complete\", 1,ySize/2+3, xSize, \"center\", colors.cyan)\ else\ screen.writeText(\"App not found\", 1,ySize/3+1, xSize, \"center\")\ end\ \ else\ screen.writeText(\"Unknown command\", 1,ySize/3+1, xSize, \"center\")\ end\ \ local exitBtn = screen.newButton(xSize-6, ySize-1, 6, 1, colors.cyan, colors.white, \"Exit\")\ \ while true do\ local event, side, x, y = os.pullEvent()\ if event == \"mouse_click\" then\ if exitBtn.check(x,y) then\ break\ end\ end\ end", path = "System/Apps/PacketManager/Start.x", }, { text = " 90 90 90 90 90 90\ 90\14700\14090\14090\14700 90\ 90 90O90S90 90 90\ 90 90 90 90 90 90", path = "System/Apps/ScreenworcksDemo/App.ico", }, { text = "{\ name = \"ScreenWorks Demo\",\ version = \"1.0\",\ developer = \"DECE\",\ }", path = "System/Apps/ScreenworcksDemo/App.info", }, { text = "local xSize, ySize = term.getSize()\ os.loadAPI(\"/System/APIs/screenworks\")\ \ os.setBarColor(colors.white)\ \ local startPos = math.floor(xSize/2)-11\ \ local screen = screenworks.newScreen(colors.lightGray,colors.white, colors.white,colors.cyan, \"ScreenWorks Demo\")\ \ screen.writeText(\"This is testing text box with align and other comfortable things...\",startPos,2,24,\"justify\")\ screen.writeText(\"This is testing text box with center align and cyan color...\",startPos,6,24,\"center\",colors.cyan)\ screen.writeText(\"This is testing text box with right align...\",startPos,10,24,\"right\")\ \ screen.writeLine(\"Type something here:\",startPos,13)\ local input = screen.newInput(startPos,14,24,\"\", \"Input field\")\ \ screen.resize(42)\ \ screen.writeLine(\"Drag this range:\",startPos,18)\ local range = screen.newRange(startPos,19,24)\ screen.writeText(range.percent..\"%\",startPos+1,20,24,\"center\")\ \ local btn1 = screen.newButton(startPos,22,8,3,colors.white,colors.gray,\"Button\")\ local btnDialog = screen.newButton(startPos, 29, 24, 3, colors.white,colors.cyan,\"Show dialog\")\ local radio1 = screen.newRadioSet(startPos+10,22, {\"Animate\", \"Not animate\"})\ \ local dropDownList = screen.newDropDownList(startPos, 33, 24, {\"test1\", \"Long test\", \"2x Long long test\", \"3x Long long long test\", \"Another test\", \"And another one\"}, \"Drop-down list\")\ \ screen.writeLine(\"Simple progress bar:\",startPos,26)\ local progress = screen.newProgressBar(startPos,27,24)\ \ local alert = screenworks.select(\"Test dialog\", \"Test dialog message and Some Other Words\", \"Yes\", \"No\", true)\ \ local animate = true\ \ while true do\ local event, side, x, y = os.pullEvent()\ if event == \"mouse_click\" then\ if btn1.check(x,y,animate) then\ if progress.percent < 100 then\ for i=1,range.percent/5 do\ progress.setPercent(progress.percent+5)\ sleep(0)\ end\ else\ progress.setPercent(0)\ end\ elseif radio1.check(x,y) then\ if radio1.selected == \"Animate\" then\ animate = true\ elseif radio1.selected == \"Not animate\" then\ animate = false\ end\ elseif input.check(x,y) then\ elseif dropDownList.check(x,y) then\ -- local alr = screenworks.alert(\"Test alert\", \"You Pressed \")\ -- alr.show()\ dropDownList.open()\ elseif btnDialog.check(x,y) then\ -- local msg = alert.show()\ -- local alr = screenworks.alert(\"Test alert\", \"You Pressed \"..(msg or \"none\"))\ -- alr.show()\ local inp = screenworks.inputDialog(\"Input\",\"Test text\", \"Yes\", \"No\", false, \"Field1\", \"Field2\")\ local btn, data = inp.show()\ local alr = screenworks.alert(\"Test alert\", \"You Pressed \"..(btn or \"none\")..\" \"..data.Field1)\ alr.show()\ end\ elseif event == \"mouse_drag\" then\ range.check(x,y)\ screen.writeText(range.percent..\"%\",startPos+1,20,24,\"center\")\ elseif event == \"mouse_scroll\" then\ screen.scroll(-side)\ end\ end", path = "System/Apps/ScreenworcksDemo/Start.x", }, { text = "{\ name = \"Script runner\",\ version = \"0.1\",\ developer = \"DECE\",\ hidden = true,\ }", path = "System/Apps/ScriptRunner/App.info", }, { text = "local args = {...}\ \ local xSize, ySize = term.getSize()\ \ term.setBackgroundColor(colors.black)\ term.setTextColor(colors.white)\ term.clear()\ term.setCursorPos(1,1)\ \ local path = args[1]\ local scriptArgs\ \ local function strToTable(str)\ local tbl = {}\ local wrd = \"\"\ for i=1,#str do\ local chr = string.sub(str,i,i)\ if chr == \" \" then\ tbl[#tbl+1] = wrd\ wrd = \"\"\ else\ wrd = wrd..chr\ end\ end\ tbl[#tbl+1] = wrd\ return tbl\ end\ \ local function execute(path, args)\ local errors = os.run(os.getEnvironment(), path, args and unpack(args))\ \ term.setBackgroundColor(colors.black)\ term.setTextColor(colors.white)\ term.setCursorPos(xSize,ySize)\ print(\"\")\ print(\"Execution completed\")\ if errors then\ print(\"\")\ term.setTextColor(colors.red)\ print(\"Error: \"..errors)\ end\ \ while true do\ local event = os.pullEvent()\ if event == \"key\" or event == \"mouse_click\" or event == \"suspend\" then\ break\ end\ end\ end\ \ if path then\ \ if #args > 1 then\ scriptArgs = {}\ for i=1, #args do\ scriptArgs[#scriptArgs+1] = args[i]\ end\ end\ \ execute(path, scriptArgs)\ else\ local text\ while not text or #text < 1 or text ~= {} do\ print(\"Input script path and arguments:\")\ term.setCursorPos(2,2)\ text = strToTable(read())\ local path = text[1]\ if path then\ if #text > 1 then\ scriptArgs = {}\ for i=1, #text do\ scriptArgs[#scriptArgs+1] = text[i]\ end\ end\ \ execute(path, scriptArgs)\ break\ end\ end\ end", path = "System/Apps/ScriptRunner/Start.x", }, { text = " 90 90 90 90 90 90\ 90\14700\14090\14090\14700 90\ 90 90O90S90 90 90\ 90 90 90 90 90 90", path = "System/Apps/Settings/App.ico", }, { text = "{\ name = \"Settings\",\ version = \"0.1\",\ developer = \"DECE\",\ }", path = "System/Apps/Settings/App.info", }, { text = "local xSize, ySize = term.getSize()\ os.loadAPI(\"/System/APIs/screenworks\")\ \ local clear = function(color)\ \009term.setBackgroundColor(color)\ \009term.clear()\ \009term.setCursorPos(1,1)\ end\ \ local text = function(string,xPos,yPos)\ \009term.setCursorPos(xPos,yPos)\ \009term.write(string)\ end\ \ clear(colors.white)\ \ local about = fs.open(\"/System/Build.info\", \"r\")\ about = textutils.unserialize(about.readAll())\ \ local osver = about.OSversion\ local build = about.build\ local build_date = about.build_date\ \ local screen = screenworks.newScreen(colors.lightGray,colors.white, colors.white,colors.cyan, about.name..\" OS\", nil, nil, nil, nil, nil, 8)\ local backBtn = screen.createBackBtn()\ \ if ySize-3 < 17 then\ \009screen.resize(9)\ end\ \ -- btn_os = screen.newButton(1,-1,xSize,7, colors.white,colors.cyan, about.name..\" OS\")\ \ screen.writeLine(\"Computer label: \",2,2)\ screen.writeLine(\"Computer ID: \",2,3)\ screen.writeLine(\"OS version: \",2,5)\ screen.writeLine(\"Build name: \",2,7)\ screen.writeLine(\"Build date: \",2,8)\ \ screen.writeLine(os.getComputerLabel() or \"not set\",xSize-#(os.getComputerLabel() or \"not set\")-1,2)\ screen.writeLine(os.getComputerID(),xSize-#tostring(os.getComputerID())-1,3)\ screen.writeLine(osver,xSize-#osver-1,5)\ screen.writeLine(build,xSize-#build-1,7)\ screen.writeLine(build_date,xSize-#build_date-1,8)\ \ while true do\ \009local event, side, x, y = os.pullEvent()\ \ \009if event == \"mouse_click\" then\ \009\009if backBtn.check(x,y) then\ \009\009\009screen.remove()\ \009\009\009break\ \009\009end\ \009elseif event == \"mouse_scroll\" then\ \009\009screen.scroll(-side)\ \009end\ \ end", path = "System/Apps/Settings/Resources/about.x", }, { text = "local xSize, ySize = term.getSize()\ os.loadAPI(\"/System/APIs/screenworks\")\ \ local screen = screenworks.newScreen(colors.lightGray,colors.white, colors.lightGray,colors.white, \"Create account\")\ // local backBtn = screen.createBackBtn()\ local btn_cancel = screen.newButton(2,ySize-3,8,1,colors.white,colors.gray,\"Cancel\")\ local btn_create\ screen.writeLine(\"Create\",xSize-7,ySize-3,colors.gray)\ \ local nameInput = screen.newInput(math.floor(xSize/2)-11,ySize/2-5,24,\"Username\")\ local passInput = screen.newInput(math.floor(xSize/2)-11,ySize/2-1,24,\"Password\",string.char(7))\ \ while true do\ local event, side, x, y = os.pullEvent()\ if event == \"mouse_click\" then\ if btn_cancel.check(x,y) then\ screen.remove()\ break\ elseif nameInput.check(x,y) then\ elseif passInput.check(x,y) then\ elseif btn_create and btn_create.check(x,y) then\ local err = os.createAccount(nameInput.text,passInput.text)\ if err then\ screen.remove()\ break\ end\ end\ end\ if not btn_create and nameInput.text ~= \"\" and nameInput.text ~= \"Username\" and passInput.text ~= \"Password\" then\ btn_create = screen.newButton(xSize-8,ySize-3,8,1,colors.white,colors.cyan,\"Create\")\ end\ end", path = "System/Apps/Settings/Resources/account_form.x", }, { text = "local arg = {...}\ local xSize, ySize = term.getSize()\ os.loadAPI(\"#API/screenworks\")\ \ os.setBarColor(colors.white)\ \ local screen = screenworks.newScreen(colors.lightGray,colors.white, colors.white,colors.cyan, \"\")\ local backBtn = screen.createBackBtn()\ local btn = {}\ \ local info = os.getAPIInfo(arg[1])\ if arg[1] and info then\ screen.setHeader(info.name)\ if not info.systemAPI then\ btn.menu = screen.createMenu(\"Remove\")\ end\ \ -- os.loadAPI(\"#API/\"..arg[1])\ local funcs = {}\ local function findFunctions(tbl, deep)\ for name,func in pairs(tbl) do\ if type(func) == \"function\" then\ table.insert(funcs, {name, deep})\ elseif type(func) == \"table\" then\ findFunctions(func, deep+1)\ end\ end\ end\ \ local tEnv = {}\ local fnAPI, err = loadfile( \"#API/\"..arg[1], tEnv )\ if fnAPI then\ local ok, err = pcall( fnAPI )\ if ok then\ local tAPI = {}\ for k,v in pairs( tEnv ) do\ if k ~= \"_ENV\" then\ tAPI[k] = v\ end\ end\ findFunctions(tAPI, 1)\ end\ end\ \ btn.icon = screen.drawImage(xSize/2-2,2, \"#SysRes/Images/exec_icon.png\", 6,4)\ screen.writeText(\"Version: \"..(info.version or \"X.0\"), 1, 7, xSize, \"center\")\ \ if info.size > 1024 then\ info.size = math.floor(info.size/1024)..\" KB\"\ else\ info.size = info.size..\" B\"\ end\ \ screen.writeLine(\"Occupied size:\", 4, 10, colors.black)\ screen.writeLine(info.size, xSize-#info.size-2, 10)\ \ screen.writeLine(\"Usage:\", 4, 11, colors.black)\ screen.writeLine(arg[1], xSize-#arg[1]-2, 11)\ \ if #funcs > 0 then\ screen.writeLine(\"Functions:\", 4, 13, colors.black)\ \ local sx, sy = screen.body.getSize()\ for i,func in ipairs(funcs) do\ if 13+i > sy then\ screen.resize(13+i)\ sy = 13+i\ end\ screen.writeLine(arg[1]..\".\"..func[1]..\"(..)\", 4+func[2], 13+i, colors.lightGray)\ end\ end\ end\ \ while true do\ local event, side, x, y = os.pullEvent()\ \ if event == \"mouse_click\" then\ if not info.systemAPI and btn.menu.check(x,y) then\ local ans = btn.menu.open()\ if ans == \"Remove\" then\ local dialog = screenworks.select(\"Remove API\", \"Are you sure? This may cause your system!\", \"Yes\", \"No\")\ local answ = dialog.show()\ if answ == \"Yes\" then\ -- os.runApp(\"PacketManager\", {\"remove\", arg[1]})\ screen.remove()\ break\ end\ end\ elseif backBtn.check(x,y) then\ screen.remove()\ break\ end\ elseif event == \"mouse_scroll\" then\ screen.scroll(-side)\ end\ end", path = "System/Apps/Settings/Resources/apiinfo.x", }, { text = "local xSize, ySize = term.getSize()\ os.loadAPI(\"#API/screenworks\")\ \ os.setBarColor(colors.white)\ \ local screen = screenworks.newScreen(colors.lightGray,colors.white, colors.white,colors.cyan, \"API list\")\ \ local backBtn = screen.createBackBtn()\ local sysAPI = os.getSystemAPIs()\ local usrAPI = os.getUserAPIs()\ \ local apis = {}\ \ screen.resize((#sysAPI+#usrAPI)*3+8)\ \ screen.newInput(1,1,xSize,\"System APIs\")\ \ for i=1,#sysAPI do\ local info = os.getAPIInfo(sysAPI[i])\ -- screen.writeLine(info.name,2,i*3+2,colors.gray)\ if not info.version then\ info.version = \"X.0\"\ end\ apis[#apis+1] = {}\ apis[#apis].btn = screen.newButton(2, i*3+2, 22, 1, colors.gray, colors.white, info.name, \"left\")\ apis[#apis].path = sysAPI[i]\ screen.writeLine(\"v\"..info.version, xSize-#info.version-2, i*3+2, colors.lightGray)\ if not info.size then\ info.size = \"unknown\"\ else\ if info.size > 1024 then\ info.size = math.floor(info.size/1024)..\" KB\"\ else\ info.size = info.size..\" B\"\ end\ end\ screen.writeLine(\"Size:\", 2, i*3+3 ,colors.lightGray)\ screen.writeLine(info.size, xSize-#info.size-1, i*3+3 ,colors.lightGray)\ end\ \ if #usrAPI > 0 then\ screen.newInput(1,#sysAPI*3+5,xSize,\"User APIs\")\ \ for i=1,#usrAPI do\ local info = os.getAPIInfo(usrAPI[i])\ apis[#apis+1] = {}\ apis[#apis].btn = screen.newButton(2, i*3+#sysAPI*3+6, 22, 1, colors.gray, colors.white, info.name, \"left\")\ apis[#apis].path = usrAPI[i]\ -- screen.writeLine(info.name,2,i*3+#sysAPI*3+6,colors.gray)\ if not info.version then\ info.version = \"X.0\"\ end\ screen.writeLine(\"v\"..info.version, xSize-#info.version-2, i*3+#sysAPI*3+6, colors.lightGray)\ if not info.size then\ info.size = \"unknown\"\ else\ if info.size > 1024 then\ info.size = math.floor(info.size/1024)..\" KB\"\ else\ info.size = info.size..\" B\"\ end\ end\ screen.writeLine(\"Size:\", 2, i*3+#sysAPI*3+7 ,colors.lightGray)\ screen.writeLine(info.size, xSize-#info.size-1, i*3+#sysAPI*3+7 ,colors.lightGray)\ end\ end\ \ while true do\ local event, side, x, y = os.pullEvent()\ \ if event == \"mouse_click\" then\ if backBtn.check(x,y) then\ screen.remove()\ break\ else\ for i=1,#apis do\ if apis[i].btn.check(x,y) then\ local err = os.run({},shell.resolve(\"Resources/apiinfo.x\"),apis[i].path)\ if err then\ local message = screenworks.alert(\"Error\", err)\ message.show()\ end\ \009\009\009screen.redraw()\ end\ end\ end\ elseif event == \"mouse_scroll\" then\ screen.scroll(-side)\ end\ end", path = "System/Apps/Settings/Resources/apis.x", }, { text = "local arg = {...}\ local xSize, ySize = term.getSize()\ os.loadAPI(\"#API/screenworks\")\ \ os.setBarColor(colors.white)\ \ local screen = screenworks.newScreen(colors.lightGray,colors.white, colors.white,colors.cyan, \"\")\ local backBtn = screen.createBackBtn()\ local btn = {}\ \ local info = os.getAppInfo(arg[1], true)\ if arg[1] and info then\ screen.setHeader(info.name)\ if not info.systemApp then\ btn.menu = screen.createMenu(\"Remove\", \"Clear data\")\ end\ \ if not info.systemApp and fs.exists(\"/User/Apps/\"..arg[1]..\"/App.ico\") then\ btn.icon = screen.drawImage(xSize/2-2,2, \"/User/Apps/\"..arg[1]..\"/App.ico\", 6,4)\ elseif info.systemApp and fs.exists(\"/System/Apps/\"..arg[1]..\"/App.ico\") then\ btn.icon = screen.drawImage(xSize/2-2,2, \"/System/Apps/\"..arg[1]..\"/App.ico\", 6,4)\ else\ btn.icon = screen.drawImage(xSize/2-2,2, \"#SysRes/Images/noicon.png\", 6,4)\ end\ screen.writeText(\"Version: \"..info.version, 1, 7, xSize, \"center\")\ \ if info.size > 1024 then\ info.size = math.floor(info.size/1024)..\" KB\"\ else\ info.size = info.size..\" B\"\ end\ if info.dataSize > 1024 then\ info.dataSize = math.floor(info.dataSize/1024)..\" KB\"\ else\ info.dataSize = info.dataSize..\" B\"\ end\ screen.writeLine(\"Occupied size:\", 4, 10, colors.black)\ screen.writeLine(info.size, xSize-#info.size-2, 10)\ screen.writeLine(\"User data size:\", 4, 11, colors.black)\ screen.writeLine(info.dataSize, xSize-#info.dataSize-2, 11)\ screen.writeLine(\"Developer:\", 4, 13)\ screen.writeLine(info.developer, xSize-#info.developer-2, 13)\ end\ \ while true do\ local event, side, x, y = os.pullEvent()\ \ if event == \"mouse_click\" then\ if not info.systemApp and btn.menu.check(x,y) then\ local ans = btn.menu.open()\ if ans == \"Clear data\" then\ if fs.exists(\"/User/Apps/\"..arg[1]..\"/Data\") then\ local dialog = screenworks.select(\"Clear data\", \"Are you sure?\", \"Yes\", \"No\")\ local answ = dialog.show()\ \ if answ == \"Yes\" then\ fs.delete(\"/User/Apps/\"..arg[1]..\"/Data\")\ info = os.getAppInfo(arg[1], true)\ if info.dataSize > 1024 then\ info.dataSize = math.floor(info.dataSize/1024)..\" KB\"\ else\ info.dataSize = info.dataSize..\" B\"\ end\ screen.writeText(\"User data size:\", 4, 11, xSize-8, 1, colors.black)\ screen.writeLine(info.dataSize, xSize-#info.dataSize-2, 11)\ end\ else\ local dialog = screenworks.alert(\"Error\", \"User data not found\")\ dialog.show()\ end\ elseif ans == \"Remove\" then\ local dialog = screenworks.select(\"Remove app\", \"Are you sure?\", \"Yes\", \"No\")\ local answ = dialog.show()\ if answ == \"Yes\" then\ os.runApp(\"PacketManager\", {\"remove\", arg[1]})\ screen.remove()\ break\ end\ end\ elseif backBtn.check(x,y) then\ screen.remove()\ break\ end\ end\ end", path = "System/Apps/Settings/Resources/appinfo.x", }, { text = "local xSize, ySize = term.getSize()\ os.loadAPI(\"#API/screenworks\")\ \ os.setBarColor(colors.white)\ \ local screen = screenworks.newScreen(colors.lightGray,colors.white, colors.white,colors.cyan, \"App list\")\ local backBtn = screen.createBackBtn()\ \ local sysApps = os.getSystemApps(true)\ local usrApps = os.getUserApps(true)\ local apps = {}\ \ screen.resize((#sysApps+#usrApps)*3+8)\ \ screen.newInput(1,1,xSize,\"System Apps\")\ \ for i=1,#sysApps do\ local info = os.getAppInfo(sysApps[i], true)\ if not info.name then\ info.name = sysApps[i]\ end\ apps[#apps+1] = {}\ apps[#apps].btn = screen.newButton(2, i*3+2, 22, 1, colors.gray, colors.white, info.name, \"left\")\ apps[#apps].path = sysApps[i]\ -- screen.writeLine(info.name,2,i*3+2,colors.gray)\ if not info.version then\ info.version = \"0.0\"\ end\ screen.writeLine(\"v\"..info.version, xSize-#info.version-2, i*3+2, colors.lightGray)\ if not info.size then\ info.size = \"unknown\"\ else\ if info.size > 1024 then\ info.size = math.floor(info.size/1024)..\" KB\"\ else\ info.size = info.size..\" B\"\ end\ end\ screen.writeLine(\"Size:\", 2, i*3+3 ,colors.lightGray)\ screen.writeLine(info.size, xSize-#info.size-1, i*3+3 ,colors.lightGray)\ end\ \ if #usrApps > 0 then\ screen.newInput(1,#sysApps*3+5,xSize,\"User Apps\")\ \ for i=1,#usrApps do\ local info = os.getAppInfo(usrApps[i], true)\ apps[#apps+1] = {}\ apps[#apps].btn = screen.newButton(2, i*3+#sysApps*3+6, 22, 1, colors.gray, colors.white, info.name, \"left\")\ apps[#apps].path = usrApps[i]\ -- screen.writeLine(info.name,2,i*3+#sysApps*3+6,colors.gray)\ if not info.version then\ info.version = \"0.0\"\ end\ screen.writeLine(\"v\"..info.version, xSize-#info.version-2, i*3+#sysApps*3+6, colors.lightGray)\ if not info.size then\ info.size = \"unknown\"\ else\ if info.size > 1024 then\ info.size = math.floor(info.size/1024)..\" KB\"\ else\ info.size = info.size..\" B\"\ end\ end\ screen.writeLine(\"Size:\", 2, i*3+#sysApps*3+7 ,colors.lightGray)\ screen.writeLine(info.size, xSize-#info.size-1, i*3+#sysApps*3+7 ,colors.lightGray)\ end\ end\ \ while true do\ local event, side, x, y = os.pullEvent()\ \ if event == \"mouse_click\" then\ if backBtn.check(x,y) then\ screen.remove()\ break\ else\ for i=1,#apps do\ if apps[i].btn.check(x,y) then\ os.run({},shell.resolve(\"Resources/appinfo.x\"),apps[i].path)\ \009\009\009screen.redraw()\ end\ end\ end\ elseif event == \"mouse_scroll\" then\ screen.scroll(-side)\ end\ end", path = "System/Apps/Settings/Resources/apps.x", }, { text = "local xSize, ySize = term.getSize()\ os.loadAPI(\"/System/APIs/screenworks\")\ \ local time = tonumber(os.getFloatingTime())\ local maxTime = 12\ \ local screen = screenworks.newScreen(colors.lightGray,colors.white, colors.white,colors.cyan, \"Notifications\")\ local backBtn = screen.createBackBtn()\ \ screen.writeLine(\"Floating notifications\", 2, 2, colors.gray)\ local float_switch = screen.newSwitch(xSize-6,2, nil, os.getFloatingEnabled())\ \ screen.writeLine(\"Indicator time\", 2, 5, colors.lightGray)\ local time_range = screen.newRange(2,6, xSize-2, (time/maxTime)*100)\ local time_input = screen.newInput(xSize-10,5,6,tostring(time),\"Time\", \"center\", nil, true)\ screen.writeLine(\"sec\", xSize-3, 5, colors.lightGray)\ \ local function checkTime()\ if not time then\ time = 4.0\ time_input.set(time)\ elseif time < 0.05 then\ time = 0.05\ time_input.set(time)\ elseif time > maxTime then\ time = maxTime\ time_input.set(time)\ end\ time_range.set((time/maxTime)*100)\ os.setFloatingTime(tostring(time))\ end\ \ while true do\ local event, side, x, y = os.pullEvent()\ if event == \"mouse_click\" then\ if backBtn.check(x,y) then\ screen.remove()\ break\ elseif float_switch.check(x,y) then\ os.setFloatingEnabled(float_switch.state)\ elseif time_input.check(x,y) then\ time = tonumber(time_input.text)\ checkTime()\ elseif time_range.check(x,y) then\ time = (time_range.percent/100)*maxTime\ time_input.set(time)\ checkTime()\ end\ elseif event == \"mouse_drag\" then\ if time_range.check(x,y) then\ time = (time_range.percent/100)*maxTime\ time_input.set(time)\ checkTime()\ end\ end\ end", path = "System/Apps/Settings/Resources/notifications.x", }, { text = "local xSize, ySize = term.getSize()\ os.loadAPI(\"/System/APIs/screenworks\")\ \ local screen = screenworks.newScreen(colors.lightGray,colors.white, colors.white,colors.cyan, \"Screen\")\ local backBtn = screen.createBackBtn()\ screen.writeLine(\"Color palette\", 2, 2, colors.lightGray)\ \ local colorSettings = fs.list(\"#SysRes/ScreenSettings\")\ local colorButtons = {}\ local colorRadioBox\ \ local selectedPalette = settings.get(\"os.currentPalette_name\")\ \ local rebootMsg = screenworks.select(\"Reboot now?\", \"You should reboot to apply settings\", \"Yes\", \"No\", true)\ \ local function applyColorSet(num)\ if num == 1 then\ settings.unset(\"os.currentPalette\")\ settings.unset(\"os.currentPalette_name\")\ settings.save(\".settings\")\ os.applyColorPalette()\ else\ if colorButtons[num] then\ settings.set(\"os.currentPalette\", colorButtons[num].newColors)\ settings.set(\"os.currentPalette_name\", colorButtons[num].name)\ settings.save(\".settings\")\ os.applyColorPalette(colorButtons[num].newColors)\ end\ end\ local answer = rebootMsg.show()\ if answer == \"Yes\" then\ os.reboot()\ end\ end\ \ if colorSettings and #colorSettings > 0 then\ for i=1, #colorSettings do\ local file = fs.open(\"#SysRes/ScreenSettings/\"..colorSettings[i], \"r\")\ colorButtons[i] = textutils.unserialize(file.readAll())\ colorSettings[i] = colorButtons[i].name\ file.close()\ end\ \ local _, sizeY = screen.body.getSize()\ if #colorSettings*2+4 > sizeY then\ screen.resize(#colorSettings*2+4)\ end\ colorRadioBox = screen.newRadioSet(3, 4, colorSettings, 1, xSize-4, colors.black)\ if selectedPalette then\ colorRadioBox.set(selectedPalette)\ end\ end\ \ while true do\ local event, side, x, y = os.pullEvent()\ if event == \"mouse_click\" then\ if backBtn.check(x,y) then\ screen.remove()\ break\ elseif colorRadioBox.check(x,y) then\ applyColorSet(colorRadioBox.selectedNum)\ end\ end\ end", path = "System/Apps/Settings/Resources/screen.x", }, { text = "local xSize, ySize = term.getSize()\ local exist = false\ if fs.exists(\"/User/User.info\") then\ exist = true\ end\ local acc\ local btn_rename\ local btn_newpass\ os.loadAPI(\"/System/APIs/screenworks\")\ \ \ local screen = screenworks.newScreen(colors.lightGray,colors.white, colors.white,colors.cyan, \"Security\")\ local backBtn = screen.createBackBtn()\ \ if exist then\ acc = fs.open(\"/User/User.info\",\"r\")\ acc = textutils.unserialize(acc.readAll())\ \ screen.writeText(acc.name,1,4,xSize,\"center\")\ btn_rename = screen.newButton(math.floor(xSize/2)-7,7,17,3,colors.white,colors.gray,\"Rename\")\ btn_newpass = screen.newButton(math.floor(xSize/2)-7,11,17,3,colors.white,colors.gray,\"Change password\")\ else\ btn_create = screen.newButton(math.floor(xSize/2)-7,math.floor(ySize/2),16,3,colors.white,colors.gray,\"Create account\")\ end\ \ screen.writeLine(\"Account manager\",2,2)\ \ while true do\ local event, side, x, y = os.pullEvent()\ if event == \"mouse_click\" then\ if backBtn.check(x,y) then\ screen.remove()\ break\ elseif btn_create and btn_create.check(x,y) then\ os.run({},shell.resolve(\"Resources/account_form.x\"))\ screen.redraw()\ end\ end\ end", path = "System/Apps/Settings/Resources/security.x", }, { text = "local xSize, ySize = term.getSize()\ os.loadAPI(\"/System/APIs/screenworks\")\ \ local screen = screenworks.newScreen(colors.lightGray,colors.white, colors.white,colors.cyan, \"Storage\")\ local backBtn = screen.createBackBtn()\ local menu = screen.createMenu(\"Clear all data\")\ \ if ySize-3 < 17 then\ \009screen.resize(17)\ end\ \ screen.writeLine(\"Applications\",2,8)\ local appDataBar = screen.newProgressBar(2,9,xSize-3,0)\ screen.writeLine(\"User data\",2,11)\ local userDataBar = screen.newProgressBar(2,12,xSize-3,0)\ \ local freeSpace = fs.getFreeSpace(\"/\")\ local freeSpaceKB = math.floor(freeSpace/1024)\ \ -- screen.writeLine(\"used from \"..freeSpaceKB..\" KB\",2,3)\ local allDataBar = screen.newProgressBar(2,4,xSize-3,0)\ \ local userStorage = 0\ \ local function getSizeOfAll()\ \009local sizeOfAll1 = 0\ \ \009local function files(path)\ \009\009local massiv = fs.list(path)\ \009\009for i=1,#massiv do\ \009\009\009if fs.isDir(fs.combine(path,massiv[i])) and massiv[i] ~= \"rom\" then\ \009\009\009\009files(fs.combine(path,massiv[i]))\ \009\009\009elseif not fs.isDir(fs.combine(path,massiv[i])) then\ \009\009\009\009sizeOfAll1 = sizeOfAll1 + fs.getSize(fs.combine(path,massiv[i]))\ screen.writeText(tostring(math.floor(sizeOfAll1/1024))..\" KB\", 2, 2, 13, \"left\", colors.cyan)\ allDataBar.setPercent( sizeOfAll1 / (freeSpace+sizeOfAll1) * 100 )\ \ if path:sub(1,12) == \"User/Storage\" then\ userStorage = userStorage + fs.getSize(fs.combine(path,massiv[i]))\ userDataBar.setPercent( userStorage / (freeSpace+sizeOfAll1) * 100 )\ end\ \009\009\009end\ \009\009end\ \009end\ \009files(\"\")\ \009return sizeOfAll1\ end\ \ local occupiedSpace = getSizeOfAll()\ \ local allStorage = occupiedSpace+freeSpace\ local allStorageKB = math.floor(allStorage/1024)\ \ local function getSizeOfApps()\ \009local size = 0\ \009local massiv = os.getAppsList()\ \ \009for i=1,#massiv do\ local info = os.getAppInfo(massiv[i], true)\ \009\009size = size + info.size\ appDataBar.setPercent( size / allStorage * 100 )\ \009end\ \ \009return size\ end\ \ local appSize = getSizeOfApps()\ local appSizeKB = math.floor(appSize/1024)\ local occupiedSpaceKB = math.floor(occupiedSpace/1024)\ \ screen.writeLine(\"used from \"..math.floor((freeSpace+occupiedSpace)/1024)..\" KB\",2,3)\ \ local userStorageKB = math.floor(userStorage/1024)\ \ screen.writeText(tostring(appSizeKB)..\" KB\", xSize-14, 8, 13, \"right\")\ appDataBar.setPercent( appSize / allStorage * 100 )\ \ screen.writeText(tostring(userStorageKB)..\" KB\", xSize-14, 11, 13, \"right\")\ userDataBar.setPercent( userStorage / allStorage * 100 )\ \ screen.writeText(tostring(occupiedSpaceKB)..\" KB\", 2, 2, 13, \"left\", colors.cyan)\ allDataBar.setPercent( occupiedSpace / allStorage * 100 )\ \ while true do\ local event, side, x, y = os.pullEvent()\ if event == \"mouse_click\" then\ if backBtn.check(x,y) then\ screen.remove()\ break\ elseif menu.check(x,y) then\ local ans = menu.open()\ end\ \009elseif event == \"mouse_scroll\" then\ \009\009screen.scroll(-side)\ end\ end", path = "System/Apps/Settings/Resources/storage.x", }, { text = "local xSize, ySize = term.getSize()\ os.loadAPI(\"#API/screenworks\")\ \ os.setBarColor(colors.white)\ \ local loadingScreen = screenworks.newScreen(colors.lightGray,colors.white, colors.lightGray,colors.white, \"\", false)\ loadingScreen.drawImage(math.floor(xSize/2)-3, 2, \"#SysRes/Images/load_icon.png\")\ loadingScreen.writeText(\"Downloading update\", math.floor(xSize/2)-11, 10, 24, \"center\", colors.lightGray)\ local loadingBar = loadingScreen.newProgressBar(math.floor(xSize/2)-11, 12, 24, 0, colors.cyan, true)\ \ local changesScreen = screenworks.newScreen(colors.lightGray,colors.white, colors.white,colors.cyan, \"What's new\", false)\ local logBackBtn = changesScreen.createBackBtn()\ local logBtnOK = changesScreen.newButton(math.floor(xSize/2)-11, ySize-3, 24, 1, colors.white, colors.lightGray, \"ok\")\ \ local changesList = screenworks.newScreen(colors.white,colors.gray, colors.white,colors.white, \"Changelog\", false, math.floor(xSize/2)-11, 3, 24, ySize-4, 0)\ \ local screen = screenworks.newScreen(colors.lightGray,colors.white, colors.white,colors.cyan, \"Updates\")\ local backBtn = screen.createBackBtn()\ \ local file = http.get(\"https://pastebin.com/raw/e59XLpie\")\ local info = file.readAll()\ file.close()\ info = textutils.unserialize(info)\ \ local curinf = os.getOSinfo()\ \ screen.writeLine(\"Current OS version\", 2, 2)\ screen.writeLine(\"Last OS version\", 2, 4)\ \ screen.writeLine(curinf.OSversion, xSize - #curinf.OSversion-1, 2, (curinf.OSversion == info.OSversion and colors.green) or colors.red)\ screen.writeLine(info.OSversion, xSize - #info.OSversion-1, 4, colors.green)\ \ local btnNews, btnUpdate\ \ if curinf.OSversion < info.OSversion then\ btnNews = screen.newButton(math.floor(xSize/2)-6, ySize-8, 14, 3, colors.lightGray, colors.white, \"What's new\")\ btnUpdate = screen.newButton(math.floor(xSize/2)-6, ySize-5, 14, 3, colors.white, colors.green, \"Update\")\ end\ \ while true do\ local event, side, x, y = os.pullEvent()\ \ if event == \"mouse_click\" then\ if backBtn.check(x,y) then\ screen.remove()\ break\ elseif btnNews and btnNews.check(x,y) then\ screen.setActive(false)\ changesScreen.setActive(true)\ changesList.resize(ySize-4)\ changesList.body.clear()\ local size = changesList.writeText(info.changelog[info.OSversion], 2,2,22)\ if size > ySize-4 then\ changesList.resize(size+2)\ changesList.writeText(info.changelog[info.OSversion], 1,2,24)\ end\ changesList.setActive(true)\ elseif btnUpdate and btnUpdate.check(x,y) then\ screen.setActive(false)\ loadingScreen.setActive(true)\ \ local function loading()\ local updater = http.get(\"https://pastebin.com/raw/MM7AKF2u\")\ local file = fs.open(\"#tmp/updater.lua\",\"w\")\ file.write(updater.readAll())\ file.close()\ updater.close()\ \ local image = http.get(info.links[info.OSversion])\ local file = fs.open(\"#tmp/img\"..info.OSversion..\".info\",\"w\")\ file.write(image.readAll())\ file.close()\ image.close()\ \ settings.set(\"boot.addNewItem\", {name = \"LegacyOS update \"..info.OSversion, path = \"/Temp/updater.lua\", args = \"/Temp/img\"..info.OSversion..\".info\"})\ settings.save(\".settings\")\ end\ \ local function waiting()\ local i = 1\ while true do\ if i > 142 then\ i = 1\ end\ loadingBar.setPercent(i)\ i = i + 1\ sleep(0)\ end\ end\ \ parallel.waitForAny(loading, waiting)\ \ loadingBar.waiting = false\ loadingBar.setPercent(100)\ \ local rebootDialog = screenworks.select(\"Reboot now?\", \"You must reboot to continue updating\", \"Yes\", \"No\", true)\ local answer = rebootDialog.show()\ if answer == \"Yes\" then\ os.reboot()\ end\ elseif logBtnOK.check(x,y) or logBackBtn.check(x,y) then\ changesList.setActive(false)\ changesScreen.setActive(false)\ screen.setActive(true)\ end\ elseif event == \"mouse_scroll\" then\ if screen.active then\ screen.scroll(-side)\ elseif changesList.active then\ changesList.scroll(-side)\ end\ end\ end", path = "System/Apps/Settings/Resources/updates.x", }, { text = "local xSize, ySize = term.getSize()\ os.loadAPI(\"#API/screenworks\")\ \ os.setBarColor(colors.white)\ \ local about = fs.open(shell.resolve(\"App.info\"), \"r\")\ about = textutils.unserialize(about.readAll())\ \ local screen = screenworks.newScreen(colors.lightGray,colors.white, colors.white,colors.cyan, \"Settings\")\ \ if ySize-3 < 17 then\ \009screen.resize(17)\ end\ \ local btn_apps = screen.newButton(2,2,24,1, colors.gray,colors.white, \"Applications\", \"left\")\ local btn_notifications = screen.newButton(2,4,24,1, colors.gray,colors.white, \"Notifications\", \"left\")\ local btn_security = screen.newButton(2,6,24,1, colors.gray,colors.white, \"Security\", \"left\")\ local btn_storage = screen.newButton(2,8,24,1, colors.gray,colors.white, \"Storage\", \"left\")\ local btn_updates = screen.newButton(2,10,24,1, colors.gray,colors.white, \"Updates\", \"left\")\ local btn_screen = screen.newButton(2,12,24,1, colors.gray,colors.white, \"Screen\", \"left\")\ local btn_API = screen.newButton(2,14,24,1, colors.gray,colors.white, \"APIs\", \"left\")\ local btn_about = screen.newButton(2,16,24,1, colors.gray,colors.white, \"About\", \"left\")\ \ -- local sSwitch = screen.newSwitch(xSize-6,2)\ \ while true do\ \009local event, side, x, y = os.pullEvent()\ \ \009if event == \"mouse_click\" then\ \009\009if btn_about.check(x,y) then\ \009\009\009local err = os.run({},shell.resolve(\"Resources/about.x\"))\ \009\009\009if err then\ \009\009\009\009local message = screenworks.alert(\"Error\", err)\ \009\009\009\009message.show()\ \009\009\009end\ \009\009\009screen.redraw()\ \009\009elseif btn_notifications.check(x,y) then\ \009\009\009local err = os.run(os.getEnvironment(),shell.resolve(\"Resources/notifications.x\"))\ \009\009\009if err then\ \009\009\009\009local message = screenworks.alert(\"Error\", err)\ \009\009\009\009message.show()\ \009\009\009end\ \009\009\009screen.redraw()\ \009\009elseif btn_API.check(x,y) then\ \009\009\009local err = os.run(os.getEnvironment(),shell.resolve(\"Resources/apis.x\"))\ \009\009\009if err then\ \009\009\009\009local message = screenworks.alert(\"Error\", err)\ \009\009\009\009message.show()\ \009\009\009end\ \009\009\009screen.redraw()\ \009\009elseif btn_storage.check(x,y) then\ \009\009\009local err = os.run({},shell.resolve(\"Resources/storage.x\"))\ \009\009\009if err then\ \009\009\009\009local message = screenworks.alert(\"Error\", err)\ \009\009\009\009message.show()\ \009\009\009end\ \009\009\009screen.redraw()\ \009\009elseif btn_apps.check(x,y) then\ \009\009\009local err = os.run(os.getEnvironment(),shell.resolve(\"Resources/apps.x\"))\ \009\009\009if err then\ \009\009\009\009local message = screenworks.alert(\"Error\", err)\ \009\009\009\009message.show()\ \009\009\009end\ \009\009\009screen.redraw()\ \009\009elseif btn_updates.check(x,y) then\ \009\009\009local err = os.run(os.getEnvironment(),shell.resolve(\"Resources/updates.x\"))\ \009\009\009if err then\ \009\009\009\009local message = screenworks.alert(\"Error\", err)\ \009\009\009\009message.show()\ \009\009\009end\ \009\009\009screen.redraw()\ \009\009elseif btn_screen.check(x,y) then\ \009\009\009local err = os.run({},shell.resolve(\"Resources/screen.x\"))\ \009\009\009if err then\ \009\009\009\009local message = screenworks.alert(\"Error\", err)\ \009\009\009\009message.show()\ \009\009\009end\ \009\009\009screen.redraw()\ \009\009elseif btn_security.check(x,y) then\ \009\009\009local err = os.run(os.getEnvironment(),shell.resolve(\"Resources/security.x\"))\ \009\009\009if err then\ \009\009\009\009local message = screenworks.alert(\"Error\", err)\ \009\009\009\009message.show()\ \009\009\009end\ \009\009\009screen.redraw()\ \009\009end\ \009elseif event == \"mouse_scroll\" then\ \009\009screen.scroll(-side)\ \009end\ \ end", path = "System/Apps/Settings/Start.x", }, { text = " 07 07 07 07 07 07\ 0f 0f 0f 0f 0f 0f\ 0f>9f 0f 0f 0f 0f\ 0f 0f 0f 0f 0f 0f", path = "System/Apps/Shell/App.ico", }, { text = "{\ name = \"Shell\",\ version = \"0.1\",\ developer = \"DECE\",\ }", path = "System/Apps/Shell/App.info", }, { text = "local xSize, ySize = term.getSize()\ os.loadAPI(\"#API/screenworks\")\ \ local place = \"/\"\ shell.setDir(place)\ local command = \"\"\ local path = {}\ local textPath = shell.path()\ local env = os.getEnvironment()\ local memory = {}\ local memCursor = 0\ os.setBarColor(colors.black)\ env.place = function()\ return place\ end\ env.shell = shell\ \ local screen = screenworks.newScreen(colors.white,colors.black, colors.cyan, colors.gray, \"Shell\")\ screen.resize(ySize*2)\ \ env.print = function(text)\ local sizeX, sizeY = screen.body.getSize()\ local cursorX, cursorY = screen.body.getCursorPos()\ while #text > 0 do\ term.write(text)\ text = string.sub(text, sizeX - cursorX+2)\ cursorX, cursorY = 1, cursorY+1\ if cursorY > sizeY then\ screen.resize(sizeY + 1)\ sizeY = sizeY + 1\ end\ screen.body.setCursorPos(cursorX, cursorY)\ end\ end\ \ local function updatePath()\ path = {}\ local pos = 0\ path[pos] = \"\"\ for i=1,#textPath do\ if string.sub(textPath,i,i) == \":\" then\ pos = pos+1\ path[pos] = \"\"\ else\ path[pos] = path[pos]..string.sub(textPath,i,i)\ end\ end\ path[#path+1] = \"/System/Scripts\"\ path[#path+1] = place\ end\ \ local function stringToTable(str)\ local pos = 1\ local tbl = {}\ tbl[pos] = \"\"\ for i=1,#str do\ if string.sub(str,i,i) == \" \" then\ pos = pos+1\ tbl[pos] = \"\"\ else\ tbl[pos] = tbl[pos]..string.sub(str,i,i)\ end\ end\ return tbl\ end\ \ local function exec(command)\ updatePath()\ command = stringToTable(command)\ local xPos,yPos = screen.body.getCursorPos()\ -- local newTerm = window.create(screen.body,xPos,yPos,xSize-1,ySize)\ -- local trm = term.redirect(newTerm)\ local trm = term.redirect(screen.body)\ \ if command[1] == \"cd\" then\ if string.sub(command[2],1,2) == \"..\" then\ local i = #place\ while string.sub(place,i,i) ~= \"/\" and i > 0 do\ i=i-1\ end\ if i > 1 then\ place = string.sub(place,0,i)\ else\ place = \"/\"\ end\ command[2] = string.sub(command[2],3)\ elseif string.sub(command[2],1,1) == \"/\" then\ place = \"/\"\ end\ if fs.exists(fs.combine(place,command[2])) then\ if fs.isDir(fs.combine(place,command[2])) then\ place = fs.combine(place,command[2])\ shell.setDir(place)\ env.shell = shell\ else\ term.setTextColor(colors.red)\ print(command[2]..\" not a directory\")\ end\ else\ term.setTextColor(colors.red)\ print(\"Can't find \"..command[2])\ end\ updatePath()\ elseif command[1] == \"clear\" then\ term.setCursorPos(1,1)\ term.setBackgroundColor(colors.black)\ term.clear()\ screen.resize(ySize*2)\ else\ for i=1,#path do\ if fs.exists(fs.combine(path[i],command[1]..\".lua\")) then\ command[1] = fs.combine(path[i],command[1]..\".lua\")\ break\ elseif string.sub(command[1],1,1) ~= \"/\" and fs.exists(fs.combine(path[i],command[1])) then\ command[1] = fs.combine(path[i],command[1])\ break\ elseif string.sub(command[1],1,1) == \"/\" and fs.exists(command[1]) then\ break\ end\ end\ \ local program = command[1]\ for i=1,#command-1 do\ command[i] = command[i+1]\ end\ command[#command] = nil\ \ -- trm = term.redirect(newTerm)\ \ --term.redirect(screen.body)\ os.run(env,program,unpack(command))\ --local xp, yp = newTerm.getCursorPos()\ --local xp_, yp_ = trm.getCursorPos()\ --trm.setCursorPos(1,yp_+yp)\ end\ term.redirect(trm)\ end\ \ local function preview(text)\ local lFiles = fs.list(place)\ local previewText = \"\"\ local finded = false\ \ local function find(tbl)\ for i=1,#tbl do\ if string.sub(tbl[i],1,#text) == text then\ previewText = string.sub(tbl[i],#text+1)\ finded = true\ break\ end\ end\ end\ \ local comm = stringToTable(text)\ text = comm[#comm]\ \ local slPos\ for i=1, #text do\ if string.sub(text,i,i) == \"/\" then\ slPos = i\ end\ end\ \ if slPos then\ lFiles = fs.list(fs.combine(place, string.sub(text,1,slPos-1)))\ text = string.sub(text,slPos+1)\ end\ \ if text ~= \"\" then\ find(lFiles)\ \ if not finded and not slPos then\ lFiles = fs.list(path[#path-1])\ for i=1,#lFiles do\ lFiles[i] = string.sub(lFiles[i],1,#lFiles[i]-4)\ end\ find(lFiles)\ end\ end\ \ return previewText\ end\ \ local function input()\ local args = \"\"\ local prev = \"\"\ \ while true do\ local xPos,yPos = screen.body.getCursorPos()\ local sizeX,sizeY = screen.body.getSize()\ local posX,posY = screen.body.getPosition()\ if yPos >= sizeY-ySize/2 then\ screen.resize(sizeY+20)\ end\ local ev, sd = os.pullEvent()\ if ev == 'key' then\ if sd == keys.enter then\ screen.body.write(\" ->\")\ screen.body.setCursorPos(1,yPos+1)\ exec(args)\ memCursor = #memory+2\ memory[#memory+1] = args\ args = \"\"\ xPos,yPos = screen.body.getCursorPos()\ elseif sd == keys.backspace then\ args = string.sub(args,1,#args-1)\ elseif sd == keys.up then\ if memCursor > 1 then\ memCursor = memCursor-1\ args = memory[memCursor]\ end\ elseif sd == keys.down then\ if memCursor < #memory then\ memCursor = memCursor+1\ args = memory[memCursor]\ end\ elseif sd == keys.tab then\ args = args..prev\ end\ elseif ev == 'char' and sd ~= nil then\ args = args..sd\ elseif ev == \"mouse_scroll\" then\ screen.scroll(-sd)\ elseif ev == \"resume\" then\ term.redirect(screen.body)\ end\ --term.redirect(screen.body)\ --term.setCursorBlink(true)\ --screen.body.setCursorBlink(true)\ prev = preview(args)\ screen.body.setCursorPos(1,yPos+1)\ screen.writeLine(\" \",1,yPos)\ screen.writeLine(\">\",2,yPos,colors.cyan)\ screen.body.setTextColor(colors.white)\ screen.body.setCursorPos(4,yPos)\ screen.body.write(args)\ screen.body.setTextColor(colors.lightGray)\ screen.body.write(prev)\ -- screen.writeLine(args,4,yPos,colors.white)\ screen.redraw()\ screen.writeLine(\" \",1,2,colors.gray,screen.header)\ screen.writeLine(\">\"..place,1,2,colors.lightGray,screen.header)\ screen.body.setCursorPos(4+#args, yPos)\ screen.body.setCursorBlink(true)\ end\ end\ \ updatePath()\ input()", path = "System/Apps/Shell/Start.x", }, { text = "{\ family = \"LegacyOS\",\ name = \"Legacy\",\ core_path = \"/System/Core.x\",\ \ OSversion = \"0.0.5\",\ APIversion = \"0.2\",\ \ build = \"Alpha#5\",\ build_date = \"09.04.19\",\ }", path = "System/Build.info", }, { text = "local arg = {...}\ \ local xSize, ySize = term.getSize()\ local centerX = math.floor(xSize/2)\ local centerY = math.floor(ySize/2)\ local tasks = {}\ local tAPIsLoading = {}\ local currentTask = 0\ local currentRunningTask\ local allowBarDrawing = true\ local first = term.native()\ local origin = window.create(term.native(),1,1,xSize,ySize)\ term.redirect(origin)\ \ local showSplash = true\ local saveLog = false\ local withoutDebug = false\ local verbose = false\ local delay = 0\ \ local defaultLauncher = settings.get(\"os.defaultLauncher\", 'Launcher')\ local defaultUI = settings.get(\"os.defaultUI\", \"LegacyUI\")\ \ local floatingEnabled = settings.get(\"os.floatingEnabled\", true)\ local floatingTime = tonumber(settings.get(\"os.floatingTime\", 4.0))\ \ local ui_state, appPosX, appPosY, appSizeX, appSizeY = 1, 1, xSize, ySize-1\ local ui_routine\ local did_mod = false\ local press_mod\ \ local file = fs.open(\"/System/Media/ScreenSettings/1.info\", \"r\")\ local stockPalette = textutils.unserialize(file.readAll()).newColors\ file.close()\ local currentPalette = settings.get(\"os.currentPalette\", stockPalette)\ \ local logBuffer = {}\ local lastLogMsg = \"\"\ \ os.applyColorPalette = function(palette, trm)\ \009if stockPalette and term.setPaletteColor then\ \009\009local palette = palette or stockPalette\ \009\009local trm = trm or term.native()\ \009\009for name, stockColor in pairs(stockPalette) do\ \009\009\009if palette[name] then\ \009\009\009\009trm.setPaletteColor(colors[name], palette[name][1], palette[name][2], palette[name][3])\ \009\009\009else\ \009\009\009\009trm.setPaletteColor(colors[name], stockColor[1], stockColor[2], stockColor[3])\ \009\009\009end\ \009\009end\ \009\009currentPalette = palette\ \009end\ end\ \ os.applyColorPalette(currentPalette)\ \ local errorBuffer\ \ -- env = {}\ \ oldOpen = fs.open\ oldDel = fs.delete\ oldCopy = fs.copy\ oldMove = fs.move\ oldMkdir = fs.makeDir\ oldList = fs.list\ oldSize = fs.getSize\ oldDir = fs.isDir\ oldExist = fs.exists\ oldName = fs.getName\ oldGDir = fs.getDir\ oldReadOnly = fs.isReadOnly\ oldPath = shell.path()\ oldLoadAPI = os.loadAPI\ \ notifications = {}\ \ if arg then\ \009for i=1,#arg do\ \009\009if arg[i] == '--no-splash' then\ \009\009\009showSplash = false\ \009\009elseif arg[i] == '--no-debug' then\ \009\009\009withoutDebug = true\ \009\009elseif arg[i] == '--use-launcher' then\ \009\009\009defaultLauncher = (arg[i+1] or defaultLauncher)\ \009\009elseif arg[i] == '--use-ui' then\ \009\009\009defaultUI = (arg[i+1] or defaultUI)\ \009\009elseif arg[i] == \"-l\" or arg[i] == \"--save-log\" then\ \009\009\009saveLog = true\ \009\009\009verbose = true\ \009\009elseif arg[i] == \"--no-bar\" then\ \009\009\009allowBarDrawing = false\ \009\009elseif arg[i] == \"-v\" or arg[i] == \"--verbose\" then\ \009\009\009verbose = true\ \009\009elseif arg[i] == \"--set-delay\" then\ \009\009\009delay = (tonumber(arg[i+1]) or delay)\ \009\009end\ \009end\ end\ \ function os.run( _tEnv, _sPath, ... )\ \009local tArgs = { ... }\ \009local tEnv = _tEnv\ \ \009local env = os.getEnvironment()\ \ \009if env then\ \009\009for val, name in pairs(env) do\ \009\009\009if not tEnv[name] then\ \009\009\009\009tEnv[name] = val\ \009\009\009end\ \009\009end\ \009end\ \ \009setmetatable( tEnv, { __index = _G } )\ \009local fnFile, err = loadfile( _sPath, tEnv )\ \009if fnFile then\ \009\009local ok, err = pcall( function()\ \009\009\009fnFile( table.unpack( tArgs ) )\ \009\009end )\ \009\009if not ok then\ \009\009\009if err and err ~= \"\" then\ \009\009\009\009return err\ \009\009\009end\ \009\009end\ \009\009return nil\ \009end\ \009if err and err ~= \"\" then\ \009\009return err\ \009end\ end\ \ local function printLog(txt, color)\ \009lastLogMsg = txt\ \009if not showSplash and (not tasks or #tasks == 0) then\ \009\009if not color then\ \009\009\009color = colors.white\ \009\009end\ \009\009term.setTextColor(color)\ \009\009print(txt)\ \009\009term.setTextColor(colors.white)\ \009end\ \009if saveLog then\ \009\009local file = oldOpen(\"/System/boot_log.txt\",\"a\")\ \009\009file.writeLine(txt)\ \009\009file.close()\ \009end\ \009if verbose then\ \009\009logBuffer[#logBuffer+1] = {text = txt, color = (color or colors.white)}\ \009end\ end\ \ if saveLog then\ \009local file = nil\ \009if fs.exists(\"/System/boot_log.txt\") then\ \009\009file = oldOpen(\"/System/boot_log.txt\",\"a\")\ \009else\ \009\009file = oldOpen(\"/System/boot_log.txt\",\"w\")\ \009end\ \009file.writeLine(\"\")\ \009file.writeLine(\"---------------New Boot----------------\")\ \009file.close()\ end\ \ \ printLog(\"Starting...\")\ printLog(\"\")\ oldLoadAPI(\"/System/Media/bootanimation.lua\")\ oldLoadAPI(\"/System/Media/shutanimation.lua\")\ \ local bootScreen = function()\ \009if showSplash then\ \009\009bootanimation.init()\ \009end\ end\ \ local function bootAnimation()\ \009if term.setPaletteColor and showSplash then\ \009\009bootanimation.loop()\ \009end\ end\ \ local shutAnimation = function()\ \009allowBarDrawing = false\ \009if term.setPaletteColor and showSplash then\ \009\009origin.setCursorBlink(false)\ \009\009shutanimation.init()\ \009\009shutanimation.loop()\ \009end\ end\ \ local nativeReboot = os.reboot\ os.reboot = function()\ \009shutAnimation()\ \009nativeReboot()\ \009while true do\ coroutine.yield()\ end\ end\ \ local nativeShutdown = os.shutdown\ os.shutdown = function()\ \009shutAnimation()\ \009nativeShutdown()\ while true do\ coroutine.yield()\ end\ end\ \ local function splash()\ while true do\ if showSplash then\ bootAnimation()\ end\ sleep(0.2)\ end\ end\ \ function boot()\ -------------------------------------------------------------------\ \009printLog(\"Clearing temporary directory\")\ \009fs.delete(\"/Temp\")\ \009fs.makeDir(\"/Temp\")\ \ printLog(\"Setting up FS API\")\ \ \009local function checkStoragePath(path)\ \009\009if (string.sub(path,1,8) == \"#Storage\" or string.sub(path,1,9) == \"/#Storage\" or string.sub(path,1,10) == \"//#Storage\") then\ \009\009\009return true\ \009\009end\ \009end\ \ \009local function checkResourcesPath(path)\ \009\009if (string.sub(path,1,7) == \"#SysRes\" or string.sub(path,1,8) == \"/#SysRes\" or string.sub(path,1,9) == \"//#SysRes\") then\ \009\009\009return true\ \009\009end\ \009end\ \ \009local function checkTempPath(path)\ \009\009if (string.sub(path,1,4) == \"#tmp\" or string.sub(path,1,5) == \"/#tmp\" or string.sub(path,1,6) == \"//#tmp\") then\ \009\009\009return true\ \009\009end\ \009end\ \ fs.open = function(path,mode)\ \009\009if (string.sub(path,1,4) == \"#API\" or string.sub(path,1,5) == \"/#API\" or string.sub(path,1,6) == \"//#API\") and mode == \"r\" then\ \009\009\009path = string.sub(path,string.find(path,\"#API\")+4)\ \009\009\009if oldExist(fs.combine(\"/User/APIs/\", path)) then\ \009\009\009\009path = fs.combine(\"/User/APIs/\", path)\ \009\009\009elseif oldExist(fs.combine(\"/System/APIs/\", path)) then\ \009\009\009\009path = fs.combine(\"/System/APIs/\", path)\ \009\009\009end\ \009\009elseif checkResourcesPath(path) and mode == \"r\" then\ \009\009\009path = fs.combine(\"/System/Media\",string.sub(path,string.find(path,\"#SysRes\")+7))\ \009\009elseif checkStoragePath(path) then\ \009\009\009path = fs.combine(\"/User/Storage\",string.sub(path,string.find(path,\"#Storage\")+8))\ \009\009elseif checkTempPath(path) then\ \009\009\009path = fs.combine(\"/Temp\",string.sub(path,string.find(path,\"#tmp\")+4))\ \009\009elseif tasks[currentTask] and not tasks[currentTask].running and tasks[currentTask].access > 1 then\ path = fs.combine(\"User/Apps/\"..tasks[currentTask].path..\"/Data\",path)\ end\ \009\009if tasks[currentTask] then\ \009\009\009printLog(\"Trying to get access to the file system, access level: \"..tasks[currentTask].access)\ \009\009\009if tasks[currentTask].running then\ \009\009\009\009tasks[currentTask].running = nil\ \009\009\009end\ \009\009end\ \009\009printLog(\"Opening file - Real file path is: \"..path)\ return oldOpen(path,mode)\ end\ \ fs.delete = function(path)\ \009\009if checkStoragePath(path) then\ \009\009\009path = fs.combine(\"/User/Storage\",string.sub(path,string.find(path,\"#Storage\")+8))\ \009\009elseif checkTempPath(path) then\ \009\009\009path = fs.combine(\"/Temp\",string.sub(path,string.find(path,\"#tmp\")+4))\ elseif tasks[currentTask] and not tasks[currentTask].running and tasks[currentTask].access > 1 then\ path = fs.combine(\"User/Apps/\"..tasks[currentTask].path..\"/Data\",path)\ end\ \009\009printLog(\"Deleting file - Real file path is: \"..path)\ return oldDel(path)\ end\ \ fs.copy = function(path1,path2)\ \009\009-- if checkStoragePath(path1) or checkStoragePath(path2) then\ \009\009-- \009if checkStoragePath(path1) then\ \009\009-- \009\009path1 = fs.combine(\"/User/Storage\",string.sub(path2,string.find(path1,\"#Storage\")+8))\ \009\009-- \009end\ \009\009-- \009if checkStoragePath(path2) then\ \009\009-- \009\009path2 = fs.combine(\"/User/Storage\",string.sub(path2,string.find(path2,\"#Storage\")+8))\ \009\009-- \009end\ -- elseif tasks[currentTask] and not tasks[currentTask].running and tasks[currentTask].access > 1 then\ -- path1 = fs.combine(\"User/Apps/\"..tasks[currentTask].path..\"/Data\",path1)\ -- path2 = fs.combine(\"User/Apps/\"..tasks[currentTask].path..\"/Data\",path2)\ -- end\ \ \009\009if checkStoragePath(path1) then\ \009\009\009path1 = fs.combine(\"/User/Storage\",string.sub(path2,string.find(path1,\"#Storage\")+8))\ \009\009elseif checkTempPath(path1) then\ \009\009\009path1 = fs.combine(\"/Temp\",string.sub(path,string.find(path1,\"#tmp\")+4))\ \009\009elseif tasks[currentTask] and not tasks[currentTask].running and tasks[currentTask].access > 1 then\ \009\009\009path1 = fs.combine(\"User/Apps/\"..tasks[currentTask].path..\"/Data\",path1)\ \009\009end\ \ \009\009if checkStoragePath(path2) then\ \009\009\009path2 = fs.combine(\"/User/Storage\",string.sub(path2,string.find(path2,\"#Storage\")+8))\ \009\009elseif checkTempPath(path2) then\ \009\009\009path2 = fs.combine(\"/Temp\",string.sub(path,string.find(path2,\"#tmp\")+4))\ \009\009elseif tasks[currentTask] and not tasks[currentTask].running and tasks[currentTask].access > 1 then\ \009\009\009path2 = fs.combine(\"User/Apps/\"..tasks[currentTask].path..\"/Data\",path2)\ \009\009end\ \ return oldCopy(path1,path2)\ end\ \ fs.move = function(path1,path2)\ \009\009-- if checkStoragePath(path1) or checkStoragePath(path2) then\ \009\009-- \009if checkStoragePath(path1) then\ \009\009-- \009\009path1 = fs.combine(\"/User/Storage\",string.sub(path2,string.find(path1,\"#Storage\")+8))\ \009\009-- \009end\ \009\009-- \009if checkStoragePath(path2) then\ \009\009-- \009\009path2 = fs.combine(\"/User/Storage\",string.sub(path2,string.find(path2,\"#Storage\")+8))\ \009\009-- \009end\ -- elseif tasks[currentTask] and not tasks[currentTask].running and tasks[currentTask].access > 1 then\ -- path1 = fs.combine(\"User/Apps/\"..tasks[currentTask].path..\"/Data\",path1)\ -- path2 = fs.combine(\"User/Apps/\"..tasks[currentTask].path..\"/Data\",path2)\ -- end\ \ \009\009if checkStoragePath(path1) then\ \009\009\009path1 = fs.combine(\"/User/Storage\",string.sub(path2,string.find(path1,\"#Storage\")+8))\ \009\009elseif checkTempPath(path1) then\ \009\009\009path1 = fs.combine(\"/Temp\",string.sub(path,string.find(path1,\"#tmp\")+4))\ \009\009elseif tasks[currentTask] and not tasks[currentTask].running and tasks[currentTask].access > 1 then\ \009\009\009path1 = fs.combine(\"User/Apps/\"..tasks[currentTask].path..\"/Data\",path1)\ \009\009end\ \ \009\009if checkStoragePath(path2) then\ \009\009\009path2 = fs.combine(\"/User/Storage\",string.sub(path2,string.find(path2,\"#Storage\")+8))\ \009\009elseif checkTempPath(path2) then\ \009\009\009path2 = fs.combine(\"/Temp\",string.sub(path,string.find(path2,\"#tmp\")+4))\ \009\009elseif tasks[currentTask] and not tasks[currentTask].running and tasks[currentTask].access > 1 then\ \009\009\009path2 = fs.combine(\"User/Apps/\"..tasks[currentTask].path..\"/Data\",path2)\ \009\009end\ return oldMove(path1,path2)\ end\ \ fs.makeDir = function(path)\ \009\009if checkStoragePath(path) then\ \009\009\009path = fs.combine(\"/User/Storage\",string.sub(path,string.find(path,\"#Storage\")+8))\ \009\009elseif checkTempPath(path) then\ \009\009\009path = fs.combine(\"/Temp\",string.sub(path,string.find(path,\"#tmp\")+4))\ elseif tasks[currentTask] and not tasks[currentTask].running and tasks[currentTask].access > 1 then\ path = fs.combine(\"User/Apps/\"..tasks[currentTask].path..\"/Data\",path)\ end\ return oldMkdir(path)\ end\ \ fs.list = function(path)\ \009\009if checkStoragePath(path) then\ \009\009\009path = fs.combine(\"/User/Storage\",string.sub(path,string.find(path,\"#Storage\")+8))\ \009\009elseif checkResourcesPath(path) then\ \009\009\009path = fs.combine(\"/System/Media\",string.sub(path,string.find(path,\"#SysRes\")+7))\ \009\009elseif checkTempPath(path) then\ \009\009\009path = fs.combine(\"/Temp\",string.sub(path,string.find(path,\"#tmp\")+4))\ elseif tasks[currentTask] and not tasks[currentTask].running and tasks[currentTask].access > 1 then\ path = fs.combine(\"User/Apps/\"..tasks[currentTask].path..\"/Data\",path)\ end\ return oldList(path)\ end\ \ fs.getSize = function(path)\ \009\009if checkStoragePath(path) then\ \009\009\009path = fs.combine(\"/User/Storage\",string.sub(path,string.find(path,\"#Storage\")+8))\ \009\009elseif checkResourcesPath(path) then\ \009\009\009path = fs.combine(\"/System/Media\",string.sub(path,string.find(path,\"#SysRes\")+7))\ \009\009elseif checkTempPath(path) then\ \009\009\009path = fs.combine(\"/Temp\",string.sub(path,string.find(path,\"#tmp\")+4))\ elseif tasks[currentTask] and not tasks[currentTask].running and tasks[currentTask].access > 1 then\ path = fs.combine(\"User/Apps/\"..tasks[currentTask].path..\"/Data\",path)\ end\ return oldSize(path)\ end\ \ fs.isDir = function(path)\ \009\009if checkStoragePath(path) then\ \009\009\009path = fs.combine(\"/User/Storage\",string.sub(path,string.find(path,\"#Storage\")+8))\ \009\009elseif checkResourcesPath(path) then\ \009\009\009path = fs.combine(\"/System/Media\",string.sub(path,string.find(path,\"#SysRes\")+7))\ \009\009elseif checkTempPath(path) then\ \009\009\009path = fs.combine(\"/Temp\",string.sub(path,string.find(path,\"#tmp\")+4))\ elseif tasks[currentTask] and not tasks[currentTask].running and tasks[currentTask].access > 1 then\ path = fs.combine(\"User/Apps/\"..tasks[currentTask].path..\"/Data\",path)\ end\ return oldDir(path)\ end\ \ fs.exists = function(path)\ \009\009if checkStoragePath(path) then\ \009\009\009path = fs.combine(\"/User/Storage\",string.sub(path,string.find(path,\"#Storage\")+8))\ \009\009elseif checkResourcesPath(path) then\ \009\009\009path = fs.combine(\"/System/Media\",string.sub(path,string.find(path,\"#SysRes\")+7))\ \009\009elseif checkTempPath(path) then\ \009\009\009path = fs.combine(\"/Temp\",string.sub(path,string.find(path,\"#tmp\")+4))\ elseif tasks[currentTask] and not tasks[currentTask].running and tasks[currentTask].access > 1 then\ path = fs.combine(\"User/Apps/\"..tasks[currentTask].path..\"/Data\",path)\ end\ return oldExist(path)\ end\ \ fs.getName = function(path)\ \009\009if checkStoragePath(path) then\ \009\009\009path = fs.combine(\"/User/Storage\",string.sub(path,string.find(path,\"#Storage\")+8))\ \009\009elseif checkResourcesPath(path) then\ \009\009\009path = fs.combine(\"/System/Media\",string.sub(path,string.find(path,\"#SysRes\")+7))\ \009\009elseif checkTempPath(path) then\ \009\009\009path = fs.combine(\"/Temp\",string.sub(path,string.find(path,\"#tmp\")+4))\ elseif tasks[currentTask] and not tasks[currentTask].running and tasks[currentTask].access > 1 then\ path = fs.combine(\"User/Apps/\"..tasks[currentTask].path..\"/Data\",path)\ end\ return oldName(path)\ end\ \ fs.getDir = function(path)\ \009\009if checkStoragePath(path) then\ \009\009\009path = fs.combine(\"/User/Storage\",string.sub(path,string.find(path,\"#Storage\")+8))\ \009\009elseif checkResourcesPath(path) then\ \009\009\009path = fs.combine(\"/System/Media\",string.sub(path,string.find(path,\"#SysRes\")+7))\ \009\009elseif checkTempPath(path) then\ \009\009\009path = fs.combine(\"/Temp\",string.sub(path,string.find(path,\"#tmp\")+4))\ elseif tasks[currentTask] and not tasks[currentTask].running and tasks[currentTask].access > 1 then\ path = fs.combine(\"User/Apps/\"..tasks[currentTask].path..\"/Data\",path)\ end\ return oldGDir(path)\ end\ \ fs.isReadOnly = function(path)\ \009\009if checkStoragePath(path) then\ \009\009\009path = fs.combine(\"/User/Storage\",string.sub(path,string.find(path,\"#Storage\")+8))\ \009\009elseif checkResourcesPath(path) then\ \009\009\009path = \"/rom/startup.lua\"\ \009\009elseif checkTempPath(path) then\ \009\009\009path = fs.combine(\"/Temp\",string.sub(path,string.find(path,\"#tmp\")+4))\ elseif tasks[currentTask] and not tasks[currentTask].running and tasks[currentTask].access > 1 then\ path = fs.combine(\"User/Apps/\"..tasks[currentTask].path..\"/Data\",path)\ end\ return oldReadOnly(path)\ end\ \ \009os.loadAPI = function(_sPath)\ \009\009if not _sPath:sub(1,1) ~= \"/\" and not (_sPath:sub(1,4) == \"#API\" or _sPath:sub(1,5) == \"/#API\" or _sPath:sub(1,6) == \"//#API\") then\ \009\009\009_sPath = fs.combine(\"#API\", _sPath)\ \009\009end\ \ \009\009if type( _sPath ) ~= \"string\" then\ error( \"bad argument #1 (expected string, got \" .. type( _sPath ) .. \")\", 2 )\ end\ local sName = fs.getName( _sPath )\ if sName:sub(-4) == \".lua\" or sName:sub(-4) == \".api\" or sName:sub(-4) == \".dll\" or sName:sub(-4) == \".lib\" then\ sName = sName:sub(1,-5)\ end\ if tAPIsLoading[sName] == true then\ printLog( \"API \"..sName..\" is already being loaded\" )\ return false\ end\ tAPIsLoading[sName] = true\ \ local tEnv = os.getEnvironment()\ setmetatable( tEnv, { __index = _G } )\ local fnAPI, err = loadfile( _sPath, tEnv )\ if fnAPI then\ local ok, err = pcall( fnAPI )\ if not ok then\ tAPIsLoading[sName] = nil\ \009\009\009\009printLog(\"API \"..sName..\" error: \"..err..\" | \".._sPath)\ \009\009\009\009error( err )\ return false\ end\ else\ tAPIsLoading[sName] = nil\ \009\009\009printLog(\"API \"..sName..\" error: \"..err..\" | \".._sPath)\ \009\009\009error( err )\ return false\ end\ \ local tAPI = {}\ for k,v in pairs( tEnv ) do\ if k ~= \"_ENV\" then\ tAPI[k] = v\ end\ end\ \ _G[sName] = tAPI\ tAPIsLoading[sName] = nil\ return true\ \009end\ \ \009os.unloadAPI = function( _sName )\ if type( _sName ) ~= \"string\" then\ error( \"bad argument #1 (expected string, got \" .. type( _sName ) .. \")\", 2 )\ end\ if _sName ~= \"_G\" and type(_G[_sName]) == \"table\" then\ _G[_sName] = nil\ end\ \009end\ \ \009oldLoadAPI(\"/System/APIs/screenworks\")\ \009oldLoadAPI(\"/System/APIs/images\")\ \009oldLoadAPI(\"/System/APIs/advanced_read\")\ \ \009os.getSystemAPIs = function()\ \009\009return oldList(\"/System/APIs\")\ \009end\ \ \009os.getUserAPIs = function()\ \009\009return oldList(\"User/APIs\")\ \009end\ \ \009os.getAPIInfo = function(api)\ \009\009local info = {}\ \009\009local path\ \009\009if oldExist(\"/User/APIs/\"..api) then\ \009\009\009path = \"/User/APIs/\"..api\ \009\009elseif oldExist(\"/System/APIs/\"..api) then\ \009\009\009path = \"/System/APIs/\"..api\ \009\009\009info.systemAPI = true\ \009\009end\ \009\009if path then\ \009\009\009--local API = require(path)\ \009\009\009local API = oldOpen(path,\"r\")\ \009\009\009local line = API.readLine()\ \009\009\009if string.sub(line,1,2) == \"--\" then\ \009\009\009\009info.name = string.sub(line,3)\ \009\009\009else\ \009\009\009\009info.name = api\ \009\009\009end\ \009\009\009line = API.readLine()\ \009\009\009if string.sub(line,1,2) == \"--\" then\ \009\009\009\009info.version = string.sub(line,3)\ \009\009\009end\ \009\009\009API.close()\ \009\009\009info.size = oldSize(path)\ \009\009\009API = nil\ \ \009\009\009return info\ \009\009end\ \009end\ \ \009os.getOSinfo = function()\ \009\009local file = oldOpen(\"/System/Build.info\", \"r\")\ \009\009local about = textutils.unserialize(file.readAll())\ \009\009file.close()\ \009\009return about\ \009end\ \ -----------------------------------------------------------------\ printLog(\"Setting up OS API\")\ \ \009os.setBarColor = function(color)\ \009\009if tasks[currentTask] then\ \009\009\009tasks[currentTask].style = color\ \009\009end\ \009end\ \ \009os.sort = function(tbl)\ \009\009local tbl = tbl or {}\ \009\009table.sort(tbl)\ \009\009return tbl\ \009end\ \ \009local function getSize(path)\ \009\009local size = 0\ \009\009if oldDir(path) then\ \009\009\009local files = oldList(path)\ \009\009\009for i=1,#files do\ \009\009\009\009size = size + getSize(fs.combine(path, files[i]))\ \009\009\009end\ \009\009else\ \009\009\009size = size + oldSize(path)\ \009\009end\ \009\009return size\ \009end\ \ \009os.getAppInfo = function(app, get_Size)\ \009\009local path\ \009\009local system\ \009\009if oldExist(\"/User/Apps/\"..app) then\ \009\009\009path = \"/User/Apps/\"..app..\"/App.info\"\ \009\009elseif oldExist(\"/System/Apps/\"..app) then\ \009\009\009path = \"/System/Apps/\"..app..\"/App.info\"\ \009\009\009system = true\ \009\009end\ \009\009if path then\ \009\009\009local file = oldOpen(path, \"r\")\ \009\009\009local info\ \009\009\009if file then\ \009\009\009\009info = file.readAll()\ \009\009\009\009file.close()\ \009\009\009\009info = textutils.unserialize(info)\ \009\009\009\009if not info.name then\ \009\009\009\009\009info.name = app\ \009\009\009\009end\ \009\009\009else\ \009\009\009\009info = {}\ \009\009\009\009info.name = app\ \009\009\009end\ \009\009\009if not info.version then\ \009\009\009\009info.version = \"X.0\"\ \009\009\009end\ \009\009\009if not info.developer then\ \009\009\009\009info.developer = \"Unknown\"\ \009\009\009end\ \009\009\009if get_Size then\ \009\009\009\009info.size = getSize(string.sub(path,1,#path-8))\ \009\009\009\009if oldExist(fs.combine(string.sub(path,1,#path-8), \"Data\")) then\ \009\009\009\009\009info.dataSize = getSize(fs.combine(string.sub(path,1,#path-8), \"Data\"))\ \009\009\009\009else\ \009\009\009\009\009info.dataSize = 0\ \009\009\009\009end\ \009\009\009end\ \009\009\009info.systemApp = system\ \009\009\009return info\ \009\009end\ \009end\ \ \009local function getApps(path)\ \009\009local apps = oldList(path)\ \009\009local i = 1\ \009\009while apps[i] do\ \009\009\009local appInfo = os.getAppInfo(apps[i])\ \009\009\009if appInfo and appInfo.hidden then\ \009\009\009\009table.remove(apps,i)\ \009\009\009else\ \009\009\009\009i=i+1\ \009\009\009end\ \009\009end\ \009\009return apps\ \009end\ \ \009os.getSystemApps = function(withHidden)\ \009\009local apps\ \009\009if not withHidden then\ \009\009\009withHidden = true\ \009\009else\ \009\009\009withHidden = false\ \009\009end\ \009\009if withHidden then\ \009\009\009return getApps(\"/System/Apps\")\ \009\009else\ \009\009\009return oldList(\"/System/Apps\")\ \009\009end\ \009end\ \ \009os.getUserApps = function(withHidden)\ \009\009local apps\ \009\009if not withHidden then\ \009\009\009apps = getApps(\"/User/Apps\")\ \009\009else\ \009\009\009apps = oldList(\"/User/Apps\")\ \009\009end\ \009\009return apps\ \009end\ \ \009os.getAppsList = function(withHidden)\ \009\009local sysApps = os.getSystemApps(withHidden)\ \009\009local usrApps = os.getUserApps(withHidden)\ \ \009\009local pos = #sysApps\ \009\009local inc = 1\ \009\009local find\ \009\009for i=1,#usrApps do\ \009\009\009find = false\ \009\009\009for j=1,pos do\ \009\009\009\009if sysApps[j] == usrApps[i] then\ \009\009\009\009\009find = true\ \009\009\009\009\009break\ \009\009\009\009end\ \009\009\009end\ \009\009\009local appInfo = os.getAppInfo(usrApps[i])\ \009\009\009if find == false then\ \009\009\009\009sysApps[pos+inc] = usrApps[i]\ \009\009\009\009inc = inc + 1\ \009\009\009end\ \009\009end\ \ \009\009return os.sort(sysApps)\ \009end\ \ \009os.getRunningTasks = function()\ \009\009return tasks\ \009end\ \ \009os.getCurrentTask = function()\ \009\009return currentTask\ \009end\ \ \009os.getFloatingEnabled = function()\ \009\009return floatingEnabled\ \009end\ \ \009os.setFloatingEnabled = function(state)\ \009\009floatingEnabled = state\ \009\009settings.set(\"os.floatingEnabled\", state)\ \009\009settings.save(\"/.settings\")\ \009end\ \ \009os.getFloatingTime = function()\ \009\009return tonumber(floatingTime)\ \009end\ \ \009os.setFloatingTime = function(time)\ \009\009floatingTime = time\ \009\009settings.set(\"os.floatingTime\", time)\ \009\009settings.save(\"/.settings\")\ \009end\ \ os.pullEvent = function()\ \009local ev, side, x, y = os.pullEventRaw()\ \009if ev ~= \"terminate\" then\ \009\009return ev, side, x, y\ \009end\ end\ \ \009local function encrypt(password)\ \009 local new_password = \"\"\ \009 local step = 0\ \009 for i=1,#password do\ \009 step = step+string.byte(string.sub(password,i,i))\ \009 end\ \009\009step = math.floor(step/#password)\ \009 local char = \"\"\ \ \009 for i=1,#password do\ \009 char = string.sub(password,i,i)\ \009 new_password = new_password..string.char(string.byte(char)+step)\ \009 end\ \ \009 return new_password\ \009end\ \ \009local function decrypt(password,code)\ \009 local new_password = \"\"\ \009 local step = 0\ \009 for i=1,#code do\ \009 step = step+string.byte(string.sub(code,i,i))\ \009 end\ \009\009step = math.floor(step/#code)\ \009 local char = \"\"\ \ \009 for i=1,#password do\ \009 char = string.sub(password,i,i)\ \009 new_password = new_password..string.char(string.byte(char)-step)\ \009 end\ \ \009 return new_password\ \009end\ \ \009os.printLog = function(txt, app)\ \009\009if not app then\ \009\009\009printLog(\"[\"..tasks[currentTask].path..\"] - \"..txt)\ \009\009else\ \009\009\009printLog(\"[\"..app..\"] - \"..txt)\ \009\009end\ \009end\ \ \009os.getLastLogMessage = function()\ \009\009return lastLogMsg\ \009end\ \ \009os.getSystemDelay = function()\ \009\009return ((delay > 0.05 and delay) or 0.05)\ \009end\ \ \009os.createAccount = function(userName,password)\ \009\009if not oldExist(\"/User/User.info\") and userName and password then\ \009\009\009printLog('Trying to create account \"'..userName..'\"')\ \009 local user = {}\ \009 user.name = userName\ \009\009\009os.setComputerLabel(userName)\ \009 user.password = encrypt(password)\ \009 local file = oldOpen(\"/User/User.info\", \"w\")\ \009 file.write(textutils.serialize(user))\ \009 file.close()\ \009 return true\ \009 end\ \009end\ \ \009os.changePassword = function(oldPassword,newPassword)\ \009\009if oldExist(\"/User/User.info\") and oldPassword and newPassword then\ \009\009\009printLog('Trying to change account password')\ \009 local user = {}\ \009 user.name = \"\"\ \009 user.password = encrypt(newPassword)\ \ \009 local file = oldOpen(\"/User/User.info\", \"r\")\ \009 file = textutils.unserialize(file.readAll())\ \ \009 if decrypt(file.password,oldPassword) == oldPassword then\ \009 user.name = file.name\ \009 file = oldOpen(\"/User/User.info\", \"w\")\ \009 file.write(textutils.serialize(user))\ \009 file.close()\ \009\009\009\009printLog(\"Success\")\ \009 return true\ \009 end\ \009 end\ \009end\ \ \009os.changeName = function(password,newName)\ \009\009if oldExist(\"/User/User.info\") and password and newName then\ \009\009\009printLog('Trying to change account name to \"'..newName..'\"')\ \009 local user = {}\ \009 user.name = newName\ \009\009\009os.setComputerLabel(newName)\ \009 user.password = \"\"\ \ \009 local file = oldOpen(\"/User/User.info\", \"r\")\ \009 file = textutils.unserialize(file.readAll())\ \ \009 if decrypt(file.password,password) == password then\ \009 user.password = file.password\ \009 file = oldOpen(\"/User/User.info\", \"w\")\ \009 file.write(textutils.serialize(user))\ \009 file.close()\ \009\009\009\009printLog(\"Success\")\ \009 return true\ \009 end\ \009 end\ \009end\ \ \009os.verifyAccaunt = function(password)\ \009\009if oldExist(\"/User/User.info\") and password then\ \009\009\009printLog('Trying to verify account')\ \009 local file = oldOpen(\"/User/User.info\", \"r\")\ \009 local inf = textutils.unserialize(file.readAll())\ \009\009\009file.close()\ \ \009 if decrypt(inf.password,password) == password then\ \009\009\009\009printLog(\"Success\")\ \009 return true\ \009 end\ \009 end\ \009end\ \ \009os.getImageSize = function(path)\ \009\009local file = fs.open(path, \"r\")\ \009\009local image = file.readLine()\ \009\009local sizeX, sizeY = 0, 0\ \009\009while image do\ \009\009\009sizeY = sizeY+1\ \009\009\009if sizeX < #image then\ \009\009\009\009sizeX = #image\ \009\009\009end\ \009\009\009image = file.readLine()\ \009\009end\ \009\009file.close()\ \009\009return sizeX, sizeY\ \009end\ \ \009os.advancedRead = advanced_read.read\ \ \009read = function(char)\ \009\009local trm = term.current()\ \009\009local xSize = trm.getSize()\ \009\009local posX, posY = trm.getCursorPos()\ \009\009return os.advancedRead(trm, posX, posY, xSize-posX, nil, char)\ \009end\ \ \009os.getAppIcon = function(app)\ \009\009local path\ \009\009local img\ \009\009if oldExist(\"/User/Apps/\"..app) then\ \009\009\009path = \"/User/Apps/\"..app..\"/App.ico\"\ \009\009elseif oldExist(\"/System/Apps/\"..app) then\ \009\009\009path = \"/System/Apps/\"..app..\"/App.ico\"\ \009\009else\ \009\009\009path = \"/System/Media/Images/noicon.png\"\ \009\009end\ \009\009if path then\ \009\009\009local info = oldOpen(path, \"r\")\ \009\009\009if info then\ \009\009\009\009img = images.loadImage(info)\ \009\009\009\009info.close()\ \009\009\009\009return img\ \009\009\009end\ \009\009end\ \009end\ \ \009os.drawImage = images.draw\ \ \009os.sendNotification = function(icon,header,text,text2,btn_script)\ \009\009if tasks[currentRunningTask] and not tasks[currentRunningTask].silentMode then\ \009\009\009notifications[#notifications+1] = {\ \009\009\009\009icon = (icon or string.char(7)),\ \009\009\009\009header = (header or tasks[currentRunningTask].name),\ \009\009\009\009text = (text or \"\"),\ \009\009\009\009text2 = (text2 or \"\"),\ \009\009\009\009btn_script = btn_script,\ \009\009\009\009app = tasks[currentRunningTask].path,\ \009\009\009}\ \009\009\009os.queueEvent(\"system.sendNotification\", notifications[#notifications])\ \009\009else\ \009\009\009notifications[#notifications+1] = {\ \009\009\009\009icon = (icon or string.char(7)),\ \009\009\009\009header = (header or \"SystemUI\"),\ \009\009\009\009text = (text or \"\"),\ \009\009\009\009text2 = (text2 or \"\"),\ \009\009\009\009btn_script = btn_script,\ \009\009\009\009app = \"SystemUI\",\ \009\009\009}\ \009\009\009os.queueEvent(\"system.sendNotification\", notifications[#notifications])\ \009\009end\ \009end\ \ \009os.getNotifications = function()\ \009\009return (notifications or {})\ \009end\ \ \009os.removeNotification = function(num)\ \009\009if notifications[num] then\ \009\009\009os.queueEvent(\"system.removeNotification\", notifications[num], num)\ \009\009\009table.remove(notifications, num)\ \009\009end\ \009end\ \ \009os.clearNotifications = function()\ \009\009if #notifications > 0 then\ \009\009\009notifications = {}\ \009\009\009os.queueEvent(\"system.clearNotifications\")\ \009\009end\ \009end\ \ \009-----------------------------------------------------------------\ printLog(\"Setting up Environment\")\ \ \009shell.getRunningProgram = function()\ \009\009if tasks[currentTask].access > 1 then\ \009\009\009return tasks[currentTask].path..\"/Start.x\"\ \009\009else\ \009\009\009return \"/System/Apps/\"..tasks[currentTask].path..\"/Start.x\"\ \009\009end\ \009end\ \ \009shell.resolve = function(path)\ \009\009if tasks[currentTask].access > 1 then\ \009\009\009return fs.combine(\"/\",path)\ \009\009elseif tasks[currentTask].access <= 1 then\ \009\009\009return fs.combine(\"/System/Apps/\"..tasks[currentTask].path,path)\ \009\009end\ \009end\ \ \009shell.path = function()\ \009\009return oldPath\ \009end\ \ \009local securedEnv = {\ \009\009oldOpen = oldOpen,\ \009\009oldExist = oldExist,\ \009\009oldDel = oldDel,\ \009\009shell = shell,\ \009\009os = os,\ \009\009read = read,\ \009\009notifications = notifications,\ \009}\ \ sleep(2)\ end\ \ os.getLog = function()\ \009return logBuffer\ end\ \ os.getErrorBuffer = function()\ \009return errorBuffer\ end\ \ os.clearErrorBuffer = function()\ \009errorBuffer = nil\ end\ \ local shellS = shell\ \ os.getEnvironment = function()\ \009local nShell = shellS\ \009local nFS = fs\ \009local nOS = os\ \009local nRead = read\ \009local nNotif = notifications\ \ \009local env = {\ \009\009[\"shell\"] = nShell,\ \009\009fs = nFS,\ \009\009os = nOS,\ \009\009read = nRead,\ \009\009notifications = nNotif,\ \009}\ \009return env\ end\ \ bootScreen()\ parallel.waitForAny(splash,boot)\ origin.setPaletteColor(colors.cyan, 0.29, 0.6, 0.69)\ \ term.redirect(origin)\ origin.setBackgroundColor(colors.black)\ origin.clear()\ \ \ \ os.changeApp = function(name)\ \009if type(name) == \"string\" then\ \009\009for i=1,#tasks do\ \009\009\009if tasks[i].path == name then\ \009\009\009\009name = i\ \009\009\009\009break\ \009\009\009end\ \009\009end\ \009end\ \ \009os.queueEvent(\"system.changeApp\", name)\ end\ \ local function changeApp(name)\ \009if stockPalette then\ \009\009tasks[currentTask].palette = {}\ \009\009for name, color in pairs(stockPalette) do\ \009\009\009tasks[currentTask].palette[name] = {}\ \009\009\009tasks[currentTask].palette[name][1], tasks[currentTask].palette[name][2], tasks[currentTask].palette[name][3] = tasks[currentTask].screen.getPaletteColor(colors[name])\ \009\009end\ \009end\ \009tasks[currentTask].screen.setVisible(false)\ \ \009if tasks[name] then\ \009\009currentTask = name\ \009\009printLog('Trying to change app to \"'..tasks[name].path..'\"')\ \009\009os.applyColorPalette(tasks[currentTask].palette, tasks[currentTask].screen)\ \ \009\009tasks[currentTask].screen.redraw()\ \009\009term.redirect(tasks[currentTask].screen)\ \009\009tasks[currentTask].error = coroutine.resume(tasks[currentTask].coroutine, \"resume\")\ \009\009os.applyColorPalette(tasks[currentTask].palette, tasks[currentTask].screen)\ \009end\ end\ \ os.closeApp = function(name)\ \009if type(name)==\"string\" then\ \009\009for i=1,#tasks do\ \009\009\009if tasks[i].path == name then\ \009\009\009\009name = i\ \009\009\009\009break\ \009\009\009end\ \009\009end\ \009end\ \ \009printLog('Trying to close app \"'..tasks[name].path..'\"')\ \009os.queueEvent(\"system.closeApp\", name)\ \009os.applyColorPalette(currentPalette)\ end\ \ local function closeApp(name)\ \009if name > 1 and tasks[name] then\ \009\009local appPath = tasks[name].path\ \ \009\009os.applyColorPalette(currentPalette)\ \009\009if tasks[name].screen then\ \009\009\009tasks[name].screen.setVisible(false)\ \009\009end\ \009\009tasks[name].screen = nil\ \ \009\009if currentTask >= name then\ \009\009\009currentTask = currentTask - 1\ \009\009end\ \009\009os.applyColorPalette(currentPalette)\ \009\009tasks[#tasks] = nil\ \ \009\009printLog('App \"'..appPath..'\" closed')\ \009else\ \009\009printLog('Error, app \"'..appPath..'\" not found or attempt to close Launcher')\ \009end\ end\ \ os.runApp = function(name, args)\ \009if not name then\ \009\009return nil\ \009end\ \ \009local findApp\ \009local path\ \009local name = name\ \ \009printLog('Trying to run app \"'..name..'\"')\ \009if oldExist(\"User/Apps/\"..name) and oldDir(\"/User/Apps/\"..name) then\ \009\009findApp = 2\ \009\009path = \"/User/Apps/\"..name..\"/Start.x\"\ \009elseif oldExist(\"/System/Apps/\"..name) and oldDir(\"/System/Apps/\"..name) then\ \009\009findApp = 1\ \009\009path = \"/System/Apps/\"..name..\"/Start.x\"\ \009else\ \009\009printLog('['..name..']'..' - App not found')\ \009end\ \ \009for i=1,#tasks do\ \009\009if tasks[i].path == name then\ \009\009\009printLog('App \"'..name..'\" already running')\ \009\009\009os.changeApp(i)\ \009\009\009return nil\ \009\009end\ \009end\ \ \009printLog('['..name..']'..' - Access level: '..findApp)\ \009os.queueEvent(\"system.runApp\", {path = path, access = findApp, name = name}, args)\ end\ \ local function runApp(info, args)\ \009local error\ \009local path = info.path\ \009local findApp = info.access\ \009local name = info.name\ \ \009if findApp ~= nil then\ \009\009local function run()\ \009\009\009if not args then\ \009\009\009\009args = {}\ \009\009\009end\ \009\009\009term.redirect(tasks[currentTask].screen)\ \009\009\009tasks[currentTask].palette = currentPalette\ \ \009\009\009local taskNum = currentTask\ \009\009\009os.applyColorPalette(currentPalette, tasks[currentTask].screen)\ \ \009\009\009local env = os.getEnvironment()\ \009\009\009printLog('['..name..']'..\" - Trying to execute main file\")\ \009\009\009error = os.run(env, path, unpack(args))\ \ \009\009\009if error then\ \009\009\009\009printLog('Error in app \"'..name..'\": '..error)\ \009\009\009\009errorBuffer = {app = name, error = error}\ \009\009\009end\ \009\009\009printLog('App \"'..name..'\" had been terminated')\ \009\009\009for i=1,#tasks do\ \009\009\009\009if tasks[i].path == path then\ \009\009\009\009\009os.closeApp(i)\ \009\009\009\009\009break\ \009\009\009\009end\ \009\009\009end\ \009\009\009coroutine.yield()\ \009\009end\ \ \009\009local info = os.getAppInfo(name)\ \ \009\009tasks[#tasks+1] = {}\ \009\009currentTask = #tasks\ \009\009tasks[currentTask].name = info.name\ \009\009tasks[currentTask].path = name\ \ \009\009tasks[currentTask].screen = window.create(first, appPosX, appPosY, appSizeX, appSizeY)\ \ \009\009term.redirect(tasks[currentTask].screen)\ \009\009tasks[currentTask].coroutine = coroutine.create(run)\ \ \009\009tasks[currentTask].access = findApp\ \009\009tasks[currentTask].running = true\ \009\009term.redirect(tasks[currentTask].screen)\ \009\009tasks[currentTask].error = coroutine.resume(tasks[currentTask].coroutine, \"resume\")\ \009\009tasks[currentTask].running = nil\ \009\009if tasks[currentTask].coroutine and not error then\ \009\009\009printLog('['..name..']'..\" - Success\")\ \009\009\009term.redirect(tasks[currentTask].screen)\ \009\009\009if not tasks[currentTask].style then\ \009\009\009\009tasks[currentTask].style = term.getBackgroundColor()\ \009\009\009end\ \009\009\009tasks[currentTask].access = findApp\ \009\009end\ \009\009os.applyColorPalette(currentPalette, tasks[currentTask].screen)\ \009else\ \009\009printLog(\"Can't \"..'find app \"'..name..'\"')\ \009end\ end\ \ local function resetAppCursor()\ \009if tasks[currentTask] and tasks[currentTask].screen then\ \009\009local _x, _y\ \009\009local txColor, bgColor\ \ \009\009_x, _y = tasks[currentTask].screen.getCursorPos()\ \009\009txColor, bgColor = tasks[currentTask].screen.getTextColor(), tasks[currentTask].screen.getBackgroundColor()\ \ \009\009if _x and _y then\ \009\009\009origin.setCursorPos(_x, _y)\ \009\009\009origin.setTextColor(txColor)\ \009\009\009origin.setBackgroundColor(bgColor)\ \009\009end\ \009end\ end\ \ local function input()\ \009local event, side, x, y, z\ \ \009while true do\ \009\009currentRunningTask = nil\ \009\009press_mod = nil\ \009\009term.redirect(origin)\ \009\009event, side, x, y, z = os.pullEvent()\ \ \009\009if event == \"system.closeApp\" then\ \009\009\009if side ~= \"System UI\" and side > 1 then\ \009\009\009\009closeApp(side)\ \009\009\009\009term.redirect(origin)\ \009\009\009\009ui_state = coroutine.resume(ui_routine, event, side, x, y, z)\ \009\009\009end\ \009\009elseif event == \"system.runApp\" then\ \009\009\009runApp(side, x)\ \009\009\009term.redirect(origin)\ \009\009\009ui_state = coroutine.resume(ui_routine, event, side, x, y, z)\ \009\009elseif event == \"system.changeApp\" then\ \009\009\009changeApp(side)\ \009\009\009term.redirect(origin)\ \009\009\009ui_state = coroutine.resume(ui_routine, event, side, x, y, z)\ \009\009elseif event == \"system.sendNotification\" then\ \009\009\009term.redirect(origin)\ \009\009\009ui_state = coroutine.resume(ui_routine, event, side, x, y, z)\ \009\009elseif event == \"system.removeNotification\" then\ \009\009\009term.redirect(origin)\ \009\009\009ui_state = coroutine.resume(ui_routine, event, side, x, y, z)\ \009\009elseif event == \"system.clearNotifications\" then\ \009\009\009term.redirect(origin)\ \009\009\009ui_state = coroutine.resume(ui_routine, event, side, x, y, z)\ \009\009else\ \009\009\009term.redirect(origin)\ \009\009\009ui_state, press_mod = coroutine.resume(ui_routine, event, side, x, y, z)\ \009\009\009if ui_state and not did_mod and not press_mod and tasks[currentTask] and tasks[currentTask].screen then\ \009\009\009\009currentRunningTask = currentTask\ \009\009\009\009tasks[currentTask].screen.setVisible(true)\ \009\009\009\009term.redirect(tasks[currentTask].screen)\ \009\009\009\009coroutine.resume(tasks[currentTask].coroutine, event, side, x, y, z)\ \009\009\009\009resetAppCursor()\ \009\009\009end\ \009\009end\ \009end\ end\ \ local function updateApps()\ while allowBarDrawing do\ \009\009currentRunningTask = nil\ \009\009term.redirect(origin)\ \009\009ui_state = coroutine.resume(ui_routine, \"resume\")\ \009\009if ui_state and not did_mod and tasks[currentTask] and tasks[currentTask].screen then\ \009\009\009currentRunningTask = currentTask\ \009\009\009tasks[currentTask].screen.setVisible(true)\ \009\009\009term.redirect(tasks[currentTask].screen)\ \009\009\009coroutine.resume(tasks[currentTask].coroutine, \"resume\")\ \009\009end\ \009\009resetAppCursor()\ sleep(delay)\ end\ end\ \ ui_routine = coroutine.create(function()\ \009local path\ \009if oldExist(\"/User/Apps/\"..defaultUI) then\ \009\009path = \"/User/Apps/\"..defaultUI\ \009elseif oldExist(\"/System/Apps/\"..defaultUI) then\ \009\009path = \"/System/Apps/\"..defaultUI\ \009else\ \009\009printLog(\"Cant't boot. Unable to find System UI app\")\ \009\009errorBuffer = {app = \"System UI\", error = \"Unable to find System UI app\"}\ \009\009os.queueEvent(\"system.closeApp\", \"System UI\")\ \009end\ \009local err = os.run({setDidState = function(state) did_mod = state end}, path..\"/Start.x\")\ \009if err then\ \009\009if err then\ \009\009\009printLog('Error in app System UI: '..err)\ \009\009\009errorBuffer = {app = \"System UI\", error = err}\ \009\009\009os.queueEvent(\"system.closeApp\", \"System UI\")\ \009\009end\ \009\009printLog(\"System UI had been terminated\")\ \009end\ end)\ \ printLog(\"Trying to run System UI\")\ ui_state, appPosX, appPosY, appSizeX, appSizeY = coroutine.resume(ui_routine)\ appPosX, appPosY, appSizeX, appSizeY = appPosX or 1, appPosY or 1, appSizeX or xSize, appSizeY or ySize\ os.runApp(defaultLauncher)\ \ parallel.waitForAny(input,updateApps)", path = "System/Core.x", }, { text = "f37o37r37 07i87=87######################################################\ b7t07e07r07m07.07######################################################\ 07x07 07=07 07i07######################################################\ e37n37d37 07 07 07######################################################\ ########################################################################\ ########################################################################\ ########################################################################\ ########################################################################\ ########################################################################\ ########################################################################\ ########################################################################\ ########################################################################", path = "System/Media/Images/code_icon.png", }, { text = "\14970 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70\14907\ \13807\14307\14307\14307\14307\14307\14307\14307\14307\14307\14307\14307\14307\14307\14307\14307\14307\14307\14307\14307\14307\14307\14307\14307\14307\14307\14307\13307", path = "System/Media/Images/dialog_bottom.png", }, { text = "\14970 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70\14907", path = "System/Media/Images/dialog_middle.png", }, { text = " 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07\ 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07 07\ \14970 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70 70\14907", path = "System/Media/Images/dialog_top.png", }, { text = " 0f 0f 0f 0f 0f 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\ 1f>1f_1f 1f 1f 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00######\ 0f 0f 0f 0f 0f 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00#########\ 0f 0f 0f 0f 0f 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00#########\ 00 0f 0f 00 0f 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00#########\ 00 0f 0f 00 0f 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00############\ ### 0f 0f 00###### 00 00 00 00 00 00 00 00 00 00 00 00 00###############\ 00 00 00######### 00 00 00 00 00 00 00 00 00 00 00 00 00###############\ ################################################### 00##################\ ########################################################################\ ########################################################################\ ########################################################################", path = "System/Media/Images/exec_icon.png", }, { text = "\12800\12800\12800\15108\14880\12800\12800\12800\12800\12800\12800\12800\12800####################################\ \12800\12800\12800\14908\14980\12800\12800\12800\12800\12800\12800\12800\12800####################################\ \12800\12800\12800\14908\14980\12800\12800\12800\12800\12800\12800\12800\12800####################################\ \12800\13680\13908\14908\14980\13508\13280\12800\12800\12800\12800\12800\12800####################################\ \12800\12800\13080\14408\15980\12980\12800\12800\12800\12800\12800\12800\12800####################################\ \12800\14080\14080\14080\14080\14080\14080\12800\12800\12800\12800\12800\12800####################################\ ###########################################################################\ ###########################################################################\ ###########################################################################\ ###########################################################################\ ###########################################################################\ ###########################################################################\ ###################################################\ ###################################################\ ###################################################\ ###################################################\ ###################################################\ ###################################################", path = "System/Media/Images/load_icon.png", }, { text = "\12790\12790\12790\12790\12790\12790\ 90\14090\14090\14090\14090 90\ 90i90c90o90n90 90\ \12790\12790\12790\12790\12790\12790", path = "System/Media/Images/noicon.png", }, { text = "{\ name = \"Default\",\ \ newColors = {\ white = {0.94, 0.94, 0.94},\ orange = {0.949, 0.698, 0.2},\ magenta = {0.9, 0.5, 0.85},\ lightBlue = {0.6,0.7,0.95},\ yellow = {0.87,0.87,0.42},\ lime = {0.5,0.8,0.1},\ pink = {0.95,0.7,0.8},\ gray = {0.3,0.3,0.3},\ lightGray = {0.6,0.6,0.6},\ cyan = {0.3,0.6,0.7},\ purple = {0.7,0.4,0.9},\ blue = {0.2,0.4,0.8},\ brown = {0.5,0.4,0.3},\ green = {0.34,0.65,0.31},\ red = {0.8,0.3,0.3},\ black = {0.1,0.1,0.1},\ }\ }", path = "System/Media/ScreenSettings/1.info", }, { text = "{\ name = \"Legacy\",\ \ newColors = {\ white = {1, 1, 1},\ orange = {1, 0.64, 0.21},\ magenta = {0.91, 0.42, 0.95},\ lightBlue = {0.31, 0.75, 0.93},\ yellow = {0.97, 0.92, 0.34},\ lime = {0.38, 0.98, 0.39},\ pink = {0.96, 0.79, 0.8},\ gray = {0.35, 0.35, 0.35},\ lightGray = {0.74, 0.74, 0.74},\ cyan = {0.24,0.75,0.77},\ purple = {0.58, 0.47, 0.96},\ blue = {0.17, 0.39, 0.88},\ brown = {0.5, 0.34, 0.16},\ green = {0.15, 0.77, 0.29},\ red = {0.94, 0.19, 0.2},\ black = {0, 0, 0},\ }\ }", path = "System/Media/ScreenSettings/Advanced.info", }, { text = "{\ name = \"Shades of gray\",\ \ newColors = {\ white = {1, 1, 1},\ orange = {0.932, 0.932, 0.932},\ magenta = {0.865, 0.865, 0.865},\ lightBlue = {0.799, 0.799, 0.799},\ yellow = {0.732, 0.732, 0.732},\ lime = {0.666, 0.666, 0.666},\ pink = {0.599, 0.599, 0.599},\ gray = {0.532, 0.532, 0.532},\ lightGray = {0.466, 0.466, 0.466},\ cyan = {0.399, 0.399, 0.399},\ purple = {0.333, 0.333, 0.333},\ blue = {0.266, 0.266, 0.266},\ brown = {0.199, 0.199, 0.199},\ green = {0.133, 0.133, 0.133},\ red = {0.066, 0.066, 0.066},\ black = {0, 0, 0},\ }\ }", path = "System/Media/ScreenSettings/ShadesOfGray.info", }, { text = "{\ name = \"True white & black\",\ \ newColors = {\ white = {1, 1, 1},\ black = {0, 0, 0},\ }\ }", path = "System/Media/ScreenSettings/TrueWhiteBlack.info", }, { text = "local xSize, ySize = term.getSize()\ local centerX = math.floor(xSize/2)\ local centerY = math.floor(ySize/2)\ local origin = term.native()\ \ local clear = function(color)\ \009term.setBackgroundColor(color)\ \009term.clear()\ \009term.setCursorPos(1,1)\ end\ \ local text = function(string,xPos,yPos,trm)\ \009if not trm then\ \009\009trm = term\ \009end\ \009trm.setCursorPos(xPos,yPos)\ \009trm.write(string)\ end\ \ function init()\ term.redirect(term.native())\ clear(colors.white)\ term.setTextColor(colors.cyan)\ text(\"Legacy\",centerX-2,centerY)\ end\ \ function loop()\ origin.setPaletteColor(colors.cyan, 0.97, 0.97, 0.97) -- 1\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.92, 0.96, 0.96) -- 2\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.85, 0.92, 0.94) -- 3\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.78, 0.87, 0.9) -- 4\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.72, 0.83, 0.87) -- 5\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.65, 0.8, 0.85) -- 6\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.58, 0.76, 0.81) -- 7\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.5, 0.72, 0.78) -- 8\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.43, 0.67, 0.76) -- 9\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.36, 0.63, 0.72) -- 10\ sleep(0.1)\ \ origin.setPaletteColor(colors.cyan, 0.29, 0.6, 0.69) -- original\ sleep(0.3)\ \ origin.setPaletteColor(colors.cyan, 0.36, 0.63, 0.72) -- 10\ sleep(0.1)\ \ origin.setPaletteColor(colors.cyan, 0.43, 0.67, 0.76) -- 9\ sleep(0.1)\ \ origin.setPaletteColor(colors.cyan, 0.5, 0.72, 0.78) -- 8\ sleep(0.1)\ \ origin.setPaletteColor(colors.cyan, 0.58, 0.76, 0.81) -- 7\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.65, 0.8, 0.85) -- 6\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.72, 0.83, 0.87) -- 5\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.78, 0.87, 0.9) -- 4\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.85, 0.92, 0.94) -- 3\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.92, 0.96, 0.96) -- 2\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.97, 0.97, 0.97) -- 1\ sleep(0)\ end", path = "System/Media/bootanimation.lua", }, { text = "local xSize, ySize = term.getSize()\ local centerX = math.floor(xSize/2)\ local centerY = math.floor(ySize/2)\ local origin = term.native()\ \ local clear = function(color)\ \009term.setBackgroundColor(color)\ \009term.clear()\ \009term.setCursorPos(1,1)\ end\ \ local text = function(string,xPos,yPos,trm)\ \009if not trm then\ \009\009trm = term\ \009end\ \009trm.setCursorPos(xPos,yPos)\ \009trm.write(string)\ end\ \ function init()\ term.redirect(term.native())\ clear(colors.white)\ term.setTextColor(colors.cyan)\ text(\"Legacy\",centerX-2,centerY)\ end\ \ function loop()\ origin.setPaletteColor(colors.cyan, 0.97, 0.97, 0.97) -- 1\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.85, 0.92, 0.94) -- 3\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.72, 0.83, 0.87) -- 5\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.58, 0.76, 0.81) -- 7\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.43, 0.67, 0.76) -- 9\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.29, 0.6, 0.69) -- original\ sleep(0.3)\ \ origin.setPaletteColor(colors.cyan, 0.36, 0.63, 0.72) -- 10\ sleep(0.1)\ \ origin.setPaletteColor(colors.cyan, 0.43, 0.67, 0.76) -- 9\ sleep(0.1)\ \ origin.setPaletteColor(colors.cyan, 0.5, 0.72, 0.78) -- 8\ sleep(0.1)\ \ origin.setPaletteColor(colors.cyan, 0.58, 0.76, 0.81) -- 7\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.72, 0.83, 0.87) -- 5\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.78, 0.87, 0.9) -- 4\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.85, 0.92, 0.94) -- 3\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.97, 0.97, 0.97) -- 1\ sleep(0.3)\ \ term.redirect(term.native())\ clear(colors.white)\ text(\"| ^ - ^ |\",centerX-4,centerY)\ \ origin.setPaletteColor(colors.cyan, 0.97, 0.97, 0.97) -- 1\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.85, 0.92, 0.94) -- 3\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.72, 0.83, 0.87) -- 5\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.58, 0.76, 0.81) -- 7\ sleep(0.1)\ \ origin.setPaletteColor(colors.cyan, 0.58, 0.76, 0.81) -- 7\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.72, 0.83, 0.87) -- 5\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.85, 0.92, 0.94) -- 3\ sleep(0)\ \ origin.setPaletteColor(colors.cyan, 0.97, 0.97, 0.97) -- 1\ sleep(0.3)\ end", path = "System/Media/shutanimation.lua", }, { text = "local args = {...}\ \ if args[1] == \"changeName\" then\ term.write(\"Password: \")\ local name = \"\"\ local pass = read(\"*\")\ if os.verifyAccaunt(pass) then\ term.write(\"New name: \")\ name = read()\ print(\"\")\ local change = os.changeName(pass,name)\ if change then\ term.setTextColor(colors.green)\ print(\"Done\")\ else\ term.setTextColor(colors.red)\ print(\"Error\")\ end\ else\ term.setTextColor(colors.red)\ print(\"Incorrect password\")\ end\ sleep(0.5)\ end", path = "System/Scripts/account.lua", }, { text = "local args = {...}\ print(\"System image creator\")\ \ local check = 1\ local final_path = \"#tmp/sysimage.info\"\ \ local function backup(chto,vochto)\ print(\"Creating system image in \"..vochto)\ \ local Massiv2 = {}\ local function FileList(path)\ local Massiv = fs.list(path)\ print(path)\ if #Massiv==0 then\ local Massiv2Id = #Massiv2 + 1\ Massiv2[Massiv2Id] = {}\ Massiv2[Massiv2Id][\"path\"] = path\ else\ if check == 0 then\ for i=1,#Massiv do\ if fs.isDir(fs.combine(path, Massiv[i])) and (fs.combine(path, Massiv[i]) == \"Temp\" or fs.combine(path, Massiv[i]) == \"User/APIs\" or fs.combine(path, Massiv[i]) == \"User/Apps\" or fs.combine(path, Massiv[i]) == \"User/Storage\") then\ local Massiv2Id = #Massiv2 + 1\ Massiv2[Massiv2Id] = {}\ Massiv2[Massiv2Id][\"path\"] = fs.combine(path, Massiv[i])\ elseif fs.isDir(fs.combine(path, Massiv[i])) and fs.combine(path, Massiv[i]) ~= \"rom\" then\ FileList(fs.combine(path, Massiv[i]))\ elseif not fs.isDir(fs.combine(path, Massiv[i])) and fs.combine(path, Massiv[i]) ~= final_path then\ local Massiv2Id = #Massiv2 + 1\ Massiv2[Massiv2Id] = {}\ Massiv2[Massiv2Id][\"path\"] = fs.combine(path, Massiv[i])\ local file = fs.open(fs.combine(path, Massiv[i]),\"r\")\ Massiv2[Massiv2Id][\"text\"] = file.readAll()\ file.close()\ end\ end\ elseif check == 1 then\ for i=1,#Massiv do\ if fs.isDir(fs.combine(path, Massiv[i])) and fs.combine(path, Massiv[i]) == \"Temp\" then\ local Massiv2Id = #Massiv2 + 1\ Massiv2[Massiv2Id] = {}\ Massiv2[Massiv2Id][\"path\"] = fs.combine(path, Massiv[i])\ elseif fs.isDir(fs.combine(path, Massiv[i])) and fs.combine(path, Massiv[i]) ~= \"rom\"then\ FileList(fs.combine(path, Massiv[i]))\ elseif not fs.isDir(fs.combine(path, Massiv[i])) and fs.combine(path, Massiv[i]) ~= final_path then\ local Massiv2Id = #Massiv2 + 1\ Massiv2[Massiv2Id] = {}\ Massiv2[Massiv2Id][\"path\"] = fs.combine(path, Massiv[i])\ local file = fs.open(fs.combine(path, Massiv[i]),\"r\")\ Massiv2[Massiv2Id][\"text\"] = file.readAll()\ file.close()\ end\ end\ end\ end\ end\ \ FileList(chto)\ file=fs.open(vochto,\"w\")\ file.write(textutils.serialise(Massiv2))\ file.close()\ return Massiv2\ end\ \ if args then\ \009for i=1,#args do\ \009\009if args[i] == '--system-only' or args[i] == '-s' then\ \009\009\009check = 0\ elseif args[i] == '--all-data' or args[i] == '-a' then\ \009\009\009check = 1\ else\ final_path = args[i]\ \009\009end\ \009end\ \ backup(\"/\", final_path)\ else\ print(\" Arguments: --system-only (-s), --all-data (-a)\")\ print(\" Usage: <output path> [arguments]\")\ end", path = "System/Scripts/createSystemImage.lua", }, { text = "local logBuffer = os.getLog()\ local startFrom = 1\ if #logBuffer > 100 then\ startFrom = #logBuffer-99\ end\ \ term.setTextColor(colors.white)\ print(\"Log output:\")\ print(\"\")\ \ for i=startFrom, #logBuffer do\ term.setTextColor(colors.white)\ term.write(\"[\"..i..\"] \")\ term.setTextColor(logBuffer[i].color or colors.white)\ print(logBuffer[i].text)\ end", path = "System/Scripts/dmesg.lua", }, { text = "local args = {...}\ \ local path = place()\ local canRun = true\ \ local function getType(txt)\ local i = #txt\ while string.sub(txt,i,i) ~= \".\" and i > 0 do\ i=i-1\ end\ if i > 0 then\ txt = string.sub(txt,i+1)\ return txt\ else\ return \"nope#\"\ end\ end\ \ if args[1] then\ if string.sub(args[1],1,1) == \"/\" then\ path = args[1]\ elseif string.sub(args[1],1,2) == \"..\" then\ local i = #path\ while string.sub(path,i,i) ~= \"/\" and i > 0 do\ i=i-1\ end\ if i > 1 then\ path = string.sub(path,0,i)\ else\ path = \"/\"\ end\ args[1] = string.sub(args[1],3)\ path = fs.combine(path,args[1])\ else\ path = fs.combine(path,args[1])\ end\ \ if not fs.exists(path) then\ term.setTextColor(colors.red)\ print(\"Can't find \"..path)\ canRun = false\ elseif fs.exists(path) and not fs.isDir(path) then\ term.setTextColor(colors.red)\ print(path..\" not a directory\")\ canRun = false\ end\ end\ \ if canRun then\ local list = os.sort(fs.list(path))\ local sort = {}\ sort.dir = {}\ local sortWords = {}\ \ for i=1,#list do\ if fs.isDir(fs.combine(path,list[i])) then\ --term.setTextColor(colors.cyan)\ sort.dir[#sort.dir+1] = list[i]\ else\ --term.setTextColor(colors.white)\ local type = getType(list[i])\ if not sort[type] then\ sort[type] = {}\ end\ sort[type][#sort[type]+1] = list[i]\ local find = false\ for i=1,#sortWords do\ if sortWords[i] == type then\ find = true\ break\ end\ end\ if not find then\ sortWords[#sortWords+1] = type\ end\ end\ --print(list[i])\ end\ \ sortWords = os.sort(sortWords)\ sort.dir = os.sort(sort.dir)\ \ for i=1,#sortWords do\ sort[sortWords[i]] = os.sort(sort[sortWords[i]])\ end\ \ term.setTextColor(colors.cyan)\ for i=1,#sort.dir do\ print(sort.dir[i])\ end\ \ for i=1,#sortWords do\ if sortWords[i] == \"x\" or sortWords[i] == \"lua\" or sortWords[i] == \"exe\" or sortWords[i] == \"sh\" then\ term.setTextColor(colors.orange)\ elseif sortWords[i] == \"txt\" or sortWords[i] == \"info\" or sortWords[i] == \"cfg\" or sortWords[i] == \"m\" or sortWords[i] == \"ini\" or sortWords[i] == \"inf\" then\ term.setTextColor(colors.yellow)\ elseif sortWords[i] == \"png\" or sortWords[i] == \"skch\" or sortWords[i] == \"nfp\" or sortWords[i] == \"nft\" or sortWords[i] == \"ico\" then\ term.setTextColor(colors.lightBlue)\ elseif sortWords[i] == \"mp3\" or sortWords[i] == \"wav\" or sortWords[i] == \"ogg\" or sortWords[i] == \"flac\" or sortWords[i] == \"sspro\" then\ term.setTextColor(colors.brown)\ else\ term.setTextColor(colors.white)\ end\ \ for j=1,#sort[sortWords[i]] do\ print(sort[sortWords[i]][j])\ end\ end\ \ end", path = "System/Scripts/ls.lua", }, { text = "local args = {...}\ \ if args[1] then\ os.runApp(\"PacketManager\", args)\ else\ local info = os.getAppInfo(\"PacketManager\")\ if info then\ print(\" \")\ print(info.name..\" version: \"..info.version)\ print(\" \")\ print(\"Arguments:\")\ print(\" install <path>\")\ print(\" remove <packet name>\")\ print(\" create <project folder> <output folder> <packet name>\")\ print(\" \")\ else\ print(\"Packet Manager not installed\")\ end\ end", path = "System/Scripts/pcm.lua", }, { text = "local args = {...}\ \ if args[1] then\ if fs.exists(args[1]) then\ if args[1]:sub(1,6) == \"System\" or args[1]:sub(1,7) == \"/System\" or args[1]:sub(1,8) == \"//System\" then\ print(\" This action may cause system failure. Are you sure you want to proceed?\")\ term.write(\"[y/N]: \")\ local ans = read()\ if ans ~= \"y\" and ans ~= \"Y\" then\ print(\" \")\ print(\" \")\ return nil\ end\ end\ fs.delete(args[1])\ print(args[1]..\" deleted\")\ print(\" \")\ else\ print(\"No such file or directory\")\ end\ else\ print(\"Usage: rm <path>\")\ end", path = "System/Scripts/rm.lua", }, { text = "local args = {...}\ \ if args[1] then\ local app = args[1]\ for i=1, #args do\ args[i] = args[i+1]\ end\ os.runApp(app, args)\ else\ print(\"Usage: run <app name> [argument1] [argument2] ...\")\ end", path = "System/Scripts/run.lua", }, { path = "Temp", }, { text = "--Benchmark Tests\ --1.2\ \ local text = function(string,xPos,yPos)\ \009term.setCursorPos(xPos,yPos)\ \009term.write(string)\ end\ \ local scrX, scrY = term.getSize()\ local centerX, centerY = math.floor(scrX/2), math.floor(scrY/2)\ local background = colors.black\ \ local clear = function()\ \009term.setBackgroundColor(background)\ \009term.clear()\ \009term.setCursorPos(1,1)\ end\ \ function test2d()\ \009local sizeX, sizeY = 10, 6\ \009local startX, startY = 40, 5\ \009local speed = 0.1\ \009local frame = 0\ \009local frameRate = 0\ \009local dir = 0\ \009local startSec = os.time()\ \009local endSec = 0\ \ \009local function ball()\ \009\009local x,y = math.random(scrX-sizeX), math.random(scrY-sizeY)\ \009\009local rot = 0\ \009\009if x < centerX then\ \009\009\009rot = 0\ \009\009else\ \009\009\009rot = math.pi\ \009\009end\ \ \009\009if y < centerY then\ \009\009\009rot = rot - math.pi/4\ \009\009else\ \009\009\009rot = rot + math.pi/4\ \009\009end\ \ \009\009endSec = os.time()\ \009\009while math.abs(startSec - endSec) < 0.1 do\ \009\009\009if x <= 1 then\ \009\009\009\009rot = math.pi/2+rot\ \009\009\009elseif x >= scrX-sizeX+1 then\ \009\009\009\009rot = -math.pi/2+rot\ \009\009\009elseif y <= 1 then\ \009\009\009\009rot = rot + math.pi/2\ \009\009\009elseif y >= scrY-sizeY+1 then\ \009\009\009\009rot = rot - math.pi/2\ \009\009\009end\ \ \009\009\009x = x + speed*math.cos(rot)\ \009\009\009y = y + speed*math.sin(rot)\ \ \009\009\009paintutils.drawFilledBox(x,y,x+sizeX,y+sizeY,colors.red)\ \009\009\009paintutils.drawFilledBox(x,y,x+sizeX,y+sizeY,colors.black)\ \009\009\009frame = frame + 1\ \009\009\009endSec = os.time()\ \009\009\009text('Rotation: '..rot,1,1)\ \009\009end\ \009end\ \ \009clear()\ \009parallel.waitForAny(ball)\ \009clear()\ \009endSec = os.time()\ \009frameRate = math.floor(frame / math.abs((startSec - endSec)*100))\ \009term.setBackgroundColor(colors.black)\ \009term.setTextColor(colors.white)\ \009text('FPS: '..frameRate,centerX-math.floor(5/2),centerY)\ \009sleep(2)\ \009return frameRate\ end\ \ function test3d()\ \009local sizeY, sizeZ = 14, 5\ \009local rot = 0\ \009local speed = math.pi/180\ \009local frame = 0\ \009local frameRate = 0\ \009local startSec = os.time()\ \009local endSec = 0\ \ \009local function redrawBox()\ \009\009clear()\ \009\009term.setBackgroundColor(colors.black)\ \009\009term.setTextColor(colors.white)\ \009\009text('Rotation: '..rot,1,1)\ \009\009local function drawSize(y,z,rd)\ \009\009\009local r = rot + rd\ \ \009\009\009paintutils.drawLine(centerX+y,z+centerY-sizeZ,centerX+y+sizeY*math.cos(r),z+centerY-sizeZ+(sizeY*math.sin(r))/3,colors.lightGray)\ \009\009\009paintutils.drawLine(centerX+y+sizeY*math.cos(r),z+centerY-sizeZ+(sizeY*math.sin(r))/3,centerX+y+sizeY*math.cos(r),z+centerY+sizeZ-(sizeY*math.sin(r))/3,colors.lightGray)\ \009\009\009paintutils.drawLine(centerX+y+sizeY*math.cos(r),z+centerY+sizeZ-(sizeY*math.sin(r))/3,centerX+y,z+centerY+sizeZ,colors.lightGray)\ \009\009\009paintutils.drawLine(centerX+y,z+centerY+sizeZ,centerX+y,z+centerY-sizeZ,colors.lightGray)\ \ \009\009\009paintutils.drawLine(centerX+y,z+centerY-sizeZ,centerX+y+sizeY*math.cos(r+math.pi/2),z+centerY-sizeZ+(sizeY*math.sin(r+math.pi/2))/3,colors.lightGray)\ \009\009\009paintutils.drawLine(centerX+y+sizeY*math.cos(r+math.pi/2),z+centerY-sizeZ+(sizeY*math.sin(r+math.pi/2))/3,centerX+y+sizeY*math.cos(r+math.pi/2),z+centerY+sizeZ-(sizeY*math.sin(r+math.pi/2))/3,colors.lightGray)\ \009\009\009paintutils.drawLine(centerX+y+sizeY*math.cos(r+math.pi/2),z+centerY+sizeZ-(sizeY*math.sin(r+math.pi/2))/3,centerX+y,z+centerY+sizeZ,colors.lightGray)\ \ \009\009\009paintutils.drawLine(centerX+y+sizeY*math.cos(r),z+centerY+sizeZ-(sizeY*math.sin(r))/3,centerX+y+sizeY*math.cos(r)+sizeY*math.cos(r+math.pi/2),z+centerY+sizeZ-(sizeY*math.sin(r))/3-(sizeY*math.sin(r+math.pi/2))/3,colors.lightGray)\ \009\009\009paintutils.drawLine(centerX+y+sizeY*math.cos(r),z+centerY-sizeZ+(sizeY*math.sin(r))/3,centerX+y+sizeY*math.cos(r)+sizeY*math.cos(r+math.pi/2),z+centerY-sizeZ+(sizeY*math.sin(r))/3+(sizeY*math.sin(r+math.pi/2))/3,colors.lightGray)\ \009\009\009paintutils.drawLine(centerX+y+sizeY*math.cos(r)+sizeY*math.cos(r+math.pi/2),z+centerY+sizeZ-(sizeY*math.sin(r))/3-(sizeY*math.sin(r+math.pi/2))/3,centerX+y+sizeY*math.cos(r+math.pi/2),z+math.floor(centerY+sizeZ-(sizeY*math.sin(r+math.pi/2))/3),colors.lightGray)\ \009\009\009paintutils.drawLine(centerX+y+sizeY*math.cos(r)+sizeY*math.cos(r+math.pi/2),z+centerY-sizeZ+(sizeY*math.sin(r))/3+(sizeY*math.sin(r+math.pi/2))/3,centerX+y+sizeY*math.cos(r+math.pi/2),z+centerY-sizeZ+(sizeY*math.sin(r+math.pi/2))/3,colors.lightGray)\ \009\009\009paintutils.drawLine(centerX+y+sizeY*math.cos(r)+sizeY*math.cos(r+math.pi/2),z+centerY-sizeZ+(sizeY*math.sin(r))/3+(sizeY*math.sin(r+math.pi/2))/3,centerX+y+sizeY*math.cos(r)+sizeY*math.cos(r+math.pi/2),z+centerY+sizeZ-(sizeY*math.sin(r))/3-(sizeY*math.sin(r+math.pi/2))/3,colors.lightGray)\ \009\009end\ \009\009drawSize(2,1,0)\ \009\009drawSize(2,1,math.pi)\ \009end\ \ \009redrawBox()\ \ \009local function run()\ \009\009endSec = os.time()\ \009\009while math.abs(startSec - endSec) < 0.08 do\ \009\009\009rot = rot + speed\ \009\009\009redrawBox()\ \009\009\009frame = frame + 1\ \009\009\009endSec = os.time()\ \009\009end\ \009end\ \ \009run()\ \009endSec = os.time()\ \ \009frameRate = math.floor(frame / math.abs((startSec - endSec)*100))\ \009clear()\ \009text('FPS: '..frameRate,centerX-math.floor(5/2),centerY)\ \009sleep(2)\ \009return frameRate\ end\ \ function testInt()\ \009local startSec = os.time()\ \009local endSec = 0\ \009local eps = 0\ \009local y = 0\ \009clear()\ \009text('Testing CPU...',centerX-6,centerY)\ \ \009endSec = os.time()\ \009while math.abs(startSec - endSec) < 0.09 do\ \009\009y = y + 1\ \009\009local function g()\ \009\009\009local m = y*4-y*2+y*6-y*4-y*2+y-y*3+y*1 +y*1-y*1+y*1-y*1+y*1-y*1\ \009\009\009return m\ \009\009end\ \009\009eps = g()\ \009\009endSec = os.time()\ \009end\ \ \009endSec = os.time()\ \009clear()\ \009text('Result: '..math.floor(eps/111),centerX-5,centerY)\ \009sleep(2)\ \009return math.floor(eps/111)\ end\ \ function testFloat()\ \009local startSec = os.time()\ \009local endSec = 0\ \009local eps = 0\ \009local y = 0\ \009clear()\ \009text('Testing FPU...',centerX-6,centerY)\ \ \009endSec = os.time()\ \009while math.abs(startSec - endSec) < 0.09 do\ \009\009y = y + 1\ \009\009local function g()\ \009\009\009local m = math.exp((y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)-(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y))*math.exp((y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)-(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y)*(y/y))/(y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y*y/y)\ \009\009\009return m\ \009\009end\ \009\009eps = g()*g()/g()*g()/g()*g()/g()*g()/g()*g()/g()\ \009\009endSec = os.time()\ \009end\ \ \009endSec = os.time()\ \009clear()\ \009text('Result: '..math.floor(1/eps),centerX-5,centerY)\ \009sleep(2)\ \009return math.floor(1/eps)\ end\ \ function testRAM()\ \009local t = {}\ \009local tab = {}\ \009local im, jm = 6000, 6000\ \009local startSec = os.time()\ \009local endSec = 0\ \009clear()\ \009text('Testing RAM...',centerX-5,centerY)\ \ \009endSec = os.time()\ \009local i = 1\ \ \009while math.abs(startSec - endSec) < 0.09 do\ \009\009tab[i] = t\ \009\009t[i] = tab[i]\ \009\009i = i + 1\ \009\009endSec = os.time()\ \009end\ \ \009endSec = os.time()\ \009clear()\ \009text('Result: '..math.floor(i/math.abs((startSec - endSec)*100)/42),centerX-5,centerY)\ \009sleep(2)\ \009return math.floor(i/math.abs((startSec - endSec)*100)/42)\ end", path = "User/APIs/tests", }, { text = "{\ _2d = 120,\ cpu = 9093,\ _3d = 65,\ fpu = 7185,\ ram = 5658,\ total = 26006,\ }", path = "User/Apps/3DBench/Data/myScore.info", }, { text = "{\ {\ name = \"Intel Xeon E5440 3.7GHz | 8GB DDR2\",\ score = 53207,\ },\ {\ name = \"Intel Xeon E5440 3.4GHz | 8GB DDR2\",\ score = 44615,\ },\ {\ name = \"Intel Pentium N4200 2.5GHz | 4GB DDR3\",\ score = 27724,\ },\ {\ name = \"MTK mt6737t 1.4GHz | 2GB LPDDR3\",\ score = 10000,\ },\ }", path = "User/Apps/3DBench/Data/scores.info", }, { text = "if os.getOSinfo() then\ \009os.loadAPI('#API/tests')\ \009os.setBarColor(colors.cyan)\ else\ \009os.loadAPI(\"/tests\")\ end\ \ local text = function(string,xPos,yPos)\ \009term.setCursorPos(xPos,yPos)\ \009term.write(string)\ end\ \ local scrX, scrY = term.getSize()\ local centerX, centerY = math.floor(scrX/2), math.floor(scrY/2)\ local background = colors.cyan\ local t3d = 0\ local t2d = 0\ local tCPU = 0\ local tFPU = 0\ local tRAM = 0\ local total = 0\ local page = 0\ local references\ \ --scrX = 26\ \ if fs.exists(\"myScore.info\") then\ \009local file = fs.open(\"myScore.info\", \"r\")\ \009local score = textutils.unserialize(file.readAll())\ \009file.close()\ \009t3d = score._3d\ \009t2d = score._2d\ \009tCPU = score.cpu\ \009tFPU = score.fpu\ \009tRAM = score.ram\ \009total = score.total\ end\ \ local clear = function()\ \009term.setBackgroundColor(background)\ \009term.clear()\ \009term.setCursorPos(1,1)\ end\ \ local function drawBar()\ \009paintutils.drawLine(1,1,scrX,1,colors.lightBlue)\ \009paintutils.drawLine(1,2,scrX,2,colors.lightBlue)\ \009term.setTextColor(colors.white)\ \009if page == 0 then\ \009\009text('Bench3D',1,1)\ \009elseif page == 1 then\ \009\009text(\"< Compare\", 1, 1)\ \009end\ end\ \ local function redraw()\ \009clear()\ \009drawBar()\ \009term.setTextColor(colors.white)\ \009term.setBackgroundColor(colors.cyan)\ \ \009total = math.floor(t2d*22+t3d*22+tCPU+tFPU+tRAM)\ \ \009if page == 0 then\ \009\009text('2D Score: '..(t2d*22)..' ('..t2d..' FPS)',2,4)\ \009\009text('3D Score: '..(t3d*22)..' ('..t3d..' FPS)',2,6)\ \009\009text('CPU Score: '..tCPU,2,8)\ \009\009text('FPU Score: '..tFPU,2,10)\ \009\009text('RAM Score: '..tRAM,2,12)\ \ \009\009text(\"Compare\", scrX/2-2, scrY-3)\ \009\009text('Total: '..total,scrX/2-#('Total: '..total)/2+1,scrY-1)\ \009\009paintutils.drawLine(scrX-5,scrY-2,scrX,scrY-2,colors.red)\ \009\009paintutils.drawLine(scrX-5,scrY,scrX,scrY,colors.red)\ \009\009text(' Exit ',scrX-5,scrY-1)\ \009\009paintutils.drawLine(1,scrY-2,7,scrY-2,colors.lightBlue)\ \009\009paintutils.drawLine(1,scrY,7,scrY,colors.lightBlue)\ \009\009text(' Start ',1,scrY-1)\ \009elseif page == 1 then\ \009\009if fs.exists(\"scores.info\") then\ \009\009\009local file = fs.open(\"scores.info\", \"r\")\ \009\009\009references = textutils.unserialize(file.readAll())\ \009\009\009file.close()\ \009\009end\ \009\009if references then\ \009\009\009-- for i=1, #references do\ \009\009\009-- \009for j=i+1, #references do\ \009\009\009-- \009\009if references[i].score > references[j].score then\ \009\009\009-- \009\009\009references[i], references[j] = references[j], references[i]\ \009\009\009-- \009\009end\ \009\009\009-- \009end\ \009\009\009-- end\ \ \009\009\009local yourPos\ \ \009\009\009for i=1, #references-1 do\ \009\009\009\009if total <= references[i].score and total > references[i+1].score then\ \009\009\009\009\009local j = #references\ \009\009\009\009\009while j > i do\ \009\009\009\009\009\009references[j+1] = references[j]\ \009\009\009\009\009\009j=j-1\ \009\009\009\009\009end\ \009\009\009\009\009references[i+1] = {name = string.char(7)..\" Your PC\", score = total}\ \009\009\009\009\009yourPos = i+1\ \009\009\009\009\009break\ \009\009\009\009elseif i == 1 and total >= references[i].score then\ \009\009\009\009\009local j = #references\ \009\009\009\009\009while j >= 1 do\ \009\009\009\009\009\009references[j+1] = references[j]\ \009\009\009\009\009\009j=j-1\ \009\009\009\009\009end\ \009\009\009\009\009references[1] = {name = string.char(7)..\" Your PC\", score = total}\ \009\009\009\009\009yourPos = 1\ \009\009\009\009\009break\ \009\009\009\009end\ \009\009\009end\ \ \009\009\009if not yourPos then\ \009\009\009\009references[#references+1] = {name = string.char(7)..\" Your PC\", score = total}\ \009\009\009\009yourPos = #references\ \009\009\009end\ \ \009\009\009local mult = (scrX-1)/references[1].score\ \ \009\009\009local function drawScore(i, ps)\ \009\009\009\009local clr = colors.lightBlue\ \009\009\009\009local txtClr = colors.white\ \009\009\009\009if i == yourPos then\ \009\009\009\009\009clr = colors.blue\ \009\009\009\009end\ \009\009\009\009term.setBackgroundColor(colors.cyan)\ \009\009\009\009term.setTextColor(txtClr)\ \009\009\009\009text(references[i].name, 2, 4*ps)\ \009\009\009\009text(references[i].score, scrX-#tostring(references[i].score), 4*ps)\ \009\009\009\009for k=2,math.floor((references[i].score*mult)/3) do\ \009\009\009\009\009paintutils.drawLine(2, 4*ps+1, k*3, 4*ps+1, clr)\ \009\009\009\009\009paintutils.drawLine(2, 4*ps+2, k*3, 4*ps+2, clr)\ \009\009\009\009\009sleep(0)\ \009\009\009\009end\ \009\009\009\009paintutils.drawLine(2, 4*ps+1, references[i].score*mult, 4*ps+1, clr)\ \009\009\009\009paintutils.drawLine(2, 4*ps+2, references[i].score*mult, 4*ps+2, clr)\ \009\009\009end\ \ \009\009\009-- text(yourPos, 2, 3)\ \009\009\009local pos = 1\ \ \009\009\009local function drawScores(from, to)\ \009\009\009\009for i=from, to do\ \009\009\009\009\009if references[i] then\ \009\009\009\009\009\009drawScore(i, pos)\ \009\009\009\009\009\009pos = pos+1\ \009\009\009\009\009end\ \009\009\009\009end\ \009\009\009end\ \ \009\009\009if yourPos == 1 then\ \009\009\009\009drawScores(yourPos, yourPos+3)\ \009\009\009elseif yourPos == #references then\ \009\009\009\009drawScores(yourPos-3, yourPos)\ \009\009\009else\ \009\009\009\009if yourPos > 2 then\ \009\009\009\009\009drawScores(yourPos-2, yourPos+2)\ \009\009\009\009else\ \009\009\009\009\009drawScores(yourPos-1, yourPos+3)\ \009\009\009\009end\ \009\009\009end\ \009\009end\ \009end\ end\ \ redraw()\ -- sleep(2)\ \ while true do\ \009local event, side, x, y = os.pullEvent()\ \009if event == 'mouse_click' then\ \009\009if page == 0 then\ \009\009\009if y == 4 then\ \009\009\009\009paintutils.drawLine(1,4,scrX,4,colors.lightBlue)\ \009\009\009\009text('2D Score: '..t2d*22,2,4)\ \009\009\009\009sleep(0.1)\ \009\009\009\009t2d = tests.test2d()\ \009\009\009\009redraw()\ \009\009\009elseif y == 6 then\ \009\009\009\009paintutils.drawLine(1,6,scrX,6,colors.lightBlue)\ \009\009\009\009text('3D Score: '..t3d*22,2,6)\ \009\009\009\009sleep(0.1)\ \009\009\009\009t3d = tests.test3d()\ \009\009\009\009redraw()\ \009\009\009elseif y == 8 then\ \009\009\009\009paintutils.drawLine(1,8,scrX,8,colors.lightBlue)\ \009\009\009\009text('CPU Score: '..tCPU,2,8)\ \009\009\009\009sleep(0.1)\ \009\009\009\009tCPU = math.floor(tests.testInt())\ \009\009\009\009redraw()\ \009\009\009elseif y == 10 then\ \009\009\009\009paintutils.drawLine(1,10,scrX,10,colors.lightBlue)\ \009\009\009\009text('FPU Score: '..tFPU,2,10)\ \009\009\009\009sleep(0.1)\ \009\009\009\009tFPU = math.floor(tests.testFloat())\ \009\009\009\009redraw()\ \009\009\009elseif y == 12 then\ \009\009\009\009paintutils.drawLine(1,12,scrX,12,colors.lightBlue)\ \009\009\009\009text('RAM Score: '..tRAM,2,12)\ \009\009\009\009sleep(0.1)\ \009\009\009\009tRAM = tests.testRAM()\ \009\009\009\009redraw()\ \009\009\009elseif x >= 1 and x <=7 and y >= scrY-2 and y <= scrY then\ \009\009\009\009paintutils.drawLine(1,scrY-2,7,scrY-2,colors.blue)\ \009\009\009\009paintutils.drawLine(1,scrY,7,scrY,colors.blue)\ \009\009\009\009text(' Start ',1,scrY-1)\ \009\009\009\009sleep(0.1)\ \009\009\009\009t2d = tests.test2d()\ \009\009\009\009clear()\ \009\009\009\009t3d = tests.test3d()\ \009\009\009\009redraw()\ \009\009\009\009tCPU = math.floor(tests.testInt())\ \009\009\009\009redraw()\ \009\009\009\009tFPU = math.floor(tests.testFloat())\ \009\009\009\009redraw()\ \009\009\009\009tRAM = tests.testRAM()\ \009\009\009\009redraw()\ \009\009\009\009total = math.floor(t2d*22+t3d*22+tCPU+tFPU+tRAM)\ \009\009\009\009local score = {}\ \009\009\009\009score._2d = t2d\ \009\009\009\009score._3d = t3d\ \009\009\009\009score.cpu = tCPU\ \009\009\009\009score.fpu = tFPU\ \009\009\009\009score.ram = tRAM\ \009\009\009\009score.total = total\ \009\009\009\009local file = fs.open(\"myScore.info\", \"w\")\ \009\009\009\009file.write(textutils.serialize(score))\ \009\009\009\009file.close()\ \009\009\009elseif x >= scrX-5 and x <=scrX and y >= scrY-2 and y <= scrY then\ \009\009\009\009paintutils.drawLine(scrX-5,scrY-2,scrX,scrY-2,colors.blue)\ \009\009\009\009paintutils.drawLine(scrX-5,scrY,scrX,scrY,colors.blue)\ \009\009\009\009text(' Exit ',scrX-5,scrY-1)\ \009\009\009\009sleep(0.1)\ \009\009\009\009background = colors.black\ \009\009\009\009clear()\ \009\009\009\009break\ \009\009\009elseif x >= scrX/2-4 and x <= scrX/2+4 and y == scrY-3 then\ \009\009\009\009page = 1\ \009\009\009\009redraw()\ \009\009\009end\ \009\009elseif page == 1 then\ \009\009\009if y == 1 then\ \009\009\009\009page = 0\ \009\009\009\009redraw()\ \009\009\009end\ \009\009end\ \009end\ end", path = "User/Apps/3DBench/Start.x", }, { text = " 03 03 03 03 03 03\ F03a03r03 03 03 03\ 00 00 00W30e30b30\ 00 00 00 00 00 00", path = "User/Apps/FarWeb/App.ico", }, { text = "<title>History</title><br><a href=\"https://vk.com\">????????? ?????? ?????????</a><br><a href=\"https://vk.com/settings?act=change_regional&hash=f6263fad7011d36bb8&lang_id=3\">???? | ?????????</a><br><a href=\"https://vk.com/settings?act=select_lang&to=aHR0cDovL3ZrLmNvbS9zZXR0aW5ncz9hY3Q9Y2hhbmdlX3JlZ2lvbmFsJmhhc2g9ZjYyNjNmYWQ3MDExZDM2YmI4JmxhbmdfaWQ9Mw--\">???? | ?????????</a><br><a href=\"https://vk.com\">????????? ?????? ?????????</a><br><a href=\"http://google.com\">Google</a><br><a href=\"https://plus.google.com/108954345031389568444\">Google ?????? - Google+</a><br><a href=\"https://goo.gl/fDRSYE\">Ghostbusters World - Apps on Google Play</a><br><a href=\"https://play.google.com/store/apps/category/MUSIC_AND_AUDIO\">?????????? ? Google Play ? ?????? ? ?????</a><br><a href=\"http://play.google.com\">Moved Permanently</a><br><a href=\"https://play.google.com/store\">Google Play</a><br><a href=\"https://m.vk.com\">????????? ?????? ?????????</a><br><a href=\"https://m.vk.com/settings?act=change_regional&hash=f6263fad7011d36bb8&lang_id=3\">???? | ?????????</a>", path = "User/Apps/FarWeb/Data/history.html", }, { text = "<title>FarWeb</title><body><h1 align=\"center\">Welcome</h1>This is a lightweight web browser for ComputerCraft. Of course it doesn`t support CCS or JavaScript and can`t show images, but it can show right html text.<p>Type link into input field to start.</p></body>", path = "User/Apps/FarWeb/Data/mainPage.html", }, { text = "\009--if os.isUtf(false) then\ \009\009--os.setUtf(true)\ \009--end\ \ \009--os.loadAPI(\"/System/API/sysbar\")\ \009os.loadAPI('contexts')\ \009--os.loadAPI('windows')\ \009local xSize, ySize = term.getSize()\ \009local xCenter = math.floor(xSize/2)\ \009local yCenter = math.floor(ySize/2)\ \009local index = 'FarWeb'\ \009local resPath = ''\ \009local mainPath = resPath..\"/mainPage.html\"\ \009local starterPage = 'file:'..resPath..'/mainPage.html'\ \009local history = {}\ \009local tags = {}\ \009local i = 0\ \009local file = nil\ \009local yPos = 1\ \009local lng = 0\ \009local pageIndex = 1\ \009history[1] = starterPage\ \009local webScreen = window.create(term.current(),1,3,xSize-1,ySize-2)\ \009--term.setFontName(\"unifont\")\ \009local screenSize = ySize-2\ \009local topBar = window.create(term.current(),1,1,xSize,2)\ \009local bottomBar = window.create(term.current(),1,ySize,xSize,1)\ \009local textAlign = 'left'\ \009local textColor = colors.black\ \009local links = {}\ \009local link = nil\ \009local buttons = {}\ \009local pos = 3\ \009local lenthScroll = 0\ \009local posScroll = 0\ \009local step = 0\ \009local header = false\ \009local inpFields = {}\ \ \009local clear = function(scr,color)\ \009\009scr.setBackgroundColor(color)\ \009\009scr.clear()\ \009\009scr.setCursorPos(1,1)\ \009end\ \ \009local text = function(str,x,y)\ \009\009term.setCursorPos(x,y)\ \009\009term.write(str)\ \009end\ \ \009local function scrollBar(count, size, pos, sizeStep, color2, color1)\ \009\009local lenthScroll = 0\ \009\009local posScroll = 0\ \009\009local lenthPage = 0\ \009\009local step = 0\ \009\009if color1 == nil then\ \009\009\009color1 = colors.white\ \009\009end\ \009\009if color2 == nil then\ \009\009\009color2 = colors.lightGray\ \009\009end\ \009\009paintutils.drawLine(xSize,3,xSize,ySize,color2)\ \009\009if count>0 then\ \009\009\009if count*size > ySize-3 then\ \009\009\009\009lenthPage = count*size\ \009\009\009\009lenthScroll = math.floor((ySize-2)/(lenthPage/(ySize-2)))\ \009\009\009\009step = ((ySize-3)-lenthScroll)/math.floor((lenthPage-(ySize-3))/sizeStep)\ \ \009\009\009else\ \009\009\009\009step = 0\ \009\009\009\009lenthScroll = ySize-2\ \009\009\009end\ \009\009else\ \009\009\009lenthScroll = ySize-2\ \009\009end\ \009\009paintutils.drawLine(xSize,3-pos,xSize,3+lenthScroll-pos,color1)\ \009\009return step\ \009end\ \ \009local textBar = function(str,x,y)\ \009\009topBar.setCursorPos(x,y)\ \009\009topBar.write(str)\ \009end\ \ \009local function textToTable(text)\ \009 local words = {}\ \009\009local pos = 1\ \ \009\009if #text > 1 then\ \009\009\009for i = 1, #text do\ \009\009\009\009if string.sub(text,i,i) ~= \" \" and string.sub(text,i,i) ~= '\\\ ' then\ \009\009\009\009\009if words[pos] == nil then\ \009\009\009\009\009\009words[pos] = \"\"\ \009\009\009\009\009end\ \009\009\009\009\009words[pos] = words[pos]..string.sub(text,i,i)\ \009\009\009\009elseif string.sub(text,i,i) == \"\\\ \" and not(string.sub(text,i-1,i-1) == string.sub(text,i,i)) then\ \009\009\009\009\009if pos > 1 then\ \009\009\009\009\009\009pos = pos + 1\ \009\009\009\009\009end\ \009\009\009\009\009words[pos] = string.sub(text,i,i)\ \009\009\009\009elseif string.sub(text,i,i) == \" \" then\ \009\009\009\009\009--if pos > 1 then\ \009\009\009\009\009\009--if string.sub(text,i-1,i-1) ~= nil and string.sub(text,i-1,i-1) ~= '' and string.sub(text,i-1,i-1) == \" \" then\ \009\009\009\009\009\009\009--words[pos] = ''\ \009\009\009\009\009\009if string.sub(text,i-1,i-1) ~= '' and string.sub(text,i-1,i-1) ~= \" \" then\ \009\009\009\009\009\009\009pos = pos + 1\ \009\009\009\009\009\009end\ \009\009\009\009\009--else\ \009\009\009\009\009--\009words[pos] = ' '\ \009\009\009\009\009--end\ \009\009\009\009end\ \009\009\009end\ \009\009elseif #text == 1 then\ \009\009\009if text ~= ' ' then\ \009\009\009\009words[1] = text\ \009\009\009end\ \009\009end\ \009\009if #words == 0 then\ \009\009\009words = nil\ \009\009end\ \009 return words\ \009end\ \ \009local function textPrinter(text,y,colorT,colorB,align,nl)\ \009\009if link then\ \009\009\009webScreen.setTextColor(colors.blue)\ \009\009elseif colorT then\ \009 webScreen.setTextColor(colorT)\ \009 end\ \009 if colorB then\ \009\009 webScreen.setBackgroundColor(colorB)\ \009 end\ \009 local words = textToTable(text)\ \009 local lines = {}\ \009\009if words then\ \ \009\009\009local pos = 0\ \009\009\009local gx, gy = webScreen.getCursorPos()\ \009\009\009local startLink = 0\ \009\009\009if nl == true then\ \009\009\009\009--if gy < y then\ \009\009\009\009\009--y = gy\ \009\009\009\009--end\ \009\009\009\009gx=gx-1\ \009\009\009\009pos = gx\ \009\009\009\009if align == 'center' then\ \009\009\009\009\009y=y+1\ \009\009\009\009\009gy=y\ \009\009\009\009\009pos = 1\ \009\009\009\009\009gx=0\ \009\009\009\009end\ \009\009\009else\ \009\009\009\009gx=0\ \009\009\009\009--gy=y\ \009\009\009\009y=y+1\ \009\009\009\009gy=y\ \009\009\009\009pos = 1\ \009\009\009end\ \ \009\009 local elms = 1\ \ \009\009 lines[1] = ''\ \009\009 for i=1, #words do\ \009\009\009\009if words[i] then\ \009\009\009\009\009pos = pos + #words[i]\ \009\009\009\009\009if words[i] == \"\\\ \" then\ \009\009\009\009\009\009elms = elms + 1\ \009\009\009 lines[elms] = \"\"\ \009\009\009 \009\009pos = 0\ \009\009\009\009\009elseif pos <= xSize-1 then\ \009\009\009\009\009\009lines[elms] = lines[elms]..words[i]..\" \"\ \009\009\009\009\009\009pos = pos+1\ \009\009\009\009\009else\ \009\009\009 --lines[elms] = string.sub(lines[elms],1,#lines[elms]-1)\ \009\009\009\009\009\009elms = elms + 1\ \009\009\009 lines[elms] = words[i]..\" \"\ \009\009\009 \009\009pos = #words[i]\ \009\009\009\009\009end\ \009\009\009\009end\ \009\009\009end\ \009\009\009local newLink = false\ \009\009\009if link then\ \009\009\009\009startLink = #links+1\ \009\009\009\009if not startLink then\ \009\009\009\009\009startLink = 1\ \009\009\009\009end\ \009\009\009\009if (links[startLink-1] and links[startLink-1]['href'] ~= link) or not links[startLink-1] then\ \009\009\009\009\009newLink = true\ \009\009\009\009--[[for i=1,#lines do\ \ \009\009\009\009end]]\ \009\009\009\009\009links[startLink] = {}\ \009\009\009\009\009links[startLink]['y1'] = y\ \009\009\009\009\009links[startLink]['x1'] = gx+1\ \009\009\009\009\009links[startLink]['href'] = link\ \009\009\009\009end\ \009\009\009end\ \ \009\009\009 if align == 'justify' then\ \009\009\009\009 \009local ps = gx+1\ \009\009\009 for i=1,#lines do\ \009\009\009 if #lines[i] < xSize-3-ps and #lines[i] > math.floor(xSize/2 + xSize/5) then\ \009\009\009 local j = 1\ \009\009\009 local space = 0\ \009\009\009 while j < #lines[i] and #lines[i] <= xSize-3 do\ \009\009\009 if j < #lines[i] and string.sub(lines[i],j,j) == ' ' then\ \009\009\009 lines[i] = string.sub(lines[i],1,j)..string.sub(lines[i],j,#lines[i])\ \009\009\009 j = j + 3 + space\ \009\009\009 else\ \009\009\009 j = j + 1\ \009\009\009 end\ \009\009\009 if j >= #lines[i] then\ \009\009\009 j = 1\ \009\009\009 space = space + 1\ \009\009\009 end\ \009\009\009 end\ \009\009\009 end\ \009\009\009\009\009\009\009\009ps = 0\ \009\009\009 end\ \009\009\009 end\ \ \009\009\009\009 for i=1, #lines do\ \009\009\009\009\009\009\009if header then\ \009\009\009\009\009\009\009\009lines[i] = string.upper(lines[i])\ \009\009\009\009\009\009\009end\ \009\009\009 if align == 'center' then\ \009\009\009 webScreen.setCursorPos(math.floor(xSize/2-#lines[i]/2)+1,i+y-1)\ \009\009\009 elseif align == 'right' then\ \009\009\009 webScreen.setCursorPos(xSize-#lines[i]+1,i+y-1)\ \009\009\009 else\ \009\009\009\009\009\009\009\009webScreen.setCursorPos(gx+1,i+y-1)\ \009\009\009\009\009\009\009\009gx = 0\ \009\009\009\009\009\009\009end\ \009\009\009\009\009 webScreen.write(lines[i])\ \009\009\009 end\ \009\009\009\009\009\009if nl == true then\ \009\009\009\009\009\009\009nl = 0\ \009\009\009\009\009\009else\ \009\009\009\009\009\009\009nl = 1\ \009\009\009\009\009\009end\ \009\009\009\009\009\009gx, gy = webScreen.getCursorPos()\ \009\009\009\009\009\009if link and newLink then\ \009\009\009\009\009\009\009links[startLink]['y2'] = gy\ \009\009\009\009\009\009\009links[startLink]['x2'] = gx\ \009\009\009\009\009\009end\ \009\009\009 return gy\ \009\009\009else\ \009\009\009\009local gx, gy = webScreen.getCursorPos()\ \009\009\009\009return gy\ \009\009\009end\ \009\009end\ \ \009local function drawInputField(size,type,value,br,input)\ \009\009local gx,gy = webScreen.getCursorPos()\ \009\009if br==false then\ \009\009\009gy = gy+1\ \009\009\009gx=1\ \009\009\009yPos = yPos+1\ \009\009end\ \009\009size = math.floor(size/2)\ \009\009webScreen.setBackgroundColor(colors.white)\ \009\009if input then\ \009\009\009webScreen.setTextColor(colors.lightBlue)\ \009\009else\ \009\009\009webScreen.setTextColor(colors.lightGray)\ \009\009end\ \009\009webScreen.setCursorPos(gx,gy)\ \009\009--[[webScreen.write(string.char(141))\ \009\009for i=2,size-1 do\ \009\009\009webScreen.write(string.char(140))\ \009\009end\ \009\009webScreen.write(string.char(142))]]\ \009\009webScreen.write(string.char(149))\ \009\009if value then\ \009\009\009if type == 'password' or type == 'passwd' then\ \009\009\009\009for i=1,#value do\ \009\009\009\009\009webScreen.write(string.char(7))\ \009\009\009\009end\ \009\009\009else\ \009\009\009\009webScreen.write(value)\ \009\009\009end\ \009\009end\ \009\009webScreen.setCursorPos(gx+size-1,gy)\ \009\009webScreen.write(string.char(149))\ \009\009webScreen.setCursorPos(gx+size,gy)\ \009\009if input == nil then\ \009\009\009inpFields[#inpFields+1] = {}\ \009\009\009inpFields[#inpFields]['type'] = type\ \009\009\009inpFields[#inpFields]['x1'] = gx\ \009\009\009inpFields[#inpFields]['x2'] = gx+size-1\ \009\009\009inpFields[#inpFields]['y'] = gy\ \009\009\009if value then\ \009\009\009\009inpFields[#inpFields]['value'] = value\ \009\009\009else\ \009\009\009\009inpFields[#inpFields]['value'] = ''\ \009\009\009end\ \009\009end\ \009end\ \ \009local drawBar = function()\ \009\009topBar.setBackgroundColor(colors.lightBlue)\ \009\009topBar.clear()\ \009\009topBar.setTextColor(colors.white)\ \009\009textBar(string.char(17)..' '..string.char(16),1,2)\ \009\009textBar(index,1,1)\ \009\009textBar('File',5,2)\ \009\009topBar.write(' Page')\ \009\009topBar.write(' History')\ \009\009topBar.setTextColor(colors.lightGray)\ \009\009if pageIndex == #history then\ \009\009\009textBar(string.char(16),3,2)\ \009\009end\ \009\009if pageIndex <= 1 then\ \009\009\009textBar(string.char(17),1,2)\ \009\009end\ \009\009topBar.setBackgroundColor(colors.white)\ \009\009topBar.setCursorPos(12,1)\ \009\009for i=12,xSize do\ \009\009\009topBar.write(' ')\ \009\009end\ \009\009textBar(history[pageIndex],13,1)\ \009\009if #history[pageIndex] > xSize-12 then\ \009\009\009topBar.setCursorPos(xSize-2,1)\ \009\009\009topBar.write('..')\ \009\009end\ \009\009topBar.setTextColor(colors.gray)\ \009\009textBar(string.char(26),xSize,1)\ \009end\ \ \009local drawBBar = function()\ \009\009bottomBar.setBackgroundColor(colors.white)\ \009\009bottomBar.clear()\ \009\009bottomBar.setTextColor(colors.red)\ \009\009bottomBar.setCursorPos(xSize,1)\ \009\009bottomBar.write('x')\ \009\009bottomBar.setTextColor(colors.gray)\ \009\009bottomBar.setCursorPos(1,1)\ \009\009bottomBar.write('Loading...')\ \009\009local percent = 0\ \009\009local x = 0\ \009\009while lng <= 0 do\ \009\009\009bottomBar.setCursorPos(12,1)\ \009\009\009bottomBar.write('-')\ \009\009\009sleep(0)\ \009\009\009bottomBar.setCursorPos(12,1)\ \009\009\009bottomBar.write(\"\\\\\")\ \009\009\009sleep(0)\ \009\009\009bottomBar.setCursorPos(12,1)\ \009\009\009bottomBar.write('|')\ \009\009\009sleep(0)\ \009\009\009bottomBar.setCursorPos(12,1)\ \009\009\009bottomBar.write('/')\ \009\009\009sleep(0)\ \009\009end\ \009\009while lng > 0 and percent < 100 do\ \009\009\009bottomBar.clear()\ \009\009\009percent = math.floor((i*100)/lng)\ \009\009\009x = (percent*xSize)/100\ \009\009\009bottomBar.setCursorPos(1,1)\ \009\009\009bottomBar.setTextColor(colors.lightBlue)\ \009\009\009bottomBar.setBackgroundColor(colors.white)\ \009\009\009for i=1,x do\ \009\009\009\009bottomBar.write(string.char(140))\ \009\009\009end\ \009\009\009bottomBar.setCursorPos(math.floor(xSize/2),1)\ \009\009\009bottomBar.write(percent..'%')\ \009\009end\ \009\009sleep(5)\ \009end\ \ \009local getCode = function(path)\ \009\009if string.sub(path,1,4) == 'http' then\ \009\009\009file = http.get(path)\ \009\009elseif string.sub(path,1,5) == 'file:' then\ \009\009\009file = fs.open(string.sub(path,6,#path),'r')\ \009\009else\ \009\009\009file = http.get('http://'..path)\ \009\009\009history[pageIndex] = 'http://'..path\ \009\009\009if not file or #file.readAll() == 0 then\ \009\009\009\009file = http.get('https://'..path)\ \009\009\009\009history[pageIndex] = 'https://'..path\ \009\009\009end\ \009\009\009drawBar()\ \009\009end\ \009\009if file then\ \009\009\009file = file.readAll()\ \009\009\009if string.sub(file,1,1) ~= '{' then\ \009\009\009\009lng = #file\ \009\009\009\009i = 1\ \009\009\009\009\009local attrIndex = 1\ \009\009\009\009\009local x = 1\ \009\009\009\009\009local y = 1\ \009\009\009\009\009local deep = 0\ \009\009\009\009\009local str = ''\ \009\009\009\009\009local tagName = ''\ \009\009\009\009\009local tagIndex = 1\ \009\009\009\009\009local attr = {}\ \009\009\009\009\009local tag = {}\ \009\009\009\009\009local text = ''\ \009\009\009\009\009local scriptCheck = false\ \009\009\009\009\009local styleCheck = false\ \009\009\009\009\009while i <= #file-1 do\ \009\009\009\009\009\009tag = {}\ \009\009\009\009\009\009if string.sub(file,i,i) == '<' then\ \009\009\009\009\009\009\009deep = deep + 1\ \009\009\009\009\009\009\009i = i+1\ \009\009\009\009\009\009\009local ended = false\ \009\009\009\009\009\009\009while string.sub(file,i,i) ~= ' ' do\ \009\009\009\009\009\009\009\009if string.sub(file,i,i) == '>' then\ \009\009\009\009\009\009\009\009\009ended = true\ \009\009\009\009\009\009\009\009\009break\ \009\009\009\009\009\009\009\009else\ \009\009\009\009\009\009\009\009\009tagName = tagName..string.sub(file,i,i)\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009i = i+1\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009tag['name'] = string.lower(tagName)\ \009\009\009\009\009\009\009if tagName == 'script' then\ \009\009\009\009\009\009\009\009scriptCheck = true\ \009\009\009\009\009\009\009elseif tagName == '/script' then\ \009\009\009\009\009\009\009\009scriptCheck = false\ \009\009\009\009\009\009\009elseif tagName == 'style' then\ \009\009\009\009\009\009\009\009styleCheck = true\ \009\009\009\009\009\009\009elseif tagName == '/style' then\ \009\009\009\009\009\009\009\009styleCheck = false\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009--sleep(0)\ \009\009\009\009\009\009\009if i == #file then\ \009\009\009\009\009\009\009\009tags[tagIndex] = tag\ \009\009\009\009\009\009\009\009break\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009if not scriptCheck and not styleCheck and not ended then\ \009\009\009\009\009\009\009\009while string.sub(file,i,i) ~= '>' do\ \009\009\009\009\009\009\009\009\009i = i+1\ \009\009\009\009\009\009\009\009\009while string.sub(file,i,i) ~= ' ' and string.sub(file,i,i) ~= '>' do\ \009\009\009\009\009\009\009\009\009\009str = ''\ \009\009\009\009\009\009\009\009\009\009while string.sub(file,i,i) ~= '=' and string.sub(file,i,i) ~= '>' and string.sub(file,i,i) ~= ' ' do\ \009\009\009\009\009\009\009\009\009\009\009str = str..string.sub(file,i,i)\ \009\009\009\009\009\009\009\009\009\009\009i = i+1\ \009\009\009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009\009\009local attrName = str\ \009\009\009\009\009\009\009\009\009\009--attr[attrIndex]['name'] = str\ \009\009\009\009\009\009\009\009\009\009str = ''\ \009\009\009\009\009\009\009\009\009\009\009if string.sub(file,i,i) == '=' then\ \009\009\009\009\009\009\009\009\009\009\009\009i = i+1\ \009\009\009\009\009\009\009\009\009\009\009\009if string.sub(file,i,i) == '\"' then\ \009\009\009\009\009\009\009\009\009\009\009\009\009i=i+1\ \009\009\009\009\009\009\009\009\009\009\009\009\009while string.sub(file,i,i) ~= '\"' do\ \009\009\009\009\009\009\009\009\009\009\009\009\009\009str = str..string.sub(file,i,i)\ \009\009\009\009\009\009\009\009\009\009\009\009\009\009i = i+1\ \009\009\009\009\009\009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009\009\009\009\009elseif string.sub(file,i,i) == \"'\" then\ \009\009\009\009\009\009\009\009\009\009\009\009\009i=i+1\ \009\009\009\009\009\009\009\009\009\009\009\009\009while string.sub(file,i,i) ~= \"'\" do\ \009\009\009\009\009\009\009\009\009\009\009\009\009\009str = str..string.sub(file,i,i)\ \009\009\009\009\009\009\009\009\009\009\009\009\009\009i = i+1\ \009\009\009\009\009\009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009\009\009\009\009i=i+1\ \009\009\009\009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009\009\009\009--attr[attrIndex]['value'] = str\ \009\009\009\009\009\009\009\009\009\009\009--attrIndex = attrIndex + 1\ \009\009\009\009\009\009\009\009\009\009\009attr[string.lower(attrName)] = str\ \009\009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009tag['attr'] = attr\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009end\ \009\009\009\009\009\009str = ''\ \009\009\009\009\009\009tags[tagIndex] = tag\ \009\009\009\009\009\009attr = {}\ \009\009\009\009\009\009str = ''\ \009\009\009\009\009\009attrIndex = 1\ \009\009\009\009\009\009tagIndex = tagIndex+1\ \009\009\009\009\009\009i=i+1\ \009\009\009\009\009\009if string.sub(file,i,i) ~= '<' then\ \009\009\009\009\009\009\009while string.sub(file,i,i) ~= '<' do\ \009\009\009\009\009\009\009\009if not scriptCheck and tagName ~= \"style\" then\ \009\009\009\009\009\009\009\009\009str = str..string.sub(file,i,i)\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009i = i+1\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009if not scriptCheck and not styleCheck then\ \009\009\009\009\009\009\009\009tags[tagIndex] = str\ \009\009\009\009\009\009\009\009str = ''\ \009\009\009\009\009\009\009\009tagIndex = tagIndex + 1\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009end\ \009\009\009\009\009\009tagName = ''\ \009\009\009\009\009end\ \009\009\009\009--[[local h = fs.open('/serPage.txt','w')\ \009\009\009\009h.write(textutils.serialize(tags))\ \009\009\009\009h.close()]]\ \009\009\009\009lng = 0\ \009\009\009else\ \009\009\009\009tags=textutils.unserialize(file)\ \009\009\009end\ \009\009else\ \009\009\009--windows.attention('Attention','Unable to load page')\ \009\009end\ \009end\ \ \009--[[local redraw = function()\ \009\009--clear(webScreen,colors.white)\ \009\009yPos = 1\ \009\009--webScreen.setBackgroundColor(colors.lightGray)\ \009\009--webScreen.clear()\ \009\009webScreen.write('n')\ \009\009local j = 1\ \009\009while j <= #tags do\ \009\009\009if type(tags[i]) == 'string' then\ \009\009\009\009local bPos = yPos\ \009\009\009\009webScreen.write('t')\ \009\009\009\009yPos = yPos + textPrinter(tags[j],bPos,textColor,colors.white,textAlign)\ \009\009\009\009j = j+1\ \009\009\009else\ \009\009\009\009webScreen.write('f')\ \009\009\009\009if tags[j]['name'] == 'title' then\ \009\009\009\009\009j=j+1\ \009\009\009\009\009title = tags[j]\ \009\009\009\009end\ \009\009\009\009j=j+1\ \009\009\009end\ \009\009end\ \009\009drawBar()\ \009end]]\ \ \009local function load()\ \009\009local function gtCode()\ \009\009\009tags = {}\ \009\009\009index = 'FarWeb'\ \009\009\009getCode(history[pageIndex])\ \009\009end\ \009\009local function stoper()\ \009\009\009while true do\ \009\009\009\009local event, side, x, y = os.pullEvent()\ \009\009\009\009if event == 'mouse_click' then\ \009\009\009\009\009if x == xSize and y == ySize then\ \009\009\009\009\009\009break\ \009\009\009\009\009end\ \009\009\009\009end\ \009\009\009end\ \009\009end\ \009\009parallel.waitForAny(gtCode,drawBBar,stoper)\ \009\009i = 0\ \009\009file = nil\ \009\009yPos = 1\ \009\009pos = 3\ \009\009posScroll = 0\ \009\009webScreen.reposition(1,pos)\ \009\009webScreen.setTextColor(colors.black)\ \009\009webScreen.setBackgroundColor(colors.white)\ \009\009webScreen.clear()\ \009\009local j = 1\ \009\009--lng = #tags\ \009\009link = nil\ \009\009links = {}\ \009\009buttons = {}\ \009\009inpFields = {}\ \009\009screenSize = ySize - 2\ \009\009yPos = 1\ \009\009webScreen.setCursorPos(1,1)\ \009\009local br = true\ \009\009local algTag = ''\ \009\009while #tags > 1 and j <= #tags do\ \009\009\009--webScreen.write(type(tags[j]))\ \009\009\009--sleep(0)\ \009\009\009if type(tags[j]) == 'string' and tags[j] ~= ' ' --[[and tags[j] ~= '\\\ ' ]]then\ \009\009\009\009--[[if link then\ \009\009\009\009\009textColor = colors.blue\ \009\009\009\009else\ \009\009\009\009\009textColor = colors.black\ \009\009\009\009end]]\ \009\009\009\009local oldP = yPos\ \009\009\009\009local oldx, oldy = webScreen.getCursorPos()\ \009\009\009\009yPos = textPrinter(tags[j],oldP,textColor,colors.white,textAlign,br)\ \009\009\009\009if yPos > screenSize then\ \009\009\009\009\009webScreen.reposition(1,3,xSize-1,yPos)\ \009\009\009\009\009webScreen.setCursorPos(oldx,oldy)\ \009\009\009\009\009textPrinter(tags[j],oldP,textColor,colors.white,textAlign,br)\ \009\009\009\009end\ \009\009\009\009br = true\ \009\009\009else\ \009\009\009\009if tags[j]['attr'] and tags[j]['attr']['align'] then\ \009\009\009\009\009textAlign = tags[j]['attr']['align']\ \009\009\009\009\009algTag = tags[j]['name']\ \009\009\009\009end\ \009\009\009\009if textAlign == 'center' then\ \009\009\009\009\009if tags[j]['name'] == '/'..algTag then\ \009\009\009\009\009\009textAlign = 'left'\ \009\009\009\009\009end\ \009\009\009\009end\ \009\009\009\009if tags[j]['name'] == 'title' then\ \009\009\009\009\009--j=j+1\ \009\009\009\009\009index = tags[j+1]\ \009\009\009\009\009j=j+1\ \009\009\009\009\009if not string.find(history[#history],resPath) and not string.find(history[#history],'file:') and pageIndex >= #history then\ \009\009\009\009\009\009local his = fs.open(resPath..'/history.html','r')\ \009\009\009\009\009\009if his then\ \009\009\009\009\009\009\009local txt = his.readAll()\ \009\009\009\009\009\009\009his.close()\ \009\009\009\009\009\009end\ \009\009\009\009\009\009if txt and txt~='' and string.sub(txt,1,6) == '<title' then\ \009\009\009\009\009\009\009txt = txt..'<br><a href=\"'..history[#history]..'\">'..index..'</a>'\ \009\009\009\009\009\009else\ \009\009\009\009\009\009\009txt = '<title>History</title><br><a href=\"'..history[#history]..'\">'..index..'</a>'\ \009\009\009\009\009\009end\ \009\009\009\009\009\009his = fs.open(resPath..'/history.html','w')\ \009\009\009\009\009\009his.write(txt)\ \009\009\009\009\009\009his.close()\ \009\009\009\009\009end\ \009\009\009\009elseif tags[j]['name'] == 'a' then\ \009\009\009\009\009if tags[j]['attr'] then\ \009\009\009\009\009\009if tags[j]['attr']['href'] then\ \009\009\009\009\009\009\009link = tags[j]['attr']['href']\ \009\009\009\009\009\009end\ \009\009\009\009\009end\ \009\009\009\009elseif tags[j]['name'] == '/a' then\ \009\009\009\009\009link = nil\ \009\009\009\009elseif tags[j]['name'] == 'br' or tags[j]['name'] == 'li' or tags[j]['name'] == 'tr' or tags[j]['name'] == 'div'then\ \009\009\009\009\009br = false\ \009\009\009\009elseif tags[j]['name'] == 'h1' or tags[j]['name'] == 'h2' or tags[j]['name'] == 'h3' or tags[j]['name'] == 'h4' then\ \009\009\009\009\009br = false\ \009\009\009\009\009header = true\ \009\009\009\009\009yPos = yPos+1\ \009\009\009\009elseif tags[j]['name'] == '/h1' or tags[j]['name'] == '/h2' or tags[j]['name'] == '/h3' or tags[j]['name'] == '/h4' then\ \009\009\009\009\009br = false\ \009\009\009\009\009header = false\ \009\009\009\009\009yPos = yPos+1\ \009\009\009\009elseif tags[j]['name'] == 'p' or tags[j]['name'] == '/p' then\ \009\009\009\009\009br = false\ \009\009\009\009\009yPos = yPos+1\ \009\009\009\009elseif tags[j]['name'] == 'input' then\ \009\009\009\009\009if tags[j]['attr'] and tags[j]['attr']['type'] and tags[j]['attr']['type']~='hidden' and (tags[j]['attr']['type'] == 'text' or tags[j]['attr']['type'] == 'password' or tags[j]['attr']['type'] == 'passwd' or tags[j]['attr']['type'] == 'email') then\ \009\009\009\009\009\009drawInputField(30,tags[j]['attr']['type'],tags[j]['attr']['value'],br)\ \009\009\009\009\009elseif not tags[j]['attr'] or not tags[j]['attr']['type'] then\ \009\009\009\009\009\009if tags[j]['attr'] then\ \009\009\009\009\009\009\009if tags[j]['attr']['value'] then\ \009\009\009\009\009\009\009\009drawInputField(30,'text',tags[j]['attr']['value'],br)\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009end\ \009\009\009\009\009elseif tags[j]['attr']['type'] == 'submit' then\ \009\009\009\009\009\009local gx,gy = webScreen.getCursorPos()\ \009\009\009\009\009\009if br == false then\ \009\009\009\009\009\009\009gx=1\ \009\009\009\009\009\009\009gy=gy+1\ \009\009\009\009\009\009\009yPos=yPos+1\ \009\009\009\009\009\009end\ \009\009\009\009\009\009buttons[#buttons+1] = {}\ \009\009\009\009\009\009buttons[#buttons]['type'] = tags[j]['attr']['type']\ \009\009\009\009\009\009buttons[#buttons]['y'] = gy\ \009\009\009\009\009\009buttons[#buttons]['x1'] = gx\ \009\009\009\009\009\009local texts = 'Submit'\ \009\009\009\009\009\009if tags[j]['attr']['value'] then\ \009\009\009\009\009\009\009texts = tags[j]['attr']['value']\ \009\009\009\009\009\009end\ \009\009\009\009\009\009webScreen.setBackgroundColor(colors.lightGray)\ \009\009\009\009\009\009webScreen.write(' '..texts..' ')\ \009\009\009\009\009\009webScreen.setBackgroundColor(colors.white)\ \009\009\009\009\009\009gx,gy = webScreen.getCursorPos()\ \009\009\009\009\009\009buttons[#buttons]['x2'] = gx\ \009\009\009\009\009end\ \009\009\009\009\009br = true\ \009\009\009\009elseif tags[j]['name'] == 'button' then\ \009\009\009\009\009local gx,gy = webScreen.getCursorPos()\ \009\009\009\009\009--[[if br then\ \009\009\009\009\009\009gx=1\ \009\009\009\009\009\009gy=gy+1\ \009\009\009\009\009\009yPos=yPos+1\ \009\009\009\009\009end]]\ \009\009\009\009\009buttons[#buttons+1] = {}\ \009\009\009\009\009if tags[j]['attr'] and tags[j]['attr']['type'] then\ \009\009\009\009\009\009buttons[#buttons]['type'] = tags[j]['attr']['type']\ \009\009\009\009\009end\ \009\009\009\009\009buttons[#buttons]['y'] = gy\ \009\009\009\009\009buttons[#buttons]['x1'] = gx\ \009\009\009\009\009local texts = ''\ \009\009\009\009\009j=j+1\ \009\009\009\009\009while tags[j]['name'] ~= '/button' do\ \009\009\009\009\009\009if type(tags[j]) == 'string' then\ \009\009\009\009\009\009\009texts = texts..tags[j]..' '\ \009\009\009\009\009\009end\ \009\009\009\009\009\009j = j+1\ \009\009\009\009\009end\ \009\009\009\009\009local oldP = yPos\ \009\009\009\009\009yPos = textPrinter(texts,oldP,textColor,colors.lightGray,textAlign,true)\ \009\009\009\009\009if yPos > screenSize then\ \009\009\009\009\009\009webScreen.reposition(1,3,xSize-1,yPos)\ \009\009\009\009\009\009textPrinter(texts,oldP,textColor,colors.lightGray,textAlign,true)\ \009\009\009\009\009end\ \009\009\009\009\009gx,gy = webScreen.getCursorPos()\ \009\009\009\009\009buttons[#buttons]['x2'] = gx\ \009\009\009\009\009br = true\ \009\009\009\009end\ \009\009\009end\ \009\009\009j=j+1\ \009\009end\ \009\009drawBar()\ \009end\ \ \009local running = function()\ \009\009while true do\ \009\009\009event, side, x, y = os.pullEvent()\ \009\009\009if event == \"mouse_click\" then\ \009\009\009\009if x <= 1 and y==2 and pageIndex > 1 then\ \009\009\009\009\009pageIndex = pageIndex - 1\ \009\009\009\009\009load()\ \009\009\009\009elseif x == 3 and y == 2 and pageIndex < #history then\ \009\009\009\009\009pageIndex = pageIndex + 1\ \009\009\009\009\009load()\ \009\009\009\009elseif x == xSize and y == 1 then\ \009\009\009\009\009load()\ \009\009\009\009elseif x >= 5 and x <= 8 and y == 2 then\ \009\009\009\009\009term.setBackgroundColor(colors.gray)\ \009\009\009\009\009term.setTextColor(colors.white)\ \009\009\009\009\009text(' File ',4,2)\ \009\009\009\009\009local fMenu = contexts.main(4,3,'Save Page','Exit')\ \009\009\009\009\009if fMenu == 'Save Page' then\ \009\009\009\009\009\009--[[if #tags > 0 then\ \009\009\009\009\009\009\009webScreen.redraw()\ \009\009\009\009\009\009\009topBar.redraw()\ \009\009\009\009\009\009\009local path = windows.input(math.floor(xSize/2-10),math.floor(ySize/2-3),'Save as',16,{\"Path\",\"\"})\ \009\009\009\009\009\009\009if path[1] > '' then\ \009\009\009\009\009\009\009\009local h = fs.open(path[1],'w')\ \009\009\009\009\009\009\009\009if h then\ \009\009\009\009\009\009\009\009\009h.write(textutils.serialize(tags))\ \009\009\009\009\009\009\009\009\009h.close()\ \009\009\009\009\009\009\009\009\009webScreen.redraw()\ \009\009\009\009\009\009\009\009\009topBar.redraw()\ \009\009\009\009\009\009\009\009\009windows.attention('Success','Page saved as '..path[1])\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009else\ \009\009\009\009\009\009\009windows.error('Nothing to save')\ \009\009\009\009\009\009end]]\ \009\009\009\009\009elseif fMenu == 'Exit' then\ \009\009\009\009\009\009break\ \009\009\009\009\009end\ \009\009\009\009elseif x >= 10 and x <= 13 and y == 2 then\ \009\009\009\009\009term.setBackgroundColor(colors.gray)\ \009\009\009\009\009term.setTextColor(colors.white)\ \009\009\009\009\009text(' Page ',9,2)\ \009\009\009\009\009local fMenu = contexts.main(9,3,'Undo','Redo','Reload')\ \009\009\009\009\009if fMenu == 'Reload' then\ \009\009\009\009\009\009webScreen.redraw()\ \009\009\009\009\009\009topBar.redraw()\ \009\009\009\009\009\009load()\ \009\009\009\009\009elseif fMenu == 'Undo' and pageIndex > 1 then\ \009\009\009\009\009\009pageIndex = pageIndex - 1\ \009\009\009\009\009\009load()\ \009\009\009\009\009elseif fMenu == 'Redo' and pageIndex < #history then\ \009\009\009\009\009\009pageIndex = pageIndex + 1\ \009\009\009\009\009\009load()\ \009\009\009\009\009end\ \009\009\009\009elseif x >= 15 and x <= 21 and y == 2 then\ \009\009\009\009\009term.setBackgroundColor(colors.gray)\ \009\009\009\009\009term.setTextColor(colors.white)\ \009\009\009\009\009text(' History ',14,2)\ \009\009\009\009\009pageIndex = pageIndex + 1\ \009\009\009\009\009if #history > pageIndex then\ \009\009\009\009\009\009for i=pageIndex+1,#history do\ \009\009\009\009\009\009\009history[i] = nil\ \009\009\009\009\009\009end\ \009\009\009\009\009end\ \009\009\009\009\009history[pageIndex] = 'file:'..resPath..'/history.html'\ \009\009\009\009\009sleep(0)\ \009\009\009\009\009webScreen.redraw()\ \009\009\009\009\009topBar.redraw()\ \009\009\009\009\009drawBar()\ \009\009\009\009\009load()\ \009\009\009\009elseif x >= 12 and x <= xSize-1 and y == 1 then\ \009\009\009\009\009topBar.setBackgroundColor(colors.white)\ \009\009\009\009\009topBar.setCursorPos(12,1)\ \009\009\009\009\009for i=12,xSize do\ \009\009\009\009\009\009topBar.write(' ')\ \009\009\009\009\009end\ \009\009\009\009\009topBar.setCursorPos(13,1)\ \009\009\009\009\009term.setBackgroundColor(colors.white)\ \009\009\009\009\009local inp = read()\ \009\009\009\009\009if inp and inp > '' then\ \009\009\009\009\009\009pageIndex = pageIndex + 1\ \009\009\009\009\009\009if #history > pageIndex then\ \009\009\009\009\009\009\009for i=pageIndex+1,#history do\ \009\009\009\009\009\009\009\009history[i] = nil\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009end\ \009\009\009\009\009\009history[pageIndex] = inp\ \009\009\009\009\009\009drawBar()\ \009\009\009\009\009\009load()\ \009\009\009\009\009else\ \009\009\009\009\009\009drawBar()\ \009\009\009\009\009end\ \009\009\009\009elseif y >= 3 then\ \009\009\009\009\009for i=1,#links do\ \009\009\009\009\009\009local lnk = false\ \009\009\009\009\009\009if links[i]['y1']==links[i]['y2'] then\ \009\009\009\009\009\009\009if x>=links[i]['x1'] and x<=links[i]['x2'] and y==links[i]['y1']+pos-1 then\ \009\009\009\009\009\009\009\009lnk = true\ \009\009\009\009\009\009\009\009f='1'\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009else\ \009\009\009\009\009\009\009if y>links[i]['y1']+pos-1 and y<links[i]['y2']+pos-1 then\ \009\009\009\009\009\009\009\009lnk = true\ \009\009\009\009\009\009\009\009f='2'\ \009\009\009\009\009\009\009elseif y==links[i]['y1']+pos-1 and x>=links[i]['x1'] then\ \009\009\009\009\009\009\009\009lnk = true\ \009\009\009\009\009\009\009\009f='3'\ \009\009\009\009\009\009\009elseif y==links[i]['y2']+pos-1 and x<=links[i]['x2'] then\ \009\009\009\009\009\009\009\009lnk = true\ \009\009\009\009\009\009\009\009f='4'\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009end\ \ \009\009\009\009\009\009--if (f1 and not(f2 or f3 or f4)) or (f2 and not(f1 or f3 or f4)) or (f3 and not (f1 or f2 or f3)) or (f4 and not(f1 or f2 or f3)) then\ \009\009\009\009\009\009if lnk then\ \009\009\009\009\009\009\009pageIndex = pageIndex + 1\ \009\009\009\009\009\009\009if #history > pageIndex then\ \009\009\009\009\009\009\009\009for i=pageIndex+1,#history do\ \009\009\009\009\009\009\009\009\009history[i] = nil\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009if string.sub(links[i]['href'],1,4) == 'http' then\ \009\009\009\009\009\009\009\009history[pageIndex] = links[i]['href']\ \009\009\009\009\009\009\009elseif string.sub(links[i]['href'],1,2) == '..' then\ \009\009\009\009\009\009\009\009local j = #history[pageIndex-1]\ \009\009\009\009\009\009\009\009while j > 1 do\ \009\009\009\009\009\009\009\009\009if string.sub(history[pageIndex-1],j,j) == '/' then\ \009\009\009\009\009\009\009\009\009\009break\ \009\009\009\009\009\009\009\009\009else\ \009\009\009\009\009\009\009\009\009\009j=j+1\ \009\009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009local prevPath = string.sub(links[i]['href'],1,j)\ \009\009\009\009\009\009\009\009history[pageIndex] = prevPath..links[i]['href']\ \009\009\009\009\009\009\009elseif string.sub(links[i]['href'],1,1) == '/' then\ \009\009\009\009\009\009\009\009local count = 0\ \009\009\009\009\009\009\009\009local pos = 0\ \009\009\009\009\009\009\009\009for j=1,#history[pageIndex-1] do\ \009\009\009\009\009\009\009\009\009if string.sub(history[pageIndex-1],j,j) == '/' then\ \009\009\009\009\009\009\009\009\009\009count = count + 1\ \009\009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009\009if count == 3 then\ \009\009\009\009\009\009\009\009\009\009pos = j\ \009\009\009\009\009\009\009\009\009\009break\ \009\009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009history[pageIndex] = string.sub(history[pageIndex-1],1,pos-1)..links[i]['href']\ \009\009\009\009\009\009\009else\ \009\009\009\009\009\009\009\009history[pageIndex] = history[pageIndex-1]..links[i]['href']\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009drawBar()\ \009\009\009\009\009\009\009load()\ \009\009\009\009\009\009\009break\ \009\009\009\009\009\009end\ \009\009\009\009\009end\ \009\009\009\009\009for i=1,#inpFields do\ \009\009\009\009\009\009if x>=inpFields[i]['x1'] and x<=inpFields[i]['x2'] and y==inpFields[i]['y']+pos-1 then\ \009\009\009\009\009\009\009local gx,gy = webScreen.getCursorPos()\ \009\009\009\009\009\009\009webScreen.setCursorPos(inpFields[i]['x1'],inpFields[i]['y'])\ \009\009\009\009\009\009\009drawInputField(30,nil,inpFields[i]['value'],true,true)\ \009\009\009\009\009\009\009webScreen.setTextColor(colors.lightGray)\ \009\009\009\009\009\009\009webScreen.setBackgroundColor(colors.white)\ \009\009\009\009\009\009\009term.setCursorPos(inpFields[i]['x1']+1,inpFields[i]['y']+pos-1)\ \009\009\009\009\009\009\009webScreen.setCursorPos(inpFields[i]['x1']+1,inpFields[i]['y'])\ \009\009\009\009\009\009\009for j=1,15-2 do\ \009\009\009\009\009\009\009\009webScreen.write(' ')\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009webScreen.setCursorPos(inpFields[i]['x1']+1,inpFields[i]['y'])\ \009\009\009\009\009\009\009if inpFields[i]['type'] == 'text' or inpFields[i]['type'] == 'email' then\ \009\009\009\009\009\009\009\009inpFields[i]['value'] = read()\ \009\009\009\009\009\009\009elseif inpFields[i]['type'] == 'password' or inpFields[i]['type'] == 'passwd' then\ \009\009\009\009\009\009\009\009inpFields[i]['value'] = read(string.char(7))\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009webScreen.setCursorPos(inpFields[i]['x1'],inpFields[i]['y'])\ \009\009\009\009\009\009\009drawInputField(30,nil,inpFields[i]['value'],true,false)\ \009\009\009\009\009\009\009webScreen.setCursorPos(gx,gy)\ \009\009\009\009\009\009\009webScreen.redraw()\ \009\009\009\009\009\009\009break\ \009\009\009\009\009\009end\ \009\009\009\009\009end\ \009\009\009\009end\ \009\009\009elseif event == 'mouse_scroll' then\ \009\009\009\009if step > 0 then\ \009\009\009\009\009if side == 1 and pos > -yPos+ySize-2 then\ \009\009\009\009\009\009posScroll = posScroll - step\ \009\009\009\009\009\009pos = pos - 1\ \009\009\009\009\009\009webScreen.reposition(1,pos)\ \009\009\009\009\009elseif side == -1 and pos < 3 then\ \009\009\009\009\009\009posScroll = posScroll +step\ \009\009\009\009\009\009pos = pos + 1\ \009\009\009\009\009\009webScreen.reposition(1,pos)\ \009\009\009\009\009\009if pos > 3 then\ \009\009\009\009\009\009\009pos = 3\ \009\009\009\009\009\009end\ \009\009\009\009\009end\ \009\009\009\009end\ \009\009\009end\ \009\009\009step = scrollBar(yPos,1,posScroll,1)\ \009\009\009webScreen.redraw()\ \009\009\009topBar.redraw()\ \009\009end\ \009end\ \ \009--redraw()\ \009step = scrollBar(yPos,1,posScroll,1)\ \009drawBar()\ \009webScreen.setBackgroundColor(colors.white)\ \009webScreen.clear()\ \009load()\ \009running()", path = "User/Apps/FarWeb/Start.x", }, { text = "\127e7\127e7\127e7\127e7\127e7\127e7\ \127e7\127e7\127e7\127e7\127e7\127e7\ 0e 0e 0e 0e 0e 0e\ 07 07 07 07 07 07", path = "User/Apps/Phoenix/App.ico", }, { text = "{\ name = \"Phoenix\",\ developer = \"DECE\",\ version = \"2.0\",\ }", path = "User/Apps/Phoenix/App.info", }, { text = " 05 05 05 05 05 05 05 05 05 05\ 05 05 05 05 05 05 05 05 05 05\ 05 05 05 05 05 05 05 05 05 05\ 05 05 05 05 05 05 05 05 05 05\ 05 05 05 05 05 05 05 05 05 05\ 05 05 05 05 05 05 05 05 05 05\ 05 05 05 05 05 05 05 05 05 05\ 05 05 05 05 05 05 05 05 05 05\ 05 05 05 05 05 05 05 05 05 05\ 05 05 05 05 05 05 05 05 05 05", path = "User/Apps/Phoenix/Data/gg.png", }, { text = "{\ {\ path = \"#Storage/PhoenixModules/size_brush.phm\",\ name = \"Resizable brush\",\ },\ {\ path = \"#Storage/PhoenixModules/shorter.phm\",\ name = \"Shortcuts\",\ },\ }", path = "User/Apps/Phoenix/Data/modules.cfg", }, { text = "local arg = {...}\ \ local text = function(string,xPos,yPos)\ \009term.setCursorPos(xPos,yPos)\ \009term.write(string)\ end\ \ local running = true\ \ local modules = {}\ local mainPath = shell.getRunningProgram()\ local accent_color = colors.red\ \ local cur_layer = 0\ local layers = {}\ local image = {}\ \ local main_menu = {\"Layers\", \"Chars\"}\ \ local scrX, scrY = term.getSize()\ local centerX, centerY = math.floor(scrX/2), math.floor(scrY/2)\ local background = colors.black\ local brushColor = 1\ local textColor = 1\ local charSet = \" \"\ local sX, sY = 1, 1\ local sizeX, sizeY = 1,0\ local startXSize, startYSize = 24, 12\ local posX, posY = centerX-math.floor(sizeX/2)+3, centerY-math.floor(sizeY/2)+1\ local obj = {}\ local layer = 1\ local select = false\ local showBar = true\ local saver = false\ local resizer = false\ local opener = false\ local charer = false\ local layerer = false\ local saveAs = \"\"\ local tool = \"B\"\ local fileType = \"png\"\ local empty_symbol = \"+\" --string.char(153)\ local newX = sizeX\ local newY = sizeY\ local splash = {\ \009'\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8',\ \009'\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8',\ \009'\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8',\ \009'\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8',\ \009'\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8',\ \009'\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8\127e8',\ \009' eep0eh0eo0ee0en0ei0ex0e ee ee ee ee ee ee ee ee ee ee ee ee ee ee ee eev0ee0er0e 0e20e.0e00e 0e',\ \009' e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8',\ \009' e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8',\ \009' e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8 e8',\ }\ \ local Colors = {\ \009[1] = \"0\",\ \009[2] = \"1\",\ \009[4] = \"2\",\ \009[8] = \"3\",\ \009[16] = \"4\",\ \009[32] = \"5\",\ \009[64] = \"6\",\ \009[128] = \"7\",\ \009[256] = \"8\",\ \009[512] = \"9\",\ \009[1024] = \"a\",\ \009[2048] = \"b\",\ \009[4096] = \"c\",\ \009[8192] = \"d\",\ \009[16384] = \"e\",\ \009[32768] = \"f\",\ }\ local ColorsB = {\ \009[\"0\"] = 1,\ \009[\"1\"] = 2,\ \009[\"2\"] = 4,\ \009[\"3\"] = 8,\ \009[\"4\"] = 16,\ \009[\"5\"] = 32,\ \009[\"6\"] = 64,\ \009[\"7\"] = 128,\ \009[\"8\"] = 256,\ \009[\"9\"] = 512,\ \009[\"a\"] = 1024,\ \009[\"b\"] = 2048,\ \009[\"c\"] = 4096,\ \009[\"d\"] = 8192,\ \009[\"e\"] = 16384,\ \009[\"f\"] = 32768,\ }\ \ local clear = function()\ \009term.setBackgroundColor(background)\ \009term.clear()\ \009term.setCursorPos(1,1)\ end\ \ local function newObj(name,x,y,sizeX,sizeY)\ \009obj[name] = {x1 = x, y1 = y, x2 = x+sizeX-1, y2 = y+sizeY-1}\ end\ \ local function moveObj(name,x,y)\ \009obj[name] = {x1 = x, y1 = y}\ \009obj[name].x2 = obj[name].x1+x\ \009obj[name].y2 = obj[name].y2+y\ end\ \ local function checkObj(name,x,y)\ \009if x>=obj[name].x1 and x<=obj[name].x2 and y>=obj[name].y1 and y<=obj[name].y2 then\ \009\009return true\ \009end\ end\ \ clear(background)\ \ local shadow = window.create(term.current(),posX+1,posY+1,sizeX,sizeY)\ shadow.setBackgroundColor(colors.black)\ shadow.setTextColor(colors.gray)\ shadow.clear()\ for i=1,sizeX-1 do\ \009shadow.setCursorPos(i,sizeY)\ \009shadow.write(string.char(131))\ end\ for i=1,sizeY-1 do\ \009shadow.setCursorPos(sizeX,i)\ \009shadow.write(string.char(149))\ end\ shadow.setCursorPos(sizeX,sizeY)\ shadow.write(string.char(129))\ \ local blackBackground = window.create(term.current(),posX,posY,sizeX+1,sizeY+1)\ \ local holst = window.create(term.current(),posX,posY,sizeX,sizeY)\ holst.setBackgroundColor(colors.white)\ holst.setTextColor(colors.lightGray)\ holst.clear()\ local function clear_holst()\ \009holst.setBackgroundColor(colors.white)\ \009holst.setTextColor(colors.lightGray)\ \009holst.clear()\ \009for i=1,sizeX do\ \009\009for j=1,sizeY do\ \009\009\009holst.setCursorPos(i,j)\ \009\009\009holst.write(empty_symbol)\ \009\009end\ \009end\ end\ clear_holst()\ \ local layer_bar = window.create(term.current(),scrX+1,1,8,scrY)\ layer_bar.setBackgroundColor(colors.gray)\ layer_bar.setTextColor(colors.lightGray)\ layer_bar.clear()\ layer_bar.setCursorPos(2,2)\ layer_bar.write(\"Layers\")\ layer_bar.setCursorPos(2,4)\ layer_bar.write(string.char(17)..\" 1\")\ layer_bar.setCursorPos(7,4)\ layer_bar.write(string.char(16))\ layer_bar.setCursorPos(2,scrY)\ layer_bar.setTextColor(colors.red)\ layer_bar.write(\"Remove\")\ layer_bar.setTextColor(accent_color)\ layer_bar.setCursorPos(2,6)\ layer_bar.write(\"Visible\")\ layer_bar.setTextColor(colors.lightGray)\ \ local bar = window.create(term.current(),1,1,3,scrY)\ bar.setBackgroundColor(colors.lightGray)\ bar.clear()\ \ local bar_color = window.create(term.current(),-4,1,4,scrY)\ bar_color.setBackgroundColor(colors.gray)\ bar_color.clear()\ for i=0,15 do\ \009bar_color.setCursorPos(2,i+2)\ \009bar_color.setBackgroundColor(2^i)\ \009bar_color.write(\" \")\ end\ bar_color.setBackgroundColor(colors.gray)\ bar_color.setTextColor(colors.lightGray)\ bar_color.setCursorPos(2,18)\ bar_color.write(\"--\")\ bar_color.setBackgroundColor(brushColor)\ bar_color.setTextColor(textColor)\ bar_color.setCursorPos(2,19)\ bar_color.write(charSet)\ bar_color.setBackgroundColor(textColor)\ bar_color.setCursorPos(3,19)\ bar_color.write(\" \")\ \ local bar_resize = window.create(term.current(),centerX-13,-9,26,9)\ bar_resize.setBackgroundColor(colors.gray)\ bar_resize.clear()\ bar_resize.setTextColor(colors.lightGray)\ bar_resize.setCursorPos(2,4)\ bar_resize.write(\"New X\")\ bar_resize.setCursorPos(2,6)\ bar_resize.write(\"New Y\")\ bar_resize.setCursorPos(12,2)\ bar_resize.write(\"Size\")\ bar_resize.setCursorPos(2,8)\ bar_resize.write(\"cancel\")\ bar_resize.setBackgroundColor(colors.lightGray)\ bar_resize.setTextColor(colors.gray)\ bar_resize.setCursorPos(8,4)\ bar_resize.write(\" \")\ bar_resize.setCursorPos(9,4)\ bar_resize.write(newX)\ bar_resize.setCursorPos(8,6)\ bar_resize.write(\" \")\ bar_resize.setCursorPos(9,6)\ bar_resize.write(newY)\ bar_resize.setCursorPos(18,8)\ bar_resize.write(\" resize \")\ newObj(\"btn_resize_\",centerX+5,8,8,1)\ \ local color_selector = window.create(bar_color,1,2,1,1)\ color_selector.setBackgroundColor(colors.gray)\ color_selector.clear()\ color_selector.setTextColor(accent_color)\ color_selector.write(string.char(149))\ \ local color_selectorT = window.create(bar_color,4,2,1,1)\ color_selectorT.setBackgroundColor(accent_color)\ color_selectorT.clear()\ color_selectorT.setTextColor(colors.gray)\ color_selectorT.write(string.char(149))\ \ bar.setTextColor(colors.gray)\ bar.setCursorPos(1,1)\ bar.write(string.char(17))\ bar.setCursorPos(2,2)\ bar.write(\"B\")\ newObj(\"B\",1,2,3,1)\ bar.setCursorPos(2,4)\ bar.write(\"E\")\ newObj(\"E\",1,4,3,1)\ bar.setCursorPos(2,6)\ bar.write(\"F\")\ newObj(\"F\",1,6,3,1)\ bar.setCursorPos(2,8)\ bar.write(\"M\")\ newObj(\"M\",1,8,3,1)\ \ bar.setCursorPos(2,9)\ bar.write(\"_\")\ \ bar.setCursorPos(2,11)\ bar.write(\"C\")\ newObj(\"btn_color\",1,11,3,1)\ \ bar.setCursorPos(2,13)\ bar.write(\"S\")\ newObj(\"btn_resize\",1,13,3,1)\ \ bar.setCursorPos(2,15)\ bar.write(string.char(24))\ bar.setCursorPos(2,16)\ bar.write(string.char(173))\ newObj(\"btn_open\",1,15,3,1)\ \ bar.setCursorPos(2,17)\ bar.write(string.char(25))\ newObj(\"btn_save\",1,17,3,1)\ \ bar.setTextColor(colors.red)\ bar.setCursorPos(2,scrY)\ bar.write(\"x\")\ newObj(\"btn_exit\",1,scrY,3,1)\ \ local selector = window.create(term.current(),1,2,1,1)\ selector.setBackgroundColor(colors.lightGray)\ selector.clear()\ selector.setTextColor(accent_color)\ selector.write(string.char(149))\ \ local save_bar = window.create(term.current(),centerX-13,-12,26,12)\ save_bar.setBackgroundColor(colors.gray)\ save_bar.clear()\ save_bar.setTextColor(colors.lightGray)\ save_bar.setCursorPos(11,2)\ save_bar.write(\"Save As\")\ save_bar.setCursorPos(2,11)\ save_bar.write(\"cancel\")\ save_bar.setBackgroundColor(colors.lightGray)\ save_bar.setCursorPos(1,4)\ save_bar.write(\" \")\ save_bar.setCursorPos(1,5)\ save_bar.write(\" \")\ save_bar.setCursorPos(1,6)\ save_bar.write(\" \")\ save_bar.setTextColor(colors.gray)\ save_bar.setCursorPos(2,5)\ if saveAs ~= \"\" then\ \009save_bar.write(saveAs)\ else\ \009save_bar.write(\"Path:\")\ end\ save_bar.setCursorPos(20,11)\ save_bar.write(\" save \")\ local function drawType()\ \009save_bar.setCursorPos(2,9)\ \009if fileType == \"png\" then\ \009\009save_bar.setBackgroundColor(accent_color)\ \009end\ \009save_bar.write(\" png \")\ \009save_bar.setBackgroundColor(colors.lightGray)\ \009save_bar.setCursorPos(8,9)\ \009if fileType == \"skch\" then\ \009\009save_bar.setBackgroundColor(accent_color)\ \009end\ \009save_bar.write(\" skch \")\ \009save_bar.setBackgroundColor(colors.lightGray)\ \009save_bar.setCursorPos(15,9)\ \009if fileType == \"nft\" then\ \009\009save_bar.setBackgroundColor(accent_color)\ \009end\ \009save_bar.write(\" nft \")\ \009save_bar.setBackgroundColor(colors.lightGray)\ \009save_bar.setCursorPos(21,9)\ \009if fileType == \"nfp\" then\ \009\009save_bar.setBackgroundColor(accent_color)\ \009end\ \009save_bar.write(\" nfp \")\ \009save_bar.setBackgroundColor(colors.lightGray)\ end\ drawType()\ newObj(\"btn_png\",centerX-11,8,5,3)\ newObj(\"btn_skch\",centerX-5,8,6,3)\ newObj(\"btn_nft\",centerX+2,8,5,3)\ newObj(\"btn_nfp\",centerX+8,8,5,3)\ newObj(\"btn_save_\",centerX+7,11,6,1)\ \ local open_bar = window.create(term.current(),centerX-13,-9,26,9)\ open_bar.setBackgroundColor(colors.gray)\ open_bar.clear()\ open_bar.setTextColor(colors.lightGray)\ open_bar.setCursorPos(12,2)\ open_bar.write(\"Open\")\ open_bar.setCursorPos(2,8)\ open_bar.write(\"cancel\")\ open_bar.setBackgroundColor(colors.lightGray)\ open_bar.setCursorPos(1,4)\ open_bar.write(\" \")\ open_bar.setCursorPos(1,5)\ open_bar.write(\" \")\ open_bar.setCursorPos(1,6)\ open_bar.write(\" \")\ open_bar.setTextColor(colors.gray)\ open_bar.setCursorPos(2,5)\ open_bar.write(\"Path:\")\ open_bar.setCursorPos(20,8)\ open_bar.write(\" open \")\ newObj(\"btn_open_\",centerX+7,8,6,1)\ \ local charPicker = window.create(term.current(),scrX+1,1,18,scrY)\ charPicker.setBackgroundColor(colors.gray)\ charPicker.setTextColor(colors.lightGray)\ charPicker.clear()\ charPicker.setCursorPos(4,1)\ charPicker.write(\"char picker\")\ local function drawPicker()\ \009charPicker.setCursorPos(2,3)\ \009for i=1,255 do\ \009\009if i%16 == 0 then\ \009\009\009charPicker.setCursorPos(2,i/16+3)\ \009\009end\ \009\009if string.char(i) == charSet then\ \009\009\009charPicker.setTextColor(accent_color)\ \009\009else\ \009\009\009charPicker.setTextColor(colors.lightGray)\ \009\009end\ \009\009charPicker.write(string.char(i))\ \009end\ end\ drawPicker()\ \ local rule_top = window.create(term.current(),4,1,scrX-3,1)\ rule_top.setBackgroundColor(colors.lightGray)\ rule_top.clear()\ for i=1,scrX-4 do\ \009rule_top.setTextColor(colors.gray)\ \009rule_top.setCursorPos(i,1)\ \009rule_top.write(string.char(149))\ end\ rule_top.setCursorPos(scrX-3,1)\ rule_top.write(string.char(17))\ \ local rule_right = window.create(term.current(),scrX,2,1,scrY-1)\ rule_right.setBackgroundColor(colors.lightGray)\ for i=1,scrY-1 do\ \009rule_right.setTextColor(colors.gray)\ \009rule_right.setCursorPos(1,i)\ \009rule_right.write(string.char(131))\ end\ \ local function redraw_gui()\ \009term.clear()\ \009blackBackground.redraw()\ \009shadow.redraw()\ \009holst.redraw()\ \009rule_top.redraw()\ \009rule_right.redraw()\ \009bar_color.redraw()\ \009--sel.redraw()\ \009bar.redraw()\ \009selector.redraw()\ \009open_bar.redraw()\ \009save_bar.redraw()\ \009bar_resize.redraw()\ \009charPicker.redraw()\ \009layer_bar.redraw()\ end\ \ local function open_context_menu(...)\ \009local args = {...}\ \009local waitFor = true\ \009local selected\ \009local reverse\ \009if type(args[#args]) == 'boolean' then\ \009\009reverse = args[#args]\ \009\009args[#args] = nil\ \009end\ \009if type(args[#args]) == 'table' then\ \009\009waitFor = false\ \009\009selected = args[#args][1]\ \009\009args[#args] = nil\ \009end\ \009local x = args[1]\ \009local y = args[2]\ \009local maxLenth = 3\ \009local output = nil\ \009for i=3,#args do\ \009\009if #args[i] > maxLenth then\ \009\009\009maxLenth = #args[i]\ \009\009end\ \009end\ \009maxLenth = maxLenth + 1\ \009local xend = maxLenth+1\ \009local yend = #args\ \009if x+maxLenth > scrX or reverse then\ \009\009-- xend = x\ \009\009x = x-maxLenth\ \009end\ \009if y+#args > scrY then\ \009\009-- yend = y\ \009\009y = y-#args+1\ \009end\ \ \009local trm = window.create(term.current(), x,y,xend,yend)\ \009if reverse then\ \009\009trm.setBackgroundColor(colors.lightGray)\ \009else\ \009\009trm.setBackgroundColor(colors.gray)\ \009end\ \009trm.setTextColor(colors.white)\ \009trm.clear()\ \ \009local usualText = function(string,xPos,yPos)\ \009\009trm.setCursorPos(xPos,yPos)\ \009\009trm.write(string)\ \009end\ \ \009for i=3,#args do\ \009\009if selected == args[i] then\ \009\009\009trm.setBackgroundColor(colors.lightGray)\ \009\009\009for k=1,maxLenth+1 do\ \009\009\009\009usualText(\" \",k,i-1)\ \009\009\009end\ \009\009end\ \009\009usualText(args[i], math.floor((maxLenth-1)/2)-math.floor(#args[i]/2)+2, i-1)\ \009\009if selected == args[i] then\ \009\009\009trm.setBackgroundColor(colors.gray)\ \009\009end\ \009end\ \ \009local event, side, xp, yp\ \009while waitFor do\ \009\009event, side, xp, yp = os.pullEvent()\ \009\009if event == 'mouse_click' then\ \009\009\009for i=1,#args-2 do\ \009\009\009\009if xp >= x and xp <= x+xend-1 and yp >= y and yp <= y+yend-1 then\ \009\009\009\009\009if yp == y+i then\ \009\009\009\009\009\009trm.setTextColor(accent_color)\ \009\009\009\009\009\009usualText(args[i+2],math.floor((maxLenth-1)/2)-math.floor(#args[i+2]/2)+2,i+1)\ \009\009\009\009\009\009sleep(0.1)\ \009\009\009\009\009\009output = args[i+2]\ \009\009\009\009\009end\ \009\009\009\009end\ \009\009\009end\ \009\009\009return output\ \009\009end\ \009end\ \009return x-1\ end\ \ local function open_main_menu()\ \009local out = open_context_menu(scrX, 1, unpack(main_menu))\ \009redraw_gui()\ \009return out\ end\ \ local function open_submenu(title, ...)\ \009local args = {...}\ \009local posY\ \009for i=1,#main_menu do\ \009\009if main_menu[i] == title then\ \009\009\009posY = i + 1\ \009\009\009break\ \009\009end\ \009end\ \009if not posY then return end\ \009-- local menu_arr = main_menu\ \009table.insert(main_menu, {title})\ \009local posX = open_context_menu(scrX, 1, unpack(main_menu))\ \009table.remove(main_menu)\ \009-- sleep(1)\ \009if posX then\ \009\009table.insert(args, true)\ \009\009local out = open_context_menu(posX, posY-1, unpack(args))\ \009\009return out\ \009end\ end\ \ local function newLayer()\ \009cur_layer = #image+1\ \009image[cur_layer] = {}\ \009layers[cur_layer] = {}\ \009layers[cur_layer].visible = true\ \009layers[cur_layer].pos = {x = 1, y = 1}\ \009for i=1,sizeY do\ \009\009if not image[cur_layer][i] then\ \009\009\009image[cur_layer][i] = {}\ \009\009end\ \009\009for j=1,sizeX do\ \009\009\009image[cur_layer][i][j] = \"###\"\ \009\009end\ \009end\ \009layer_bar.setCursorPos(5,4)\ \009layer_bar.write(\" \")\ \009layer_bar.setCursorPos(4,4)\ \009layer_bar.write(cur_layer)\ end\ \ local function redraw_layers(pos, x,y)\ \009if not pos then\ \009\009pos = 1\ \009\009if not (x and y) then\ \009\009\009clear_holst()\ \009\009end\ \009end\ \009for l=pos,#image do\ \009\009if image[l] and layers[l] and layers[l].visible then\ \009\009\009if not x or not y then\ \009\009\009\009for i=1,#image[l] do\ \009\009\009\009\009for j=1,#image[l][i] do\ \009\009\009\009\009\009local str = image[l][i][j]\ \009\009\009\009\009\009if str ~= \"###\" then\ \009\009\009\009\009\009\009holst.setCursorPos(j, i)\ \009\009\009\009\009\009\009holst.setTextColor(ColorsB[string.sub(str,2,2)])\ \009\009\009\009\009\009\009holst.setBackgroundColor(ColorsB[string.sub(str,3)])\ \009\009\009\009\009\009\009holst.write(string.sub(str,1,1))\ \009\009\009\009\009\009elseif l==1 then\ \009\009\009\009\009\009\009holst.setCursorPos(j, i)\ \009\009\009\009\009\009\009holst.setTextColor(colors.lightGray)\ \009\009\009\009\009\009\009holst.setBackgroundColor(colors.white)\ \009\009\009\009\009\009\009holst.write(empty_symbol)\ \009\009\009\009\009\009end\ \009\009\009\009\009end\ \009\009\009\009end\ \009\009\009else\ \009\009\009\009if image[l][y] and image[l][y][x] then\ \009\009\009\009\009local str = image[l][y][x]\ \009\009\009\009\009if str ~= \"###\" then\ \009\009\009\009\009\009holst.setCursorPos(x, y)\ \009\009\009\009\009\009holst.setTextColor(ColorsB[string.sub(str,2,2)])\ \009\009\009\009\009\009holst.setBackgroundColor(ColorsB[string.sub(str,3)])\ \009\009\009\009\009\009holst.write(string.sub(str,1,1))\ \009\009\009\009\009elseif l==1 then\ \009\009\009\009\009\009holst.setCursorPos(x, y)\ \009\009\009\009\009\009holst.setTextColor(colors.lightGray)\ \009\009\009\009\009\009holst.setBackgroundColor(colors.white)\ \009\009\009\009\009\009holst.write(empty_symbol)\ \009\009\009\009\009end\ \009\009\009\009end\ \009\009\009end\ \009\009end\ \009end\ \009-- redraw_gui()\ \009-- redraw_holst()\ end\ \ local function change_layer(num)\ \009if num <= #image and num >= 1 then\ \009\009cur_layer = num\ \009elseif num < 1 then\ \009\009cur_layer = 1\ \009elseif num > #image then\ \009\009newLayer()\ \009end\ \009if not layers[num] or not layers[num].visible then\ \009\009layer_bar.setTextColor(colors.lightGray)\ \009else\ \009\009layer_bar.setTextColor(accent_color)\ \009end\ \009layer_bar.setCursorPos(2,6)\ \009layer_bar.write(\"Visible\")\ \009layer_bar.setTextColor(colors.lightGray)\ \009layer_bar.setCursorPos(5,4)\ \009layer_bar.write(\" \")\ \009layer_bar.setCursorPos(4,4)\ \009layer_bar.write(cur_layer)\ \009redraw_layers()\ end\ \ local function remove_layer(num)\ \009if num > 1 and num <= #image then\ \009\009for i=num,#image-1 do\ \009\009\009image[i] = image[i+1]\ \009\009\009layers[i] = layers[i+1]\ \009\009end\ \009\009layers[#image] = nil\ \009\009image[#image] = nil\ \009\009redraw_layers()\ \009\009change_layer(num-1)\ \009elseif num == 1 and #image == 1 then\ \009\009image[1] = nil\ \009\009cur_layer = 0\ \009\009newLayer()\ \009end\ end\ \ local function change_visible(num)\ \009if num >= 1 and num <= #image then\ \009\009if layers[num] and layers[num].visible then\ \009\009\009layers[num].visible = false\ \009\009\009layer_bar.setTextColor(colors.lightGray)\ \009\009else\ \009\009\009layers[num].visible = true\ \009\009\009layer_bar.setTextColor(accent_color)\ \009\009end\ \009\009layer_bar.setCursorPos(2,6)\ \009\009layer_bar.write(\"Visible\")\ \009\009layer_bar.setTextColor(colors.lightGray)\ \009\009redraw_layers()\ \009end\ end\ \ local function check_visible(num)\ \009if not num then num = cur_layer end\ \009if layers[num] and layers[num].visible then\ \009\009return true\ \009else\ \009\009return false\ \009end\ end\ \ --newLayer()\ \ local function redraw_holst()\ \009local posX, posY = holst.getPosition()\ \009if posX < 5 then\ \009\009bar.redraw()\ \009\009selector.redraw()\ \009end\ \009if posY < 3 and showBar then\ \009\009rule_top.redraw()\ \009end\ \009if 2 + posX + shadow.getSize() > scrX and showBar then\ \009\009rule_right.redraw()\ \009end\ end\ \ local function fill(x,y, color)\ \009local function fill_(x,y, color)\ \009\009if color == nil then\ \009\009\009color = \"#\"\ \009\009end\ \009\009local function next(i)\ \009\009\009if image[cur_layer][i] and image[cur_layer][i][x+1] and string.sub(image[cur_layer][i][x+1],3) == color and string.sub(image[cur_layer][i][x+1],3) ~= Colors[brushColor] then\ \009\009\009\009fill_(x+1,i,color)\ \009\009\009end\ \009\009\009if image[cur_layer][i] and image[cur_layer][i][x-1] and string.sub(image[cur_layer][i][x-1],3) == color and string.sub(image[cur_layer][i][x-1],3) ~= Colors[brushColor] then\ \009\009\009\009fill_(x-1,i,color)\ \009\009\009end\ \009\009end\ \009\009local function vertical(x,y)\ \009\009\009local i = y\ \009\009\009local top, down\ \009\009\009while image[cur_layer][i] and image[cur_layer][i][x] and string.sub(image[cur_layer][i][x],3) == color do\ \009\009\009\009image[cur_layer][i][x] = charSet..Colors[textColor]..Colors[brushColor]\ \009\009\009\009i = i-1\ \009\009\009end\ \009\009\009top = i+1\ \009\009\009i = y+1\ \009\009\009while image[cur_layer][i] and image[cur_layer][i][x] and string.sub(image[cur_layer][i][x],3) == color do\ \009\009\009\009image[cur_layer][i][x] = charSet..Colors[textColor]..Colors[brushColor]\ \009\009\009\009i = i+1\ \009\009\009end\ \009\009\009down = i-1\ \009\009\009next(top)\ \009\009\009next(down)\ \009\009end\ \009\009vertical(x,y)\ \009\009next(y)\ \009end\ \009fill_(x,y,color)\ \009redraw_layers(cur_layer)\ \009redraw_holst()\ end\ \ local function checkHolstClick(x,y)\ \009local bx, by\ \009bx, by = x-posX+1-math.floor(sX/2),y-math.floor(sY/2)-posY+1\ \ \009if check_visible() and image[cur_layer][by] and image[cur_layer][by][bx] then\ \009\009return bx, by\ \009end\ end\ \ local function draw_pixel(x,y,absolute)\ \009local bx, by\ \009if not absolute then\ \009\009bx, by = x-posX+1-math.floor(sX/2),y-math.floor(sY/2)-posY+1\ \009else\ \009\009bx, by = x, y\ \009end\ \009if check_visible() and image[cur_layer][by] and image[cur_layer][by][bx] and (image[cur_layer][by][bx] == \"###\" or string.sub(image[cur_layer][by][bx],3) ~= Colors[brushColor] or string.sub(image[cur_layer][by][bx],2,2) ~= Colors[textColor] or string.sub(image[cur_layer][by][bx],1,1) ~= charSet) then\ \009\009image[cur_layer][by][bx] = charSet..(type(textColor) == \"number\" and Colors[textColor] or textColor)..(type(brushColor) == \"number\" and Colors[brushColor] or brushColor)\ \009\009redraw_layers(cur_layer, bx,by)\ \009\009-- bar.redraw()\ \009\009-- selector.redraw()\ \009\009-- rule_top.redraw()\ \009\009-- rule_right.redraw()\ \009\009redraw_holst()\ \009end\ end\ \ local function erase_pixel(x,y,absolute)\ \009local bx, by\ \009if not absolute then\ \009\009bx, by = x-posX+1-math.floor(sX/2),y-math.floor(sY/2)-posY+1\ \009else\ \009\009bx, by = x, y\ \009end\ \009if check_visible() and image[cur_layer][by] and image[cur_layer][by][bx] and image[cur_layer][by][bx] ~= \"###\" then\ \009\009image[cur_layer][by][bx] = '###'\ \009\009redraw_layers(nil, bx,by)\ \009\009-- bar.redraw()\ \009\009-- selector.redraw()\ \009\009-- rule_top.redraw()\ \009\009-- rule_right.redraw()\ \009\009redraw_holst()\ \009end\ end\ \ local function reposition_layer(x, y)\ \009-- local x, y = x-posX+1, y-posY+1\ \ \009local newImg = {}\ \009local startI = 1\ \009local startJ = 1\ \009local offset\ \ \009layers[cur_layer].pos.x = layers[cur_layer].pos.x+x\ \009layers[cur_layer].pos.y = layers[cur_layer].pos.y+y\ \ \009if layers[cur_layer].pos.x > 0 then\ \009\009layers[cur_layer].pos.x = 0\ \009end\ \009if layers[cur_layer].pos.y > 0 then\ \009\009layers[cur_layer].pos.y = 0\ \009end\ \ \009if startI > layers[cur_layer].pos.y then\ \009\009startI = layers[cur_layer].pos.y\ \009end\ \ \009if startJ > layers[cur_layer].pos.x then\ \009\009startJ = layers[cur_layer].pos.x\ \009end\ \ \009for i=startI, #image[cur_layer] do\ \009\009if image[cur_layer][i] then\ \009\009\009if not newImg[i+y] then\ \009\009\009\009newImg[i+y] = {}\ \009\009\009end\ \009\009\009for j=startJ, #image[cur_layer][i] do\ \009\009\009\009newImg[i+y][j+x] = image[cur_layer][i][j]\ \009\009\009\009image[cur_layer][i][j] = \"###\"\ \009\009\009end\ \009\009end\ \009end\ \ \009for i=1, #image[cur_layer] do\ \009\009if not newImg[i] then\ \009\009\009newImg[i] = {}\ \009\009end\ \009\009for j=1, #image[cur_layer][i] do\ \009\009\009if not newImg[i][j] then\ \009\009\009\009if not image[cur_layer][i][j] then\ \009\009\009\009\009image[cur_layer][i][j] = \"###\"\ \009\009\009\009end\ \009\009\009\009newImg[i][j] = image[cur_layer][i][j]\ \009\009\009end\ \009\009end\ \009end\ \ \009image[cur_layer] = newImg\ \ \009redraw_layers()\ \009-- bar.redraw()\ \009-- selector.redraw()\ \009-- rule_top.redraw()\ \009-- rule_right.redraw()\ \009redraw_holst()\ end\ \ local function change_color(clr,side)\ \009local sel = color_selector\ \009if not side or side == \"brush\" then\ \009\009brushColor = clr\ \009else\ \009\009textColor = clr\ \009\009sel = color_selectorT\ \009end\ \ \009bar_color.setBackgroundColor(brushColor)\ \009bar_color.setTextColor(textColor)\ \009bar_color.setCursorPos(2,19)\ \009if not charSet then\ \009\009charSet = \" \"\ \009end\ \009bar_color.write(charSet)\ \009bar_color.setBackgroundColor(textColor)\ \009bar_color.setCursorPos(3,19)\ \009bar_color.write(\" \")\ \ \009local xx,xy = sel.getPosition()\ \009while 2^(xy-2) ~= clr do\ \009\009bar_color.setBackgroundColor(colors.gray)\ \009\009bar_color.setCursorPos(xx,xy)\ \009\009bar_color.write(\" \")\ \009\009if 2^(xy-2) > clr then\ \009\009\009xy = xy-1\ \009\009else\ \009\009\009xy = xy+1\ \009\009end\ \009\009sel.reposition(xx,xy)\ \009\009sleep(0)\ \009end\ end\ \ local function pick_color(x,y,mode,absolute)\ \009local bx, by\ \009if not absolute then\ \009\009bx, by = x-posX+1-math.floor(sX/2),y-math.floor(sY/2)-posY+1\ \009else\ \009\009bx, by = x, y\ \009end\ \009local mode = mode or \"brush\"\ \009local color\ \009if check_visible() and image[cur_layer][by] and image[cur_layer][by][bx] and image[cur_layer][by][bx] ~= \"###\" and (image[cur_layer][by][bx] == \"###\" or string.sub(image[cur_layer][by][bx],3) ~= Colors[brushColor] or string.sub(image[cur_layer][by][bx],2,2) ~= Colors[textColor] or string.sub(image[cur_layer][by][bx],1,1) ~= charSet) then\ \009\009if mode == \"brush\" then\ \009\009\009color = ColorsB[string.sub(image[cur_layer][by][bx],3,3)]\ \009\009else\ \009\009\009if string.sub(image[cur_layer][by][bx],1,1) ~= \" \" and string.sub(image[cur_layer][by][bx],1,1) ~= \"\" then\ \009\009\009\009color = ColorsB[string.sub(image[cur_layer][by][bx],2,2)]\ \009\009\009else\ \009\009\009\009color = ColorsB[string.sub(image[cur_layer][by][bx],3,3)]\ \009\009\009end\ \009\009end\ \009\009change_color(color,mode)\ \009\009return color\ \009end\ end\ \ local function resize(x,y)\ \009term.setCursorPos(1,1)\ \009local bx, by = sizeX, sizeY\ \009x = tonumber(x)\ \009y = tonumber(y)\ \009sizeX, sizeY = x, y\ \009newX, newY = x, y\ \009bar_resize.setBackgroundColor(colors.lightGray)\ \009bar_resize.setTextColor(colors.gray)\ \009bar_resize.setCursorPos(8,4)\ \009bar_resize.write(\" \")\ \009bar_resize.setCursorPos(9,4)\ \009bar_resize.write(newX)\ \009bar_resize.setCursorPos(8,6)\ \009bar_resize.write(\" \")\ \009bar_resize.setCursorPos(9,6)\ \009bar_resize.write(newY)\ \009posX, posY = centerX-math.floor(sizeX/2)+3, centerY-math.floor(sizeY/2)+1\ \ \009blackBackground.reposition(posX, posY, sizeX+1, sizeY+1)\ \009shadow.reposition(posX+1, posY+1, sizeX, sizeY)\ \009shadow.clear()\ \009for i=1,sizeX-1 do\ \009\009shadow.setCursorPos(i,sizeY)\ \009\009shadow.write(string.char(131))\ \009end\ \009for i=1,sizeY-1 do\ \009\009shadow.setCursorPos(sizeX,i)\ \009\009shadow.write(string.char(149))\ \009end\ \009shadow.setCursorPos(sizeX,sizeY)\ \009shadow.write(string.char(129))\ \009holst.reposition(posX, posY, sizeX, sizeY)\ \ \009for l=1,#image do\ \009\009if not image[l] then\ \009\009\009image[l] = {}\ \009\009end\ \009\009for i=1,sizeY do\ \009\009\009if not image[l][i] then\ \009\009\009\009image[l][i] = {}\ \009\009\009end\ \009\009\009for j=1,sizeX do\ \009\009\009\009if not image[l][i][j] then\ \009\009\009\009\009image[l][i][j] = \"###\"\ \009\009\009\009end\ \009\009\009end\ \009\009end\ \009end\ \009term.setCursorPos(1,1)\ \009redraw_layers()\ end\ \ local function save(path, fileType)\ \009path = shell.resolve(path)\ \009local img = {}\ \009for l=1,#image do\ \009\009for i=1,#image[l] do\ \009\009\009if not img[i] then\ \009\009\009\009img[i] = {}\ \009\009\009end\ \009\009\009for j=1,#image[l][i] do\ \009\009\009\009if not (img[i][j] and img[i][j] ~= \"###\" and image[l][i][j] == \"###\") then\ \009\009\009\009\009img[i][j] = image[l][i][j]\ \009\009\009\009end\ \009\009\009\009if not img[i][j] then\ \009\009\009\009\009img[i][j] = \"###\"\ \009\009\009\009end\ \009\009\009end\ \009\009end\ \009end\ \009if fileType == \"png\" then\ \009\009local file = fs.open(path..\".\"..fileType,\"w\")\ \009\009for i=1,#img do\ \009\009\009if not img[i] then\ \009\009\009\009img[i] = {}\ \009\009\009end\ \009\009\009local line = \"\"\ \009\009\009for j=1,#img[i] do\ \009\009\009\009if not img[i][j] then\ \009\009\009\009\009line = line..\"###\"\ \009\009\009\009else\ \009\009\009\009\009line = line..img[i][j]\ \009\009\009\009end\ \009\009\009end\ \009\009\009file.writeLine(line)\ \009\009end\ \009\009file.close()\ \009elseif fileType == \"skch\" then\ \009\009local file = fs.open(path..\".\"..fileType,\"w\")\ \009\009local lr = {}\ \009\009for l=1,#image do\ \009\009\009local arr = {}\ \009\009\009arr.Visible = true\ \009\009\009arr.Index = l\ \009\009\009arr.Name = \"layer#\"..l\ \009\009\009arr.BackgroundColour = -1\ \009\009\009arr.Pixels = {}\ \009\009\009for i=1,#image[l] do\ \009\009\009\009local line = \"\\030 \\031f\"\ \009\009\009\009local back = \"#\"\ \009\009\009\009local backT = \"f\"\ \009\009\009\009for j=1,#image[l][i] do\ \009\009\009\009\009if string.sub(image[l][i][j],3) == back and string.sub(image[l][i][j],2,2) == backT and string.sub(image[l][i][j],1,1) ~= \"#\" then\ \009\009\009\009\009\009line = line..string.sub(image[l][i][j],1,1)\ \009\009\009\009\009elseif string.sub(image[l][i][j],3) == back and string.sub(image[l][i][j],1,1) == \"#\" then\ \009\009\009\009\009\009line = line..\" \"\ \009\009\009\009\009elseif not image[l][i][j] or image[l][i][j] == \"###\" then\ \009\009\009\009\009\009back = \"#\"\ \009\009\009\009\009\009backT = \"f\"\ \009\009\009\009\009\009local s = \" \"\ \009\009\009\009\009\009if i >= #image[l]-1 then\ \009\009\009\009\009\009\009s = \"\"\ \009\009\009\009\009\009end\ \009\009\009\009\009\009line = line..string.char(30)..\" \"..string.char(31)..backT..s\ \009\009\009\009\009else\ \009\009\009\009\009\009if string.sub(image[l][i][j],3) ~= back then\ \009\009\009\009\009\009\009back = string.sub(image[l][i][j],3)\ \009\009\009\009\009\009\009line = line..string.char(30)..back\ \009\009\009\009\009\009end\ \009\009\009\009\009\009if string.sub(image[l][i][j],2,2) ~= backT then\ \009\009\009\009\009\009\009backT = string.sub(image[l][i][j],2,2)\ \009\009\009\009\009\009\009line = line..string.char(31)..backT\ \009\009\009\009\009\009end\ \009\009\009\009\009\009line = line..string.sub(image[l][i][j],1,1)\ \009\009\009\009\009end\ \009\009\009\009end\ \009\009\009\009arr.Pixels[i] = line\ \009\009\009end\ \009\009\009lr[l] = arr\ \009\009end\ \009\009file.write(textutils.serialize(lr))\ \009\009file.close()\ \009elseif fileType == \"nft\" then\ \009\009local file = fs.open(path..\".\"..fileType,\"w\")\ \009\009for i=1,#img do\ \009\009\009local line = \"\030 \031f\"\ \009\009\009local back = \"#\"\ \009\009\009local backT = \"f\"\ \009\009\009local bcount = 0\ \009\009\009for j=1,#img[i] do\ \009\009\009\009if string.sub(img[i][j],3) == back and string.sub(img[i][j],2,2) == backT and string.sub(img[i][j],1,1) ~= \"#\" then\ \009\009\009\009\009line = line..string.sub(img[i][j],1,1)\ \009\009\009\009elseif string.sub(img[i][j],3) == back and string.sub(img[i][j],1,1) == \"#\" then\ \009\009\009\009\009line = line..\" \"\ \009\009\009\009elseif not img[i][j] or img[i][j] == \"###\" then\ \009\009\009\009\009back = \"#\"\ \009\009\009\009\009backT = \"f\"\ \009\009\009\009\009local s = \" \"\ \009\009\009\009\009if i >= #img-1 then\ \009\009\009\009\009\009s = \"\"\ \009\009\009\009\009end\ \009\009\009\009\009line = line..string.char(30)..\" \"..string.char(31)..backT..s\ \009\009\009\009else\ \009\009\009\009\009if string.sub(img[i][j],3) ~= back then\ \009\009\009\009\009\009back = string.sub(img[i][j],3)\ \009\009\009\009\009\009line = line..string.char(30)..back\ \009\009\009\009\009end\ \009\009\009\009\009if string.sub(img[i][j],2,2) ~= backT then\ \009\009\009\009\009\009backT = string.sub(img[i][j],2,2)\ \009\009\009\009\009\009line = line..string.char(31)..backT\ \009\009\009\009\009end\ \009\009\009\009\009line = line..string.sub(img[i][j],1,1)\ \009\009\009\009end\ \009\009\009end\ \009\009\009file.writeLine(line)\ \009\009end\ \009\009file.close()\ \009elseif fileType == \"nfp\" then\ \009\009local file = fs.open(path..\".\"..fileType,\"w\")\ \009\009for i=1,#img do\ \009\009\009local line = \"\"\ \009\009\009for j=1,#img[i] do\ \009\009\009\009if img[i][j] == \"###\" then\ \009\009\009\009\009line = line..\" \"\ \009\009\009\009else\ \009\009\009\009\009line = line..string.sub(img[i][j],3)\ \009\009\009\009end\ \009\009\009end\ \009\009\009file.writeLine(line)\ \009\009end\ \009\009file.close()\ \009end\ end\ \ local function getFileFormat(path)\ \009local name = fs.getName(path)\ \009local starting,ending = string.find(name,\"(.)%.[%d%w]*$\")\ \009if starting == nil then\ \009\009return nil\ \009else\ \009\009return string.sub(name,starting+2,-1), string.sub(name,1,starting)\ \009end\ end\ \ local function draw(trm,img,x,y)\ \009for i=1,#img do\ \009\009for j=1,#img[i]/3 do\ \009\009\009if string.sub(img[i],j*3-2,j*3) ~= \"###\" then\ \009\009\009\009trm.setCursorPos(j,i)\ \009\009\009\009trm.setTextColor(ColorsB[string.sub(img[i],j*3-1,j*3-1)])\ \009\009\009\009trm.setBackgroundColor(ColorsB[string.sub(img[i],j*3,j*3)])\ \009\009\009\009trm.write(string.sub(img[i],j*3-2,j*3-2))\ \009\009\009end\ \009\009end\ \009end\ end\ \ local function open(pth)\ \009local path = shell.resolve(pth)\ \009if not fs.exists(path) then return end\ \ \009term.clear()\ \009term.setCursorPos(1,1)\ \009blackBackground.setVisible(false)\ \009holst.setVisible(false)\ \009shadow.setVisible(false)\ \009local loadScreen = window.create(term.current(),centerX-14,centerY-7,32,16)\ \009loadScreen.setBackgroundColor(colors.gray)\ \009loadScreen.setTextColor(colors.lightGray)\ \009loadScreen.clear()\ \009draw(loadScreen,splash,1,1)\ \009loadScreen.setBackgroundColor(colors.gray)\ \009loadScreen.setTextColor(colors.lightGray)\ \009loadScreen.setCursorPos(2,12)\ \009loadScreen.write(\"Loading...\")\ \009loadScreen.setCursorPos(2,13)\ \009loadScreen.write(\"Finding file \")\ \009sleep(0.5)\ \ \009loadScreen.setCursorPos(2,15)\ \009loadScreen.write(path)\ \ \009local file = fs.open(path,\"r\")\ \ \009loadScreen.setCursorPos(2,13)\ \009loadScreen.write(\"Getting file format \")\ \009sleep(0.5)\ \ \009fileType = getFileFormat(pth)\ \009saveAs = string.sub(pth,1,#pth-#fileType-1)\ \ \009if file then\ \009\009local load = true\ \009\009loadScreen.setCursorPos(2,13)\ \009\009loadScreen.write(\"Reading file \")\ \009\009sleep(0.5)\ ------------------------------------------------------------------\ \009\009if fileType == \"png\" then\ \009\009\009newLayer()\ \009\009\009local line = file.readLine()\ \009\009\009local i=1\ \009\009\009while line do\ \009\009\009\009if #line/3 > sizeX then\ \009\009\009\009\009resize(#line/3,sizeY)\ \009\009\009\009end\ \009\009\009\009if not image[cur_layer] then\ \009\009\009\009\009image[cur_layer] = {}\ \009\009\009\009end\ \009\009\009\009for j=1,#line/3 do\ \009\009\009\009\009if not image[cur_layer][i] then\ \009\009\009\009\009\009image[cur_layer][i] = {}\ \009\009\009\009\009end\ \009\009\009\009\009image[cur_layer][i][j] = string.sub(line,j*3-2,j*3)\ \009\009\009\009end\ \009\009\009\009line = file.readLine()\ \009\009\009\009if line then\ \009\009\009\009\009i=i+1\ \009\009\009\009\009if i > sizeY then\ \009\009\009\009\009\009resize(sizeX,i)\ \009\009\009\009\009end\ \009\009\009\009end\ \009\009\009end\ \009\009\009redraw_layers(cur_layer)\ -------------------------------------------------------------------------------\ \009\009elseif fileType == \"skch\" then\ \009\009\009local las = textutils.unserialize(file.readAll())\ \ \009\009\009for l=1,#las do\ \009\009\009\009newLayer()\ \009\009\009\009if las[l].Visible then\ \009\009\009\009\009layers[cur_layer].setVisible(false)\ \009\009\009\009end\ \ \009\009\009\009\009for i=1, #las[l].Pixels do\ \009\009\009\009\009\009local j=5\ \009\009\009\009\009\009local char = \"\"\ \009\009\009\009\009\009local px = 0\ \009\009\009\009\009\009local line = las[l].Pixels[i]\ \ \009\009\009\009\009\009if i > sizeY then\ \009\009\009\009\009\009\009resize(sizeX,i)\ \009\009\009\009\009\009end\ \ \009\009\009\009\009\009local _bColor = string.sub(line,2,2)\ \009\009\009\009\009\009local _tColor = string.sub(line,4,4)\ \009\009\009\009\009\009local bColor = _bColor\ \009\009\009\009\009\009local tColor = _tColor\ \ \009\009\009\009\009\009if not image[cur_layer][i] then\ \009\009\009\009\009\009\009image[cur_layer][i] = {}\ \009\009\009\009\009\009end\ \ \009\009\009\009\009\009while j<=#line do\ \009\009\009\009\009\009\009char = string.sub(line,j,j)\ \009\009\009\009\009\009\009if char == \"\030\" then\ \009\009\009\009\009\009\009\009j=j+1\ \009\009\009\009\009\009\009\009bColor = string.sub(line,j,j)\ \009\009\009\009\009\009\009\009if bColor ~= \" \" then\ \009\009\009\009\009\009\009\009else\ \009\009\009\009\009\009\009\009\009bColor = _bColor\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009j=j+1\ \009\009\009\009\009\009\009elseif char == \"\031\" then\ \009\009\009\009\009\009\009\009j=j+1\ \009\009\009\009\009\009\009\009tColor = string.sub(line,j,j)\ \009\009\009\009\009\009\009\009if tColor ~= \" \" then\ \009\009\009\009\009\009\009\009else\ \009\009\009\009\009\009\009\009\009tColor = _tColor\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009j=j+1\ \009\009\009\009\009\009\009else\ \009\009\009\009\009\009\009\009px = px + 1\ \009\009\009\009\009\009\009\009if px > sizeX then\ \009\009\009\009\009\009\009\009\009resize(px,sizeY)\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009if bColor ~= \" \" then\ \009\009\009\009\009\009\009\009\009image[cur_layer][i][px] = char..tColor..bColor\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009j = j+1\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009end\ \009\009\009\009\009end\ \009\009\009end\ --------------------------------------------------------------\ \009\009elseif fileType == \"nft\" then\ \009\009\009newLayer()\ \009\009\009local line = file.readLine()\ \009\009\009local i=1\ \009\009\009while line do\ \009\009\009\009local j=5\ \009\009\009\009local char = \"\"\ \009\009\009\009local px = 0\ \ \009\009\009\009local _bColor = string.sub(line,2,2)\ \009\009\009\009local _tColor = string.sub(line,4,4)\ \009\009\009\009local bColor = _bColor\ \009\009\009\009local tColor = _tColor\ \ \009\009\009\009if not image[cur_layer][i] then\ \009\009\009\009\009image[cur_layer][i] = {}\ \009\009\009\009end\ \ \009\009\009\009while j<=#line do\ \009\009\009\009\009char = string.sub(line,j,j)\ \009\009\009\009\009if char == \"\030\" then\ \009\009\009\009\009\009j=j+1\ \009\009\009\009\009\009bColor = string.sub(line,j,j)\ \009\009\009\009\009\009if bColor ~= \" \" then\ \009\009\009\009\009\009else\ \009\009\009\009\009\009\009bColor = _bColor\ \009\009\009\009\009\009end\ \009\009\009\009\009\009j=j+1\ \009\009\009\009\009elseif char == \"\031\" then\ \009\009\009\009\009\009j=j+1\ \009\009\009\009\009\009tColor = string.sub(line,j,j)\ \009\009\009\009\009\009if tColor ~= \" \" then\ \009\009\009\009\009\009else\ \009\009\009\009\009\009\009tColor = _tColor\ \009\009\009\009\009\009end\ \009\009\009\009\009\009j=j+1\ \009\009\009\009\009else\ \009\009\009\009\009\009px = px + 1\ \009\009\009\009\009\009if px > sizeX then\ \009\009\009\009\009\009\009resize(px,sizeY)\ \009\009\009\009\009\009end\ \009\009\009\009\009\009if bColor ~= \" \" then\ \009\009\009\009\009\009\009image[cur_layer][i][px] = char..tColor..bColor\ \009\009\009\009\009\009end\ \009\009\009\009\009\009j = j+1\ \009\009\009\009\009end\ \009\009\009\009end\ \009\009\009\009line = file.readLine()\ \009\009\009\009if line then\ \009\009\009\009\009i=i+1\ \009\009\009\009\009if i > sizeY then\ \009\009\009\009\009\009resize(sizeX,i)\ \009\009\009\009\009end\ \009\009\009\009end\ \009\009\009end\ -----------------------------------------------------------------\ \009\009elseif fileType == \"nfp\" then\ \009\009\009newLayer()\ \009\009\009local line = file.readLine()\ \009\009\009local i=1\ \009\009\009while line do\ \009\009\009\009if not image[cur_layer][i] then\ \009\009\009\009\009image[cur_layer][i] = {}\ \009\009\009\009end\ \009\009\009\009if #line > sizeX then\ \009\009\009\009\009resize(#line,sizeY)\ \009\009\009\009end\ \009\009\009\009for j=1,#line do\ \009\009\009\009\009if string.sub(line,j,j) ~= \" \" then\ \009\009\009\009\009\009image[cur_layer][i][j] = \" \"..string.sub(line,j,j)..string.sub(line,j,j)\ \009\009\009\009\009else\ \009\009\009\009\009\009image[cur_layer][i][j] = \"###\"\ \009\009\009\009\009end\ \009\009\009\009end\ \009\009\009\009line = file.readLine()\ \009\009\009\009if line then\ \009\009\009\009\009i=i+1\ \009\009\009\009\009if i > sizeY then\ \009\009\009\009\009\009resize(sizeX,i)\ \009\009\009\009\009end\ \009\009\009\009end\ \009\009\009end\ ---------------------------------------------------------------------\ \009\009elseif fileType == \"phm\" then\ \009\009\009term.clear()\ \009\009\009loadScreen.redraw()\ \009\009\009loadScreen.setCursorPos(2,13)\ \009\009\009loadScreen.write(\"Loading module... \")\ \009\009\009local mdl_name = file.readLine()\ \009\009\009if string.sub(mdl_name,1,2) == \"--\" then\ \009\009\009\009mdl_name = string.sub(mdl_name,3)\ \009\009\009else\ \009\009\009\009mdl_name = saveAs\ \009\009\009end\ \009\009\009local find = false\ \009\009\009for i=1,#modules do\ \009\009\009\009if modules[i].name == mdl_name and modules[i].path == pth then\ \009\009\009\009\009for j=i,#modules-1 do\ \009\009\009\009\009\009modules[j] = modules[j+1]\ \009\009\009\009\009end\ \009\009\009\009\009modules[#modules] = nil\ \009\009\009\009\009find = true\ \009\009\009\009\009break\ \009\009\009\009elseif modules[i].name == mdl_name and modules[i].path ~= pth then\ \009\009\009\009\009modules[i].path = pth\ \009\009\009\009\009find = true\ \009\009\009\009\009break\ \009\009\009\009elseif modules[i].name ~= mdl_name and modules[i].path == pth then\ \009\009\009\009\009modules[i].name = name\ \009\009\009\009\009find = true\ \009\009\009\009\009break\ \009\009\009\009end\ \009\009\009end\ \009\009\009if not find then\ \009\009\009\009modules[#modules+1] = {}\ \009\009\009\009modules[#modules].name = mdl_name\ \009\009\009\009modules[#modules].path = pth\ \009\009\009end\ \009\009\009for i=1,#modules do\ \009\009\009\009if modules[i].prg then\ \009\009\009\009\009modules[i].prg = nil\ \009\009\009\009end\ \009\009\009end\ \009\009\009local md = fs.open(shell.resolve(\"modules.cfg\"),\"w\")\ \009\009\009md.write(textutils.serialize(modules))\ \009\009\009md.close()\ \009\009\009sleep(0.5)\ \009\009\009running = false\ \009\009else\ \009\009\009term.clear()\ \009\009\009loadScreen.redraw()\ \009\009\009loadScreen.setCursorPos(2,13)\ \009\009\009loadScreen.write(\"Unknown format \")\ \009\009\009load = false\ \009\009\009sleep(0.5)\ \009\009end\ \009\009if load then\ \009\009\009term.clear()\ \009\009\009loadScreen.redraw()\ \009\009\009loadScreen.setCursorPos(2,13)\ \009\009\009loadScreen.write(\"Comlete \")\ \009\009\009drawType()\ \009\009\009saveAs = \"\"\ \009\009\009redraw_layers()\ \009\009\009sleep(0.5)\ \009\009end\ \009\009file.close()\ \009else\ \009\009term.clear()\ \009\009loadScreen.redraw()\ \009\009loadScreen.setCursorPos(2,13)\ \009\009loadScreen.write(\"File not found \")\ \009\009sleep(0.5)\ \009end\ \009term.clear()\ \009blackBackground.setVisible(true)\ \009shadow.setVisible(true)\ \009shadow.redraw()\ \009holst.setVisible(true)\ \009holst.redraw()\ \009bar.redraw()\ \009rule_top.redraw()\ \009rule_right.redraw()\ \009selector.redraw()\ end\ \ local function open_save_window()\ \009saver = true\ \009bar.setTextColor(accent_color)\ \009bar.setCursorPos(2,17)\ \009bar.write(string.char(25))\ \009local _sx, _sy = save_bar.getSize()\ \009for i=-_sy/2,1 do\ \009\009save_bar.reposition(centerX-12,i*2-1)\ \009\009sleep(0)\ \009end\ end\ \ local function open_open_window()\ \009opener = true\ \009bar.setTextColor(accent_color)\ \009bar.setCursorPos(2,15)\ \009bar.write(string.char(24))\ \009local _sx, _sy = open_bar.getSize()\ \009for i=-_sy/2,1 do\ \009\009open_bar.reposition(centerX-12,i*2)\ \009\009sleep(0)\ \009end\ end\ \ local function open_resize_window()\ \009resizer = true\ \009bar.setTextColor(accent_color)\ \009bar.setCursorPos(2,13)\ \009bar.write(\"S\")\ \009local _sx, _sy = bar_resize.getSize()\ \009for i=-_sy/2,1 do\ \009\009bar_resize.reposition(centerX-12,i*2)\ \009\009sleep(0)\ \009end\ end\ \ \ --------------------------Setting up environment----------------------------\ \009local env = {\ \009\009holst = holst,\ \009\009holst_shadow = shadow,\ \009\009image = image,\ \009\009get_accent_color = function()\ \009\009\009return accent_color\ \009\009end,\ \009\009set_accent_color = function(color)\ \009\009\009accent_color = color\ \009\009end,\ \009\009change_tool = function(tl)\ \009\009\009local xx,xy = selector.getPosition()\ \009\009\009local y\ \009\009\009if tl == \"B\" then\ \009\009\009\009y = 2\ \009\009\009elseif tl == \"E\" then\ \009\009\009\009y = 4\ \009\009\009elseif tl == \"F\" then\ \009\009\009\009y = 6\ \009\009\009elseif tl == \"M\" then\ \009\009\009\009y = 8\ \009\009\009elseif tl == \"C\" then\ \009\009\009\009y = 11\ \009\009\009end\ \009\009\009if y then\ \009\009\009\009while xy ~= y do\ \009\009\009\009\009if xy > y then\ \009\009\009\009\009\009xy = xy-1\ \009\009\009\009\009else\ \009\009\009\009\009\009xy = xy+1\ \009\009\009\009\009end\ \009\009\009\009\009bar.redraw()\ \009\009\009\009\009selector.reposition(1,xy)\ \009\009\009\009\009sleep(0)\ \009\009\009\009end\ \009\009\009\009tool = tl\ \009\009\009end\ \009\009end,\ \009\009get_tool = function()\ \009\009\009return tool\ \009\009end,\ \009\009get_fullscreen_state = function()\ \009\009\009if showBar then\ \009\009\009\009return false\ \009\009\009else\ \009\009\009\009return true\ \009\009\009end\ \009\009end,\ \009\009shadow = shadow,\ \009\009rule_top = rule_top,\ \009\009rule_right = rule_right,\ \009\009toolbar = bar,\ \009\009save_window = save_bar,\ \009\009open_window = open_bar,\ \009\009selector = selector,\ \009\009open_save_window = open_save_window,\ \009\009close_save_window = function()\ \009\009\009saver = false\ \009\009\009bar.setTextColor(colors.gray)\ \009\009\009bar.setCursorPos(2,17)\ \009\009\009bar.write(string.char(25))\ \009\009\009local _sx, _sy = save_bar.getSize()\ \009\009\009for i=-_sy/2,1 do\ \009\009\009\009term.clear()\ \009\009\009\009shadow.redraw()\ \009\009\009\009holst.redraw()\ \009\009\009\009bar.redraw()\ \009\009\009\009rule_top.redraw()\ \009\009\009\009rule_right.redraw()\ \009\009\009\009selector.redraw()\ \009\009\009\009save_bar.reposition(centerX-12,-(_sy+i*2+1))\ \009\009\009\009sleep(0)\ \009\009\009end\ \009\009end,\ \009\009open_open_window = open_open_window,\ \009\009close_open_window = function()\ \009\009\009opener = false\ \009\009\009bar.setTextColor(colors.gray)\ \009\009\009bar.setCursorPos(2,15)\ \009\009\009bar.write(string.char(24))\ \009\009\009local _sx, _sy = open_bar.getSize()\ \009\009\009for i=-_sy/2,1 do\ \009\009\009\009term.clear()\ \009\009\009\009shadow.redraw()\ \009\009\009\009holst.redraw()\ \009\009\009\009bar.redraw()\ \009\009\009\009rule_top.redraw()\ \009\009\009\009rule_right.redraw()\ \009\009\009\009selector.redraw()\ \009\009\009\009open_bar.reposition(centerX-12,-(_sy+i*2+1))\ \009\009\009\009sleep(0)\ \009\009\009end\ \009\009end,\ \009\009open_resize_window = open_resize_window,\ \009\009close_resize_window = function()\ \009\009\009resizer = false\ \009\009\009bar.setTextColor(colors.gray)\ \009\009\009bar.setCursorPos(2,13)\ \009\009\009bar.write(\"S\")\ \009\009\009local _sx, _sy = open_bar.getSize()\ \009\009\009for i=-_sy/2,1 do\ \009\009\009\009term.clear()\ \009\009\009\009shadow.redraw()\ \009\009\009\009holst.redraw()\ \009\009\009\009bar.redraw()\ \009\009\009\009rule_top.redraw()\ \009\009\009\009rule_right.redraw()\ \009\009\009\009selector.redraw()\ \009\009\009\009bar_resize.reposition(centerX-12,-(_sy+i*2+1))\ \009\009\009\009sleep(0)\ \009\009\009end\ \009\009end,\ \009\009open_layers_menu = function()\ \009\009\009layerer = true\ \009\009\009local _sx, _sy = layer_bar.getSize()\ \009\009\009for i = 1,_sx/2 do\ \009\009\009\009layer_bar.reposition(scrX-i*2+1,1)\ \009\009\009\009sleep(0)\ \009\009\009end\ \009\009end,\ \009\009open_charPicker = function()\ \009\009\009charer = true\ \009\009\009local _sx, _sy = charPicker.getSize()\ \009\009\009for i = 0,_sx/3 do\ \009\009\009\009charPicker.reposition(scrX-i*3+1,1)\ \009\009\009\009sleep(0)\ \009\009\009end\ \009\009end,\ \009\009open_context_menu = open_context_menu,\ \009\009open_main_menu = open_main_menu,\ \009\009open_submenu = open_submenu,\ \009\009add_item_to_main_menu = function(item)\ \009\009\009main_menu[#main_menu+1] = item\ \009\009end,\ \009\009draw_pixel = draw_pixel,\ \009\009erase_pixel = erase_pixel,\ \009\009redraw_gui = redraw_gui,\ \009\009xSize = scrX,\ \009\009ySize = scrY,\ \009\009resize = resize,\ \009\009get_image_pos = function()\ \009\009\009return posX,posY\ \009\009end,\ \009\009get_image_size = function()\ \009\009\009return sizeX, sizeY\ \009\009end,\ \009\009can_draw = function()\ \009\009\009if not charer and not saver and not resizer and not opener and not select and not layerer then\ \009\009\009\009return true\ \009\009\009else\ \009\009\009\009return false\ \009\009\009end\ \009\009end,\ \009\009check_mouse_on_holst = checkHolstClick,\ \009\009set_color = change_color,\ \009\009get_colors = function(hex)\ \009\009\009if hex then\ \009\009\009\009return textColor, brushColor\ \009\009\009else\ \009\009\009\009return ColorsB[textColor], ColorsB[brushColor]\ \009\009\009end\ \009\009end,\ \009\009set_char = function(nchar)\ \009\009\009charSet = nchar\ \009\009end,\ \009\009pick_color = pick_color,\ \009\009change_layer = change_layer,\ \009\009redraw_layers = redraw_layers,\ \009\009get_current_layer = function()\ \009\009\009return cur_layer\ \009\009end,\ \009\009get_current_layer_image = function()\ \009\009\009if image[cur_layer] and layers[cur_layer] and layers[cur_layer].visible then\ \009\009\009\009return image[cur_layer]\ \009\009\009end\ \009\009end,\ \009\009save = save,\ \009\009open = open,\ \009\009get_file_name = function()\ \009\009\009return saveAs\ \009\009end,\ \009\009set_file_name = function(name)\ \009\009\009saveAs = name\ \009\009end,\ \009\009get_file_type = function()\ \009\009\009return fileType\ \009\009end,\ \009\009set_file_type = function(_type)\ \009\009\009fileType = _type\ \009\009end,\ \009\009get_empty_symbol = function()\ \009\009\009return empty_symbol\ \009\009end,\ \009\009set_empty_symbol = function(symbol)\ \009\009\009empty_symbol = symbol\ \009\009end,\ \009\009move_holst = function(posX,posY)\ \009\009\009blackBackground.redraw()\ \009\009\009blackBackground.reposition(posX,posY)\ \009\009\009shadow.reposition(posX+1,posY+1)\ \009\009\009holst.reposition(posX,posY)\ \009\009\009redraw_holst()\ \009\009end\ \009}\ --------------------------------------------------------------------------------\ \ \ local function runPhoenix()\ \009local px, py = 0,0\ \009local gx, gy = posX, posY\ \ \009local did_mod = nil\ \009local stat = nil\ \ \009for i=1,#modules do\ \009\009local function runModule()\ \009\009\009os.run(env,shell.resolve(modules[i].path))\ \009\009end\ \009\009modules[i].prg = coroutine.create(runModule)\ \009\009coroutine.resume(modules[i].prg, \"init\")\ \009end\ \ \009local event, side, x, y\ \009while running do\ \009\009event, side, x, y = os.pullEvent()\ \009\009term.setCursorPos(1,1)\ \ \009\009for i=1,#modules do\ \009\009\009if not modules[i].prg then\ \009\009\009\009local function runModule()\ \009\009\009\009\009os.run(env,shell.resolve(modules[i].path))\ \009\009\009\009end\ \009\009\009\009modules[i].prg = coroutine.create(runModule)\ \009\009\009end\ \009\009\009stat, did_mod = coroutine.resume(modules[i].prg, event, side, x, y)\ \009\009\009if did_mod then\ \009\009\009\009break\ \009\009\009end\ \009\009end\ \ \009\009if not did_mod or (stat and type(did_mod) == \"table\") then\ \009\009\009if event == \"mouse_click\" then\ \009\009\009\009if showBar then\ \009\009\009\009\009------------------------------------------------------------------------------------------\ \009\009\009\009\009if saver then\ \009\009\009\009\009\009if y>=4 and y<=6 and x >= centerX-12 and x <= centerX+13 then\ \009\009\009\009\009\009\009local trm = term.redirect(save_bar)\ \009\009\009\009\009\009\009term.setCursorPos(2,5)\ \009\009\009\009\009\009\009term.write(\" \")\ \009\009\009\009\009\009\009term.setCursorPos(2,5)\ \009\009\009\009\009\009\009saveAs = read()\ \009\009\009\009\009\009\009term.redirect(trm)\ \009\009\009\009\009\009elseif checkObj(\"btn_png\",x,y) then\ \009\009\009\009\009\009\009fileType = \"png\"\ \009\009\009\009\009\009\009drawType()\ \009\009\009\009\009\009elseif checkObj(\"btn_skch\",x,y) then\ \009\009\009\009\009\009\009fileType = \"skch\"\ \009\009\009\009\009\009\009drawType()\ \009\009\009\009\009\009elseif checkObj(\"btn_nft\",x,y) then\ \009\009\009\009\009\009\009fileType = \"nft\"\ \009\009\009\009\009\009\009drawType()\ \009\009\009\009\009\009elseif checkObj(\"btn_nfp\",x,y) then\ \009\009\009\009\009\009\009fileType = \"nfp\"\ \009\009\009\009\009\009\009drawType()\ \009\009\009\009\009\009elseif checkObj(\"btn_save_\",x,y) and saveAs ~= \"\" then\ \009\009\009\009\009\009\009save_bar.setBackgroundColor(accent_color)\ \009\009\009\009\009\009\009save_bar.setCursorPos(20,11)\ \009\009\009\009\009\009\009save_bar.write(\" save \")\ \009\009\009\009\009\009\009sleep(0)\ \009\009\009\009\009\009\009env.save(saveAs,fileType)\ \009\009\009\009\009\009\009sleep(0)\ \009\009\009\009\009\009\009save_bar.setBackgroundColor(colors.lightGray)\ \009\009\009\009\009\009\009save_bar.setCursorPos(20,11)\ \009\009\009\009\009\009\009save_bar.write(\" save \")\ \009\009\009\009\009\009\009env.close_save_window()\ \009\009\009\009\009\009else\ \009\009\009\009\009\009\009env.close_save_window()\ \009\009\009\009\009\009end\ \009\009\009\009\009--------------------------------------------------------------------------------------------------\ \009\009\009\009\009elseif resizer then\ \009\009\009\009\009\009if not select and resizer and not saver and y==4 and x >= centerX-12 and x <= centerX+13 then\ \009\009\009\009\009\009\009local trm = term.redirect(bar_resize)\ \009\009\009\009\009\009\009term.setCursorPos(9,4)\ \009\009\009\009\009\009\009term.write(\" \")\ \009\009\009\009\009\009\009term.setCursorPos(9,4)\ \009\009\009\009\009\009\009newX = read()\ \009\009\009\009\009\009\009term.redirect(trm)\ \009\009\009\009\009\009elseif not select and resizer and not saver and y==6 and x >= centerX-12 and x <= centerX+13 then\ \009\009\009\009\009\009\009local trm = term.redirect(bar_resize)\ \009\009\009\009\009\009\009term.setCursorPos(9,6)\ \009\009\009\009\009\009\009term.write(\" \")\ \009\009\009\009\009\009\009term.setCursorPos(9,6)\ \009\009\009\009\009\009\009newY = read()\ \009\009\009\009\009\009\009term.redirect(trm)\ \009\009\009\009\009\009elseif not select and resizer and not saver and checkObj(\"btn_resize_\",x,y) and newX ~= 0 and newY ~= 0 then\ \009\009\009\009\009\009\009bar_resize.setBackgroundColor(accent_color)\ \009\009\009\009\009\009\009bar_resize.setCursorPos(18,8)\ \009\009\009\009\009\009\009bar_resize.write(\" resize \")\ \009\009\009\009\009\009\009sleep(0)\ \009\009\009\009\009\009\009resize(newX,newY)\ \009\009\009\009\009\009\009sleep(0)\ \009\009\009\009\009\009\009bar_resize.setBackgroundColor(colors.lightGray)\ \009\009\009\009\009\009\009bar_resize.setCursorPos(18,8)\ \009\009\009\009\009\009\009bar_resize.write(\" resize \")\ \009\009\009\009\009\009\009env.close_resize_window()\ \009\009\009\009\009\009elseif not select and resizer and not saver then\ \009\009\009\009\009\009\009env.close_resize_window()\ \009\009\009\009\009\009end\ \009\009\009\009\009-------------------------------------------------------------------------------------\ \009\009\009\009\009elseif opener then\ \009\009\009\009\009\009if y>=4 and y<=6 and x >= centerX-12 and x <= centerX+13 then\ \009\009\009\009\009\009\009local trm = term.redirect(open_bar)\ \009\009\009\009\009\009\009term.setCursorPos(2,5)\ \009\009\009\009\009\009\009term.write(\" \")\ \009\009\009\009\009\009\009term.setCursorPos(2,5)\ \009\009\009\009\009\009\009saveAs = read()\ \009\009\009\009\009\009\009term.redirect(trm)\ \009\009\009\009\009\009elseif checkObj(\"btn_open_\",x,y) and saveAs ~= \"\" then\ \009\009\009\009\009\009\009open_bar.setBackgroundColor(accent_color)\ \009\009\009\009\009\009\009open_bar.setCursorPos(20,8)\ \009\009\009\009\009\009\009open_bar.write(\" open \")\ \009\009\009\009\009\009\009sleep(0.1)\ \009\009\009\009\009\009\009open_bar.setBackgroundColor(colors.lightGray)\ \009\009\009\009\009\009\009open_bar.setCursorPos(20,8)\ \009\009\009\009\009\009\009open_bar.write(\" open \")\ \009\009\009\009\009\009\009env.close_open_window()\ \009\009\009\009\009\009\009open(saveAs)\ \009\009\009\009\009\009\009sleep(0)\ \009\009\009\009\009\009\009open_bar.setBackgroundColor(colors.lightGray)\ \009\009\009\009\009\009\009open_bar.setCursorPos(8,11)\ \009\009\009\009\009\009\009open_bar.write(\" open \")\ \009\009\009\009\009\009else\ \009\009\009\009\009\009\009env.close_open_window()\ \009\009\009\009\009\009end\ \009\009\009\009\009----------------------------------------------------------------------------------------\ \009\009\009\009\009elseif charer then\ \009\009\009\009\009\009if x >= scrX-16 and x <= scrX-1 and y >= 3 and y <= scrY-1 then\ \009\009\009\009\009\009\009if y == 3 then\ \009\009\009\009\009\009\009\009charSet = string.char(x - scrX+17)\ \009\009\009\009\009\009\009else\ \009\009\009\009\009\009\009\009charSet = string.char((x - scrX+17) + (16*(y-3)-1))\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009drawPicker()\ \009\009\009\009\009\009else\ \009\009\009\009\009\009\009charer = false\ \009\009\009\009\009\009\009local _sx, _sy = charPicker.getSize()\ \009\009\009\009\009\009\009for i = 0,_sx/3 do\ \009\009\009\009\009\009\009\009term.clear()\ \009\009\009\009\009\009\009\009shadow.redraw()\ \009\009\009\009\009\009\009\009holst.redraw()\ \009\009\009\009\009\009\009\009rule_top.redraw()\ \009\009\009\009\009\009\009\009bar.redraw()\ \009\009\009\009\009\009\009\009selector.redraw()\ \009\009\009\009\009\009\009\009charPicker.reposition(scrX-17+i*3,1)\ \009\009\009\009\009\009\009\009sleep(0)\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009rule_top.redraw()\ \009\009\009\009\009\009\009rule_right.redraw()\ \009\009\009\009\009\009end\ \009\009\009\009\009elseif layerer then\ \009\009\009\009\009\009if x >= scrX-7 then\ \009\009\009\009\009\009\009if y==scrY then\ \009\009\009\009\009\009\009\009env.remove_layer(cur_layer)\ \009\009\009\009\009\009\009elseif y==4 then\ \009\009\009\009\009\009\009\009if x <= scrX-5 then\ \009\009\009\009\009\009\009\009\009env.change_layer(cur_layer-1)\ \009\009\009\009\009\009\009\009elseif x>= scrX-2 then\ \009\009\009\009\009\009\009\009\009env.change_layer(cur_layer+1)\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009elseif y== 6 then\ \009\009\009\009\009\009\009\009change_visible(cur_layer)\ \009\009\009\009\009\009\009else\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009else\ \009\009\009\009\009\009\009layerer = false\ \009\009\009\009\009\009\009local _sx, _sy = charPicker.getSize()\ \009\009\009\009\009\009\009for i = 0,_sx/2 do\ \009\009\009\009\009\009\009\009term.clear()\ \009\009\009\009\009\009\009\009shadow.redraw()\ \009\009\009\009\009\009\009\009holst.redraw()\ \009\009\009\009\009\009\009\009rule_top.redraw()\ \009\009\009\009\009\009\009\009bar.redraw()\ \009\009\009\009\009\009\009\009selector.redraw()\ \009\009\009\009\009\009\009\009layer_bar.reposition(scrX-7+i*2,1)\ \009\009\009\009\009\009\009\009sleep(0)\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009rule_top.redraw()\ \009\009\009\009\009\009\009rule_right.redraw()\ \009\009\009\009\009\009end\ \009\009\009\009\009----------------------------------------------------------------------------------------\ \009\009\009\009\009else\ \009\009\009\009\009\009if x<=3 and y==scrY then\ \009\009\009\009\009\009\009term.clear()\ \009\009\009\009\009\009\009term.setCursorPos(1,1)\ \009\009\009\009\009\009\009break\ \ \009\009\009\009\009\009elseif x == scrX and not select then\ \009\009\009\009\009\009\009if side == 2 then\ \009\009\009\009\009\009\009\009local out = env.open_main_menu()\ \ \009\009\009\009\009\009\009\009if out == \"Chars\" then\ \009\009\009\009\009\009\009\009\009env.open_charPicker()\ \009\009\009\009\009\009\009\009elseif out == \"Layers\" then\ \009\009\009\009\009\009\009\009\009env.open_layers_menu()\ \009\009\009\009\009\009\009\009elseif out then\ \009\009\009\009\009\009\009\009\009for i=1,#modules do\ \009\009\009\009\009\009\009\009\009\009if modules[i].prg then\ \009\009\009\009\009\009\009\009\009\009\009stat, did_mod = coroutine.resume(modules[i].prg, \"main_menu_pressed\", out)\ \009\009\009\009\009\009\009\009\009\009\009if did_mod then\ \009\009\009\009\009\009\009\009\009\009\009\009break\ \009\009\009\009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009else\ \009\009\009\009\009\009\009\009\009redraw_gui()\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009elseif side == 1 then\ \009\009\009\009\009\009\009\009env.open_layers_menu()\ \009\009\009\009\009\009\009end\ \ \009\009\009\009\009\009elseif checkObj(\"btn_save\",x,y) and not select then\ \009\009\009\009\009\009\009open_save_window()\ \009\009\009\009\009\009elseif checkObj(\"btn_resize\",x,y) and not select then\ \009\009\009\009\009\009\009open_resize_window()\ \009\009\009\009\009\009elseif x==1 and y==1 and not select then\ \009\009\009\009\009\009\009showBar = false\ \009\009\009\009\009\009\009for i=-1,1 do\ \009\009\009\009\009\009\009\009term.clear()\ \009\009\009\009\009\009\009\009shadow.redraw()\ \009\009\009\009\009\009\009\009holst.redraw()\ \009\009\009\009\009\009\009\009bar.reposition(-i,1)\ \009\009\009\009\009\009\009\009rule_top.reposition(4,-i)\ \009\009\009\009\009\009\009\009rule_right.reposition(scrX+i+1,2)\ \009\009\009\009\009\009\009\009selector.redraw()\ \009\009\009\009\009\009\009\009sleep(0)\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009elseif checkObj(\"btn_color\",x,y) and not select and side == 1 then\ \009\009\009\009\009\009\009select = true\ \009\009\009\009\009\009\009bar.setTextColor(accent_color)\ \009\009\009\009\009\009\009bar.setCursorPos(2,11)\ \009\009\009\009\009\009\009bar.write(\"C\")\ \009\009\009\009\009\009\009for i=1,4 do\ \009\009\009\009\009\009\009\009bar_color.reposition(i,1)\ \009\009\009\009\009\009\009\009bar.redraw()\ \009\009\009\009\009\009\009\009selector.redraw()\ \009\009\009\009\009\009\009\009sleep(0)\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009elseif checkObj(\"btn_color\",x,y) and side == 2 then\ \009\009\009\009\009\009\009local xx,xy = selector.getPosition()\ \009\009\009\009\009\009\009while xy ~= y do\ \009\009\009\009\009\009\009\009if xy > y then\ \009\009\009\009\009\009\009\009\009xy = xy-1\ \009\009\009\009\009\009\009\009else\ \009\009\009\009\009\009\009\009\009xy = xy+1\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009bar.redraw()\ \009\009\009\009\009\009\009\009selector.reposition(1,xy)\ \009\009\009\009\009\009\009\009sleep(0)\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009tool = \"C\"\ \009\009\009\009\009\009elseif checkObj(\"B\",x,y) then\ \009\009\009\009\009\009\009local xx,xy = selector.getPosition()\ \009\009\009\009\009\009\009while xy ~= y do\ \009\009\009\009\009\009\009\009if xy > y then\ \009\009\009\009\009\009\009\009\009xy = xy-1\ \009\009\009\009\009\009\009\009else\ \009\009\009\009\009\009\009\009\009xy = xy+1\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009bar.redraw()\ \009\009\009\009\009\009\009\009selector.reposition(1,xy)\ \009\009\009\009\009\009\009\009sleep(0)\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009tool = \"B\"\ \009\009\009\009\009\009elseif checkObj(\"E\",x,y) then\ \009\009\009\009\009\009\009local xx,xy = selector.getPosition()\ \009\009\009\009\009\009\009while xy ~= y do\ \009\009\009\009\009\009\009\009if xy > y then\ \009\009\009\009\009\009\009\009\009xy = xy-1\ \009\009\009\009\009\009\009\009else\ \009\009\009\009\009\009\009\009\009xy = xy+1\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009bar.redraw()\ \009\009\009\009\009\009\009\009selector.reposition(1,xy)\ \009\009\009\009\009\009\009\009sleep(0)\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009tool = \"E\"\ \009\009\009\009\009\009elseif checkObj(\"F\",x,y) then\ \009\009\009\009\009\009\009local xx,xy = selector.getPosition()\ \009\009\009\009\009\009\009while xy ~= y do\ \009\009\009\009\009\009\009\009if xy > y then\ \009\009\009\009\009\009\009\009\009xy = xy-1\ \009\009\009\009\009\009\009\009else\ \009\009\009\009\009\009\009\009\009xy = xy+1\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009bar.redraw()\ \009\009\009\009\009\009\009\009selector.reposition(1,xy)\ \009\009\009\009\009\009\009\009sleep(0)\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009tool = \"F\"\ \009\009\009\009\009\009elseif checkObj(\"M\", x,y) then\ \009\009\009\009\009\009\009local xx, xy = selector.getPosition()\ \009\009\009\009\009\009\009while xy ~= y do\ \009\009\009\009\009\009\009\009if xy > y then\ \009\009\009\009\009\009\009\009\009xy = xy-1\ \009\009\009\009\009\009\009\009else\ \009\009\009\009\009\009\009\009\009xy = xy+1\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009bar.redraw()\ \009\009\009\009\009\009\009\009selector.reposition(1,xy)\ \009\009\009\009\009\009\009\009sleep(0)\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009tool = \"M\"\ \009\009\009\009\009\009elseif checkObj(\"btn_open\",x,y) and not select then\ \009\009\009\009\009\009\009open_open_window()\ \009\009\009\009\009\009elseif (tool == \"B\" or tool == \"E\" or tool == \"C\") and not select then\ \009\009\009\009\009\009\009if tool == \"B\" and side == 1 then\ \009\009\009\009\009\009\009\009draw_pixel(x,y)\ \009\009\009\009\009\009\009elseif tool == \"E\" and side == 1 then\ \009\009\009\009\009\009\009\009erase_pixel(x,y)\ \009\009\009\009\009\009\009elseif tool == \"C\" then\ \009\009\009\009\009\009\009\009if side == 1 then\ \009\009\009\009\009\009\009\009\009env.pick_color(x,y,\"brush\")\ \009\009\009\009\009\009\009\009elseif side == 2 then\ \009\009\009\009\009\009\009\009\009env.pick_color(x,y,\"char\")\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009elseif tool == \"F\" and not select and side == 1 then\ \009\009\009\009\009\009\009local bx, by = x-posX+1-math.floor(sX/2),y-math.floor(sY/2)-posY+1\ \009\009\009\009\009\009\009if image[cur_layer][by] and image[cur_layer][by][bx] then\ \009\009\009\009\009\009\009\009local color = string.sub(image[cur_layer][by][bx],3)\ \009\009\009\009\009\009\009\009fill(bx,by,color)\ \009\009\009\009\009\009\009\009-- bar.redraw()\ \009\009\009\009\009\009\009\009-- selector.redraw()\ \009\009\009\009\009\009\009\009-- rule_top.redraw()\ \009\009\009\009\009\009\009\009-- rule_right.redraw()\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009elseif select then\ \009\009\009\009\009\009\009if x>=4 and x<=7 and y>=2 and y<=17 then\ \009\009\009\009\009\009\009\009local sel = color_selector\ \009\009\009\009\009\009\009\009if side == 1 then\ \009\009\009\009\009\009\009\009\009brushColor = 2^(y-2)\ \009\009\009\009\009\009\009\009else\ \009\009\009\009\009\009\009\009\009textColor = 2^(y-2)\ \009\009\009\009\009\009\009\009\009sel = color_selectorT\ \009\009\009\009\009\009\009\009end\ \ \009\009\009\009\009\009\009\009bar_color.setBackgroundColor(brushColor)\ \009\009\009\009\009\009\009\009bar_color.setTextColor(textColor)\ \009\009\009\009\009\009\009\009bar_color.setCursorPos(2,19)\ \009\009\009\009\009\009\009\009bar_color.write(charSet)\ \009\009\009\009\009\009\009\009bar_color.setBackgroundColor(textColor)\ \009\009\009\009\009\009\009\009bar_color.setCursorPos(3,19)\ \009\009\009\009\009\009\009\009bar_color.write(\" \")\ \ \009\009\009\009\009\009\009\009local xx,xy = sel.getPosition()\ \009\009\009\009\009\009\009\009while xy ~= y do\ \009\009\009\009\009\009\009\009\009bar_color.setBackgroundColor(colors.gray)\ \009\009\009\009\009\009\009\009\009bar_color.setCursorPos(xx,xy)\ \009\009\009\009\009\009\009\009\009bar_color.write(\" \")\ \009\009\009\009\009\009\009\009\009if xy > y then\ \009\009\009\009\009\009\009\009\009\009xy = xy-1\ \009\009\009\009\009\009\009\009\009else\ \009\009\009\009\009\009\009\009\009\009xy = xy+1\ \009\009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009\009\009sel.reposition(xx,xy)\ \009\009\009\009\009\009\009\009\009sleep(0)\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009else\ \009\009\009\009\009\009\009\009select = false\ \009\009\009\009\009\009\009\009bar.setTextColor(colors.gray)\ \009\009\009\009\009\009\009\009bar.setCursorPos(2,11)\ \009\009\009\009\009\009\009\009bar.write(\"C\")\ \009\009\009\009\009\009\009\009sleep(0)\ \009\009\009\009\009\009\009\009for i=-4,4 do\ \009\009\009\009\009\009\009\009\009term.clear()\ \009\009\009\009\009\009\009\009\009shadow.redraw()\ \009\009\009\009\009\009\009\009\009holst.redraw()\ \009\009\009\009\009\009\009\009\009rule_top.redraw()\ \009\009\009\009\009\009\009\009\009bar_color.reposition(-i,1)\ \009\009\009\009\009\009\009\009\009bar.redraw()\ \009\009\009\009\009\009\009\009\009rule_right.redraw()\ \009\009\009\009\009\009\009\009\009selector.redraw()\ \009\009\009\009\009\009\009\009\009sleep(0)\ \009\009\009\009\009\009\009\009end\ \009\009\009\009\009\009\009end\ \009\009\009\009\009\009end\ \009\009\009\009\009end\ \009\009\009\009elseif not showBar then\ \009\009\009\009\009if x==1 then\ \009\009\009\009\009\009showBar = true\ \009\009\009\009\009\009for i=-1,1 do\ \009\009\009\009\009\009\009bar.reposition(i,1)\ \009\009\009\009\009\009\009rule_top.reposition(4,i)\ \009\009\009\009\009\009\009rule_right.reposition(scrX-i+1,2)\ \009\009\009\009\009\009\009selector.redraw()\ \009\009\009\009\009\009\009sleep(0)\ \009\009\009\009\009\009end\ \009\009\009\009\009elseif (tool == \"B\" or tool == \"E\") and side == 1 then\ \009\009\009\009\009\009if tool == \"B\" then\ \009\009\009\009\009\009\009draw_pixel(x,y)\ \009\009\009\009\009\009elseif tool == \"E\" then\ \009\009\009\009\009\009\009erase_pixel(x,y)\ \009\009\009\009\009\009end\ \009\009\009\009\009elseif tool == \"F\" and side == 1 then\ \009\009\009\009\009\009local bx, by = x-posX+1-math.floor(sX/2),y-math.floor(sY/2)-posY+1\ \009\009\009\009\009\009if image[cur_layer][by] and image[cur_layer][by][bx] then\ \009\009\009\009\009\009\009local color = string.sub(image[cur_layer][by][bx],3)\ \009\009\009\009\009\009\009fill(bx,by,color)\ \009\009\009\009\009\009\009-- bar.redraw()\ \009\009\009\009\009\009\009-- selector.redraw()\ \009\009\009\009\009\009\009-- rule_top.redraw()\ \009\009\009\009\009\009\009-- rule_right.redraw()\ \009\009\009\009\009\009end\ \009\009\009\009\009end\ \009\009\009\009end\ \009\009\009\009if side == 2 then\ \009\009\009\009\009px, py = x, y\ \009\009\009\009\009gx, gy = posX, posY\ \009\009\009\009elseif side == 1 and tool == \"M\" then\ \009\009\009\009\009px, py = x, y\ \009\009\009\009\009gx, gy = layers[cur_layer].pos.x, layers[cur_layer].pos.y\ \009\009\009\009end\ \009----------------------------------------------------------------------------------------\ \009\009\009elseif event == \"mouse_drag\" then\ \009\009\009\009if not select and not resizer and not saver and not opener and side == 2 then\ \009\009\009\009\009-- term.clear()\ \009\009\009\009\009posX = gx - (px - x)\ \009\009\009\009\009posY = gy - (py - y)\ \ \009\009\009\009\009env.move_holst(posX, posY)\ \009\009\009\009elseif (tool == \"B\" or tool == \"E\" or tool == \"M\") and x>=bar.getPosition()+3 and not select and not resizer and not saver and not opener and side == 1 then\ \009\009\009\009\009if tool == \"B\" then\ \009\009\009\009\009\009draw_pixel(x,y)\ \009\009\009\009\009elseif tool == \"E\" then\ \009\009\009\009\009\009erase_pixel(x,y)\ \009\009\009\009\009elseif tool == \"M\" then\ \009\009\009\009\009\009reposition_layer(-(px - x), -(py - y))\ \009\009\009\009\009\009px, py = x, y\ \009\009\009\009\009end\ \009\009\009\009end\ \009\009\009elseif event == \"char\" then\ \009\009\009\009charSet = side\ \009\009\009\009bar_color.setBackgroundColor(brushColor)\ \009\009\009\009bar_color.setTextColor(textColor)\ \009\009\009\009bar_color.setCursorPos(2,19)\ \009\009\009\009bar_color.write(charSet)\ \009\009\009\009bar_color.setBackgroundColor(textColor)\ \009\009\009\009bar_color.setCursorPos(3,19)\ \009\009\009\009bar_color.write(\" \")\ \009\009\009elseif event == \"key\" then\ \009\009\009\009if tool == \"M\" and side == keys.up then\ \009\009\009\009\009reposition_layer(0, -1)\ \009\009\009\009elseif tool == \"M\" and side == keys.down then\ \009\009\009\009\009reposition_layer(0, 1)\ \009\009\009\009elseif tool == \"M\" and side == keys.left then\ \009\009\009\009\009reposition_layer(-1, 0)\ \009\009\009\009elseif tool == \"M\" and side == keys.right then\ \009\009\009\009\009reposition_layer(1, 0)\ \009\009\009\009end\ \009\009\009end\ \009\009end\ \009end\ \009term.clear()\ \009term.setCursorPos(1,1)\ end\ \ term.setCursorPos(1,1)\ \ if arg[1] == \"--open\" or arg[1] == \"-o\" then\ \009if fs.exists(shell.resolve(\"modules.cfg\")) then\ \009\009local file = fs.open(shell.resolve(\"modules.cfg\"),\"r\")\ \009\009modules = textutils.unserialize(file.readAll())\ \009\009file.close()\ \009end\ \009open(arg[2])\ \ \009runPhoenix()\ elseif arg[1] == \"--get-modules\" or arg[1] == \"-m\" then\ \009term.setBackgroundColor(colors.black)\ \009term.setTextColor(colors.white)\ \009term.clear()\ \009print(\" Phoenix: Active modules\")\ \ \009local file = fs.open(shell.resolve(\"modules.cfg\"),\"r\")\ \009local modules\ \009if file then\ \009\009modules = textutils.unserialize(file.readAll())\ \009end\ \009file.close()\ \ \009for i=1,#modules do\ \009\009print(\"\")\ \009\009term.setTextColor(colors.orange)\ \009\009write(\" - \"..modules[i].name..\": \")\ \009\009term.setTextColor(colors.white)\ \009\009print(modules[i].path)\ \009end\ \009print(\"\")\ elseif arg[1] == \"--help\" or arg[1] == \"-h\" then\ \009term.setBackgroundColor(colors.black)\ \009term.setTextColor(colors.white)\ \009term.clear()\ \009print(\" Phoenix:\")\ \009print(\"\")\ \009print(\" --open <path> - open file\")\ \009print(\" --get-modules - list of active modules\")\ \009print(\" --help - show this message\")\ \009print(\"\")\ else\ \009term.clear()\ \009term.setCursorPos(1,1)\ \009local loadScreen = window.create(term.current(),centerX-14,centerY-7,32,16)\ \009loadScreen.setBackgroundColor(colors.gray)\ \009loadScreen.setTextColor(colors.lightGray)\ \009loadScreen.clear()\ \009draw(loadScreen,splash,1,1)\ \009loadScreen.setBackgroundColor(colors.gray)\ \009loadScreen.setTextColor(colors.lightGray)\ \009loadScreen.setCursorPos(2,12)\ \009loadScreen.write(\"Loading...\")\ -------------------------------------------Load Modules--------------------------\ \009if fs.exists(shell.resolve(\"modules.cfg\")) then\ \009\009local file = fs.open(shell.resolve(\"modules.cfg\"),\"r\")\ \009\009modules = textutils.unserialize(file.readAll())\ \009\009file.close()\ \009\009for i=1,#modules do\ \009\009\009loadScreen.setCursorPos(2,14)\ \009\009\009loadScreen.write(\" \")\ \009\009\009loadScreen.setCursorPos(2,14)\ \009\009\009loadScreen.write(\"Loading module: \"..modules[i].name)\ \009\009\009sleep(0.5)\ \009\009end\ \009end\ \009newLayer()\ \009loadScreen.setCursorPos(2,14)\ \009loadScreen.write(\" \")\ \009loadScreen.setCursorPos(2,14)\ \009loadScreen.write(\"Creating new image\")\ \009sleep(0.5)\ \009term.clear()\ \009resize(startXSize, startYSize)\ \009shadow.redraw()\ \009holst.redraw()\ \009bar.redraw()\ \009rule_top.redraw()\ \009rule_right.redraw()\ \009selector.redraw()\ \ \009runPhoenix()\ end", path = "User/Apps/Phoenix/Start.x", }, { path = "User/Storage/Audio", }, { path = "User/Storage/Downloads", }, { path = "User/Storage/Images", }, { text = "\ settings.set(\"shell.allow_disk_startup\", false)\ settings.save(\".settings\")\ \ local accent_color = colors.cyan\ local text_color = colors.lightGray\ local text_color_alt = colors.gray\ local background_color = colors.white\ \ local waitFor = 5\ local version = \"0.2.2\"\ \ local name = \"Legacy\"\ \ \ term.setBackgroundColor(background_color)\ \ term.clear()\ term.setCursorPos(1,1)\ term.setTextColor(accent_color)\ term.write(name)\ term.setTextColor(text_color)\ term.write(' bootloader ')\ print('v'..version)\ term.setTextColor(text_color)\ print()\ print('Boot from:')\ \ local xSize, ySize = term.getSize()\ local bootFrom = 1\ local drives = {}\ local label = os.getComputerLabel()\ local boot = false\ local key = false\ \ if not label then label = 'nil' end\ \ function os.run( _tEnv, _sPath, ... )\ local tArgs = { ... }\ local tEnv = _tEnv\ setmetatable( tEnv, { __index = _G } )\ local fnFile, err = loadfile( _sPath, tEnv )\ if fnFile then\ local ok, err = pcall( function()\ fnFile( table.unpack( tArgs ) )\ end )\ if not ok then\ if err and err ~= \"\" then\ printError( err )\ end\ return err\ end\ return nil\ end\ if err and err ~= \"\" then\ printError( err )\ end\ return err\ end\ \ if settings.get(\"boot.addNewItem\") then\ drives[#drives+1] = settings.get(\"boot.addNewItem\")\ settings.unset(\"boot.addNewItem\")\ settings.save(\".settings\")\ end\ \ drives[#drives+1] = {}\ if fs.exists(\"/System/Build.info\") then\ local osinfo = fs.open(\"/System/Build.info\", \"r\")\ osinfo = textutils.unserialize(osinfo.readAll())\ drives[#drives] = {name = osinfo.name..\" \"..osinfo.build..\" \"..label, path = osinfo.core_path, args = ''}\ elseif fs.exists('/System/Core.x') then\ drives[#drives] = {name = \"Unknown Legacy family OS \"..label, path = '/System/Core.x', args = ''}\ elseif fs.exists('/launcher') then\ drives[#drives] = {name = \"VedroidOS \"..label, path = '/launcher', args = ''}\ else\ drives[#drives] = {name = \"HDD Shell \"..label, path = '', args = ''}\ end\ \ local fileList = fs.list('/')\ \ for i=1,#fileList do\ \009if fs.isDir(fileList[i]) and fs.getDrive(fileList[i]) and fs.getDrive(fileList[i]) ~= 'hdd' and string.sub(fileList[i],1,4) == 'disk' then\ \009\009local find = false\ \009\009local files = fs.list(fileList[i])\ \009\009local point = ''\ \009\009for ii=1,#files do\ \009\009\009if not fs.isDir(files[ii]) and (files[ii] == 'startup' or files[ii] == 'startup.lua') then\ \009\009\009\009point = fileList[i]..'/'..files[ii]\ \009\009\009\009find = true\ \009\009\009\009break\ \009\009\009elseif fs.isDir(files[ii]) and files[ii] == 'startup' and (fs.exists(files[ii]..'/startup') or fs.exists(files[ii]..'/startup.lua')) then\ \009\009\009\009point = fileList[i]..'/'..files[ii]..'/startup'\ \009\009\009\009find = true\ \009\009\009\009break\ \009\009\009end\ \009\009end\ \009\009if find then\ \009\009\009local dlabel = disk.getLabel(fs.getDrive(fileList[i]))\ \009\009\009if not dlabel then\ \009\009\009\009dlabel = 'nil'\ \009\009\009end\ \009\009\009drives[#drives+1] = {}\ \009\009\009drives[#drives]['name'] = fs.getDrive(fileList[i])..' drive '..dlabel\ \009\009\009drives[#drives]['path'] = point\ \009\009\009drives[#drives]['args'] = ''\ \009\009end\ \009end\ end\ \ local function drawDrives()\ \009term.setCursorPos(1,5)\ \009for i=1,#drives do\ \009\009term.setTextColor(text_color_alt)\ \009\009if i == bootFrom then\ \009\009\009term.setTextColor(accent_color)\ \009\009end\ \009\009print(i..' '..drives[i]['name'])\ \009end\ \009term.setTextColor(text_color)\ \009print()\ end\ \ drawDrives()\ print('Press \"e\" for configure')\ print('Press \"Enter\" for boot')\ \ local pullEvent = function()\ \009local event, side, x, y = os.pullEventRaw()\ \009if event ~= \"terminate\" then\ \009\009return event, side, x, y\ \009else\ \009\009os.shutdown()\ \009end\ end\ \ local function strToTable(str)\ local tbl = {}\ local wrd = \"\"\ for i=1,#str do\ local chr = string.sub(str,i,i)\ if chr == \" \" then\ tbl[#tbl+1] = wrd\ wrd = \"\"\ else\ wrd = wrd..chr\ end\ end\ tbl[#tbl+1] = wrd\ return tbl\ end\ \ local function run()\ \009while not boot or key do\ \009\009local event, side, x, y = pullEvent()\ \009\009if event == 'mouse_click' or event == 'key' then\ \009\009\009if not key then\ \009\009\009\009key = true\ \009\009\009\009paintutils.drawLine(1,ySize,xSize,ySize,background_color)\ \009\009\009end\ \009\009\009if event == 'key' and side >= 2 and side <= #drives+1 then\ \009\009\009\009bootFrom = side-1\ \009\009\009\009drawDrives()\ \009\009\009elseif event == 'key' and side == keys.up and bootFrom > 1 then\ \009\009\009\009bootFrom = bootFrom - 1\ \009\009\009\009drawDrives()\ \009\009\009elseif event == 'key' and side == keys.down and bootFrom < #drives then\ \009\009\009\009bootFrom = bootFrom + 1\ \009\009\009\009drawDrives()\ \009\009\009elseif event == 'key' and side == keys.e then\ \009\009\009\009paintutils.drawLine(1,6+#drives,xSize,6+#drives,background_color)\ \009\009\009\009term.setCursorPos(1,6+#drives)\ \009\009\009\009term.write('Args: ')\ \009\009\009\009local args = ''\ local fr = true\ \009\009\009\009term.setCursorBlink(true)\ \009\009\009\009while true do\ \009\009\009\009\009local ev, sd = pullEvent()\ if not fr then\ \009\009\009\009\009if ev == 'key' then\ \009\009\009\009\009\009if sd == keys.enter then\ \009\009\009\009\009\009\009drives[bootFrom]['args'] = args\ \009\009\009\009\009\009\009term.setCursorPos(7,6+#drives)\ \009\009\009\009\009\009\009term.write(drives[bootFrom]['args'])\ \009\009\009\009\009\009\009boot = true\ \009\009\009\009\009\009\009key = false\ \009\009\009\009\009\009\009break\ \009\009\009\009\009\009elseif sd == keys.backspace then\ \009\009\009\009\009\009\009args = string.sub(args,1,#args-1)\ \009\009\009\009\009\009\009term.setCursorPos(7+#args,6+#drives)\ \009\009\009\009\009\009\009term.write(' ')\ \009\009\009\009\009\009end\ \009\009\009\009\009elseif ev == 'char' and sd ~= nil then\ \009\009\009\009\009\009args = args..sd\ \009\009\009\009\009end\ \009\009\009\009\009term.setCursorPos(7,6+#drives)\ \009\009\009\009\009term.write(args)\ else\ fr = false\ end\ \009\009\009\009end\ \009\009\009\009term.setCursorBlink(false)\ \009\009\009elseif event == 'key' and side == keys.enter then\ \009\009\009\009break\ \009\009\009end\ \009\009end\ \009end\ end\ \ local function timer()\ \009for i=1,waitFor do\ \009\009if not key then\ \009\009\009term.setCursorPos(1,ySize)\ \009\009\009term.write('Waiting '..(waitFor+1-i)..' sec')\ \009\009\009sleep(1)\ \009\009\009paintutils.drawLine(1,ySize,xSize,ySize,background_color)\ \009\009else\ \009\009\009while true do\ \009\009\009\009sleep(1)\ \009\009\009end\ \009\009end\ \009end\ \009boot = true\ end\ \ parallel.waitForAny(run,timer)\ \ local argsTable = strToTable(drives[bootFrom]['args'])\ --term.setCursorPos(1,ySize-1)\ --print(drives[bootFrom]['args'])\ --term.write('Booting from '..drives[bootFrom]['name'])\ sleep(0)\ term.setBackgroundColor(colors.black)\ term.clear()\ term.setCursorPos(1,1)\ local osError\ if drives[bootFrom]['path'] ~= \"\" then\ osError = os.run({shell = shell},drives[bootFrom]['path'],unpack(argsTable))\ else\ shell.run(\"shell\")\ end\ \ if osError then\ \009term.redirect(term.native())\ \009term.setBackgroundColor(background_color)\ \009term.clear()\ \009term.setTextColor(text_color)\ \009term.setCursorPos(2,2)\ \009term.write('OS has been crashed')\ \009term.setCursorPos(2,5)\ \009term.setTextColor(colors.red)\ \009print('Error in: '..osError)\ \009term.setTextColor(text_color)\ \009term.setCursorPos(2,ySize-2)\ \009term.write('Press any key to reboot')\ \009term.setCursorPos(2,ySize-1)\ \009term.write('Press Enter to shutdown')\ \009while true do\ \009\009local event, side = os.pullEvent()\ \009\009if event == 'key' or event == 'mouse_click' then\ \009\009\009if event == 'key' and side == keys.enter then\ \009\009\009\009os.shutdown()\ \009\009\009else\ \009\009\009\009os.reboot()\ \009\009\009end\ \009\009end\ \009end\ else\ os.reboot()\ end", path = "startup", }, }