Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- GridOS version 0.1.0 by CrazedProgrammer
- -- This is a discontinued project.
- -- You may do anything with this and you don't have to give credit.
- local function loadAPI(name, str)
- local env = {}
- setmetatable(env, {__index = _G})
- local fn, err = loadstring(str, name)
- if fn then
- setfenv(fn, env)
- local ok, err = pcall(fn)
- if not ok then
- error(err)
- end
- else
- error(err)
- end
- local api = {}
- for k,v in pairs(env) do
- if k ~= "_ENV" then
- api[k] = v
- end
- end
- return api
- end
- local surface = nil
- local startmenu = "local a={...}local b=a\[1\]local c=a\[2\]local d=a\[3\]local e,f,g,h,i=nil;local j=os.startTimer(0)local function k()g,h=term.getSize()i=b.create(g,h)e,f=2,2;if g<18 then e=1 end;if h<7 then f=1 end end;multishell.setTitle(multishell.getCurrent(),\"start menu\")k()while true do local l={os.pullEvent()}if l\[1\]==\"timer\"and l\[2\]==j then i:clear(nil,colors.white,colors.black)i:drawText(e,f,\"Launch Shell\")i:drawText(e,f+1,\"Shortcut Settings\")i:drawText(e,f+2,\"Skin Settings\")i:drawText(e,f+3,\"Close GridOS\")i:drawText(e,f+4,\"Shutdown\")i:drawText(e,f+5,\"Reboot\")i:render()j=os.startTimer(0)elseif l\[1\]==\"term_resize\"then k()elseif l\[1\]==\"mouse_click\"then if l\[3\]>=e and l\[3\]<=e+16 then if l\[4\]==f then multishell.setFocus(multishell.launch({shell=shell,multishell=multishell},\"rom/programs/shell\"))elseif l\[4\]==f+3 then d\[1\]=false elseif l\[4\]==f+4 then os.shutdown()elseif l\[4\]==f+5 then os.reboot()end end end end"
- local dir = fs.getDir(shell.getRunningProgram()).."/"
- local config = nil
- local parentTerm = term.current()
- local parentShell = shell
- local width, height, surf = nil
- local processes = { }
- local multishell = { }
- local order = { }
- local current = 1
- local offset = 0
- local mode = 0
- local lockX, lockY = nil
- local running = {true}
- local osTimer = os.startTimer(0)
- local function loadConfig()
- local f = fs.open(dir.."config.tab", "r")
- if f then
- config = textutils.unserialize(f.readAll())
- f.close()
- else
- config = {bounds={},skin={bc=256,gridbc=32768,gridtc=1,taskbc=128,taskscrbc=128,taskscrtc=32768,taskacttc=1,tasknortc=256,taskmintc=32768,wintopbc=128,winrightbc=128,wintitletc=1,winminbc=128,winmintc=32768,winclosebc=128,winclosetc=16384,winresizebc=128,winresizetc=32768}}
- end
- end
- local function saveConfig()
- if config then
- local f = fs.open(dir.."config.tab", "w")
- if f then
- f.write(textutils.serialize(config))
- f.close()
- end
- end
- end
- local function checkOffset()
- if offset < 0 then
- offset = 0
- return
- elseif offset ~= 0 then
- local m = 0
- for i=1,#processes do
- m = m + #processes[i].title + 2
- end
- if offset > m - width + 4 then
- offset = m - width + 4
- end
- if offset < 0 then
- offset = 0
- end
- end
- end
- local function removeProcess(n)
- config.bounds[processes[n].path] = {x = processes[n].x, y = processes[n].y, width = processes[n].width, height = processes[n].height}
- table.remove(processes, n)
- for i=1,#order do
- if order[i] == n then
- table.remove(order, i)
- break
- end
- end
- for i=1,#order do
- if order[i] > n then
- order[i] = order[i] - 1
- end
- end
- checkOffset()
- end
- local function resumeProcess(n, event, ...)
- if processes[n].filter == nil or processes[n].filter == event or event == "terminate" then
- current = n
- local prev = term.redirect(processes[n].term)
- local ok, result = coroutine.resume(processes[n].coroutine, event, ...)
- processes[n].term = term.current()
- term.redirect(prev)
- if ok then
- processes[n].filter = result
- else
- printError(result)
- end
- if coroutine.status(processes[n].coroutine) == "dead" then
- removeProcess(n)
- end
- end
- end
- local function resizeProcess(n, width, height)
- if width < 6 then
- width = 6
- end
- if height < 2 then
- height = 2
- end
- if width ~= processes[n].width or height ~= processes[n].height then
- processes[n].width = width
- processes[n].height = height
- local surf = surface.create(width - 1, height - 1)
- surf:drawSurface(1, 1, processes[n].surface)
- surf.blink, surf.curX, surf.curY = processes[n].surface.blink, processes[n].surface.curX, processes[n].surface.curY
- processes[n].surface = surf
- for k,v in pairs(surf:getTerm()) do
- processes[n].surfterm[k] = v
- end
- resumeProcess(n, "term_resize")
- end
- end
- local function getBounds(x, y, w, h)
- if w > width then
- w = width
- end
- if h > height - 1 then
- h = height - 1
- end
- if y > height then
- y = height
- end
- if y < 2 then
- y = 2
- end
- if x > width then
- x = width
- end
- if x < 1 then
- x = 1
- end
- return x, y, w, h
- end
- local function distributeEvent(...)
- local limit = #processes
- for i=1,limit do
- resumeProcess(i, ...)
- end
- end
- local function getFront()
- local p = nil
- for i=1,#order do
- if not processes[order[i]].minimized then
- p = order[i]
- break
- end
- end
- if p then
- processes[p].interacted = true
- return p
- end
- end
- local function resize()
- width, height = parentTerm.getSize()
- surf = surface.create(width, height)
- local limit = #processes
- for i=1,limit do
- local x, y, w, h = getBounds(processes[i].x, processes[i].y, processes[i].width, processes[i].height)
- processes[i].x, processes[i].y = x, y
- if w ~= processes[i].width or h ~= processes[i].height then
- resizeProcess(i, w, h)
- end
- end
- end
- function multishell.getFocus()
- return getFront() or 1
- end
- function multishell.setFocus(n)
- if processes[n] then
- if n ~= getFront() then
- for i=1,#order do
- if order[i] == n then
- table.remove(order, i)
- break
- end
- end
- table.insert(order, 1, n)
- processes[n].minimized = false
- end
- processes[n].interacted = true
- return true
- end
- return false
- end
- function multishell.getTitle(n)
- if processes[n] then
- return processes[n].title
- end
- end
- function multishell.setTitle(n, title)
- if processes[n] then
- if title ~= "shell" then
- --os.sleep(0.1)
- end
- processes[n].title = title
- end
- end
- function multishell.getCurrent()
- return current
- end
- function multishell.launch(env, path, ...)
- local process = { }
- local p = #processes + 1
- process.path = path
- process.title = fs.getName(path)
- if path == "rom/programs/shell" and arg[1] then
- process.path = arg[1]
- process.title = fs.getName(arg[1])
- end
- if config.bounds[path] then
- process.x, process.y, process.width, process.height = config.bounds[path].x, config.bounds[path].y, config.bounds[path].width, config.bounds[path].height
- else
- process.x, process.y, process.width, process.height = math.random(2, 10), math.random(2,5), 40, 15
- end
- process.x, process.y, process.width, process.height = getBounds(process.x, process.y, process.width, process.height)
- process.minimized = false
- process.surface = surface.create(process.width - 1, process.height - 1)
- process.surfterm = process.surface:getTerm()
- process.term = process.surfterm
- process.coroutine = coroutine.create(function ()
- os.run(env, path, unpack(arg))
- if not process.interacted then
- term.setCursorBlink(false)
- print("Press any key to continue")
- os.pullEvent("char")
- end
- end)
- processes[p] = process
- table.insert(order, p)
- resumeProcess(p)
- return p
- end
- function multishell.getCount()
- return #processes
- end
- local function run()
- surface = loadAPI("surface", "version=\"1.6.2\"local a,b,c,d,e=math.floor,math.cos,math.sin,table.concat,{\[1\]=\"0\",\[2\]=\"1\",\[4\]=\"2\",\[8\]=\"3\",\[16\]=\"4\",\[32\]=\"5\",\[64\]=\"6\",\[128\]=\"7\",\[256\]=\"8\",\[512\]=\"9\",\[1024\]=\"a\",\[2048\]=\"b\",\[4096\]=\"c\",\[8192\]=\"d\",\[16384\]=\"e\",\[32768\]=\"f\"}local function f(g,h,i,j,k,l)local m=k-i;local n=m>0 and 1 or-1;m=2*math.abs(m)local o=l-j;local p=o>0 and 1 or-1;o=2*math.abs(o)g\[(j-1)*h+i\]=true;if m>=o then local q=o-m/2;while i~=k do if q>=0 and q~=0 or n>0 then q=q-m;j=j+p end;q=q+o;i=i+n;g\[(j-1)*h+i\]=true end else local q=m-o/2;while j~=l do if q>=0 and q~=0 or p>0 then q=q-o;i=i+n end;q=q+m;j=j+p;g\[(j-1)*h+i\]=true end end end;local r={setBounds=function(s,i,j,k,l)if i>k then local t=i;i,k=k,t end;if j>l then local t=j;j,l=l,t end;if k<1 or i>s.width or l<1 or j>s.height then return end;if i<1 then i=1 end;if k>s.width then k=s.width end;if j<1 then j=1 end;if l>s.height then l=s.height end;s.x1,s.y1,s.x2,s.y2=i,j,k,l end,getBounds=function(s)return s.x1,s.y1,s.x2,s.y2 end,copy=function(s)local u=create(s.width,s.height)u.x1,u.y1,u.x2,u.y2,u.blink,u.curX,u.curY,u.overwrite=s.x1,s.y1,s.x2,s.y2,s.blink,s.curX,s.curY,s.overwrite;for v=1,s.width*s.height*3 do u.buffer\[v\]=s.buffer\[v\]end;return u end,save=function(s,w,x)x=x or\"srf\"local y=fs.open(w,\"w\")if x==\"nfp\"then local z=nil;for A=1,s.height do if A>1 then y.write(\"\\n\")end;for v=1,s.width do z=s.buffer\[((A-1)*s.width+v)*3-1\]if z then y.write(e\[z\])else y.write(\" \")end end end elseif x==\"nft\"then local B,C,char=nil;for A=1,s.height do if A>1 then y.write(\"\\n\")end;B,C=nil;for v=1,s.width do if B~=s.buffer\[((A-1)*s.width+v)*3-1\]then y.write(string.char(30))B=s.buffer\[((A-1)*s.width+v)*3-1\]if B then y.write(e\[B\])else y.write(\" \")end end;if C~=s.buffer\[((A-1)*s.width+v)*3\]then y.write(string.char(31))C=s.buffer\[((A-1)*s.width+v)*3\]if C then y.write(e\[C\])else y.write(\" \")end end;char=s.buffer\[((A-1)*s.width+v)*3-2\]if char then y.write(char)else y.write(\" \")end end end elseif x==\"srf\"then y.write(s:saveString())end;y.close()end,saveString=function(s)local D={\"_\"..string.format(\"%04x\",s.width)..string.format(\"%04x\",s.height)}for A=1,s.height do for v=1,s.width do if s.buffer\[((A-1)*s.width+v)*3-2\]then D\[#D+1\]=string.format(\"%02x\",s.buffer\[((A-1)*s.width+v)*3-2\]:byte(1))else D\[#D+1\]=\"__\"end;if s.buffer\[((A-1)*s.width+v)*3-1\]then D\[#D+1\]=e\[s.buffer\[((A-1)*s.width+v)*3-1\]\]else D\[#D+1\]=\"_\"end;if s.buffer\[((A-1)*s.width+v)*3\]then D\[#D+1\]=e\[s.buffer\[((A-1)*s.width+v)*3\]\]else D\[#D+1\]=\"_\"end end end;return d(D)end,getTerm=function(s)local term,B,C={},colors.black,colors.white;function term.write(D)s:drawText(s.curX,s.curY,tostring(D),B,C)s.curX=s.curX+#tostring(D)end;function term.blit(D,E,F)for v=1,#D do if s.curX>=s.x1 and s.curY>=s.y1 and s.curX<=s.x2 and s.curY<=s.y2 then s.buffer\[((s.curY-1)*s.width+s.curX)*3-2\]=D:sub(v,v)s.buffer\[((s.curY-1)*s.width+s.curX)*3-1\]=2^tonumber(F:sub(v,v),16)s.buffer\[((s.curY-1)*s.width+s.curX)*3\]=2^tonumber(E:sub(v,v),16)end;s.curX=s.curX+1 end end;function term.clear()s:clear(\" \",B,C)end;function term.clearLine(G)s:drawHLine(s.x1,s.x2,s.curY,\" \",B,C)end;function term.getCursorPos()return s.curX,s.curY end;function term.setCursorPos(H,I)s.curX,s.curY=a(H),a(I)end;function term.setCursorBlink(J)s.blink=J end;function term.isColor()return true end;term.isColour=term.isColor;function term.setTextColor(z)C=z end;term.setTextColour=term.setTextColor;function term.setBackgroundColor(z)B=z end;term.setBackgroundColour=term.setBackgroundColor;function term.getSize()return s.width,s.height end;function term.scroll(G)s:shift(0,-G)end;function term.getTextColor()return C end;term.getTextColour=term.getTextColor;function term.getBackgroundColor()return B end;term.getBackgroundColour=term.getBackgroundColor;return term end,render=function(s,K,H,I,L,M,N,O)K,H,I,L,M,N,O=K or term,H or 1,I or 1,L or 1,M or 1,N or s.width,O or s.height;if L>N then local t=L;L,N=N,t end;if M>O then local t=M;M,O=O,t end;if N<1 or L>s.width or O<1 or M>s.height then return end;if L<1 then L=1 end;if N>s.width then N=s.width end;if M<1 then M=1 end;if O>s.height then O=s.height end;local P={}if K.blit then local D,F,E={},{},{}for A=M,O do for v=L,N do D\[v-L+1\]=s.buffer\[((A-1)*s.width+v)*3-2\]or\" \"F\[v-L+1\]=e\[s.buffer\[((A-1)*s.width+v)*3-1\]or 32768\]E\[v-L+1\]=e\[s.buffer\[((A-1)*s.width+v)*3\]or 1\]end;P\[#P+1\]=I+A-M;P\[#P+1\]=d(D)P\[#P+1\]=d(E)P\[#P+1\]=d(F)end;for v=1,#P,4 do K.setCursorPos(H,P\[v\])K.blit(P\[v+1\],P\[v+2\],P\[v+3\])end else local D,B,C,Q,R=\"\",0,0;for A=M,O do P\[#P+1\]=1;P\[#P+1\]=I+A-M;for v=L,N do Q,R=s.buffer\[((A-1)*s.width+v)*3-1\]or 32768,s.buffer\[((A-1)*s.width+v)*3\]or 1;if Q~=B then B=Q;if D~=\"\"then P\[#P+1\]=4;P\[#P+1\]=D;D=\"\"end;P\[#P+1\]=2;P\[#P+1\]=B end;if R~=C then C=R;if D~=\"\"then P\[#P+1\]=4;P\[#P+1\]=D;D=\"\"end;P\[#P+1\]=3;P\[#P+1\]=C end;D=D..s.buffer\[((A-1)*s.width+v)*3-2\]or\" \"end;P\[#P+1\]=4;P\[#P+1\]=D;D=\"\"end;local S,T=nil;for v=1,#P,2 do S,T=P\[v\],P\[v+1\]if S==1 then K.setCursorPos(H,T)elseif S==2 then K.setBackgroundColor(T)elseif S==3 then K.setTextColor(T)else K.write(T)end end end;if s.blink and s.curX>=1 and s.curY>=1 and s.curX<=s.width and s.curY<=s.height then K.setCursorPos(H+s.curX-L,I+s.curY-M)K.setCursorBlink(true)elseif s.blink==false then K.setCursorBlink(false)s.blink=nil end;return#P/2 end,clear=function(s,char,B,C)local U=s.overwrite;s.overwrite=true;s:fillRect(s.x1,s.y1,s.x2,s.y2,char,B,C)s.overwrite=U end,drawPixel=function(s,H,I,char,B,C)if H<s.x1 or I<s.y1 or H>s.x2 or I>s.y2 then return end;if char or s.overwrite then s.buffer\[((I-1)*s.width+H)*3-2\]=char end;if B or s.overwrite then s.buffer\[((I-1)*s.width+H)*3-1\]=B end;if C or s.overwrite then s.buffer\[((I-1)*s.width+H)*3\]=C end end,getPixel=function(s,H,I)if H<1 or I<1 or H>s.width or I>s.height then return end;return s.buffer\[((I-1)*s.width+H)*3-2\],s.buffer\[((I-1)*s.width+H)*3-1\],s.buffer\[((I-1)*s.width+H)*3\]end,drawText=function(s,H,I,E,B,C)local V=H;for v=1,#E do if E:sub(v,v)~=\"\\n\"then if H>=s.x1 and I>=s.y1 and H<=s.x2 and I<=s.y2 then s.buffer\[((I-1)*s.width+H)*3-2\]=E:sub(v,v)if B or s.overwrite then s.buffer\[((I-1)*s.width+H)*3-1\]=B end;if C or s.overwrite then s.buffer\[((I-1)*s.width+H)*3\]=C end end else H=V-1;I=I+1 end;H=H+1 end end,drawLine=function(s,i,j,k,l,char,B,C)local m=k-i;local n=m>0 and 1 or-1;m=2*math.abs(m)local o=l-j;local p=o>0 and 1 or-1;o=2*math.abs(o)s:drawPixel(i,j,char,B,C)if m>=o then local q=o-m/2;while i~=k do if q>=0 and q~=0 or n>0 then q=q-m;j=j+p end;q=q+o;i=i+n;s:drawPixel(i,j,char,B,C)end else local q=m-o/2;while j~=l do if q>=0 and q~=0 or p>0 then q=q-o;i=i+n end;q=q+m;j=j+p;s:drawPixel(i,j,char,B,C)end end end,drawLines=function(s,W,X,char,B,C)X=X or 1;if X==1 then for v=1,#W,4 do s:drawLine(W\[v\],W\[v+1\],W\[v+2\],W\[v+3\],char,B,C)end elseif X==2 then local Y,Z=W\[1\],W\[2\]for v=3,#W,2 do local _,a0=W\[v\],W\[v+1\]s:drawLine(Y,Z,_,a0,char,B,C)Y=_;Z=a0 end elseif X==3 then local a1,a2=W\[1\],W\[2\]for v=3,#W,2 do s:drawLine(a1,a2,W\[v\],W\[v+1\],char,B,C)end end end,drawHLine=function(s,i,k,I,char,B,C)if i>k then local t=i;i,k=k,t end;if I<s.y1 or I>s.y2 or k<s.x1 or i>s.x2 then return end;if i<s.x1 then i=s.x1 end;if k>s.x2 then k=s.x2 end;if char or s.overwrite then for H=i,k do s.buffer\[((I-1)*s.width+H)*3-2\]=char end end;if B or s.overwrite then for H=i,k do s.buffer\[((I-1)*s.width+H)*3-1\]=B end end;if C or s.overwrite then for H=i,k do s.buffer\[((I-1)*s.width+H)*3\]=C end end end,drawVLine=function(s,j,l,H,char,B,C)if j>l then local t=j;j,l=l,t end;if H<s.x1 or H>s.x2 or l<s.y1 or j>s.y2 then return end;if j<s.y1 then j=s.y1 end;if l>s.y2 then l=s.y2 end;if char or s.overwrite then for I=j,l do s.buffer\[((I-1)*s.width+H)*3-2\]=char end end;if B or s.overwrite then for I=j,l do s.buffer\[((I-1)*s.width+H)*3-1\]=B end end;if C or s.overwrite then for I=j,l do s.buffer\[((I-1)*s.width+H)*3\]=C end end end,drawRect=function(s,i,j,k,l,char,B,C)s:drawHLine(i,k,j,char,B,C)s:drawHLine(i,k,l,char,B,C)s:drawVLine(j,l,i,char,B,C)s:drawVLine(j,l,k,char,B,C)end,drawRoundRect=function(s,i,j,k,l,char,B,C)s:drawHLine(i+1,k-1,j,char,B,C)s:drawHLine(i+1,k-1,l,char,B,C)s:drawVLine(j+1,l-1,i,char,B,C)s:drawVLine(j+1,l-1,k,char,B,C)end,drawRoundedRect=function(s,i,j,k,l,a3,char,B,C)s:drawHLine(i+a3,k-a3,j,char,B,C)s:drawHLine(i+a3,k-a3,l,char,B,C)s:drawVLine(j+a3,l-a3,i,char,B,C)s:drawVLine(j+a3,l-a3,k,char,B,C)s:drawArc(i,j,i+a3*2+2,j+a3*2+2,-math.pi,-math.pi/2,char,B,C)s:drawArc(k,j,k-a3*2-2,j+a3*2+2,0,-math.pi/2,char,B,C)s:drawArc(i,l,i+a3*2+2,l-a3*2-2,math.pi,math.pi/2,char,B,C)s:drawArc(k,l,k-a3*2-2,l-a3*2-2,0,math.pi/2,char,B,C)end,fillRect=function(s,i,j,k,l,char,B,C)if i>k then local t=i;i,k=k,t end;if j>l then local t=j;j,l=l,t end;if k<s.x1 or i>s.x2 or l<s.y1 or j>s.y2 then return end;if i<s.x1 then i=s.x1 end;if k>s.x2 then k=s.x2 end;if j<s.y1 then j=s.y1 end;if l>s.y2 then l=s.y2 end;if char or s.overwrite then for I=j,l do for H=i,k do s.buffer\[((I-1)*s.width+H)*3-2\]=char end end end;if B or s.overwrite then for I=j,l do for H=i,k do s.buffer\[((I-1)*s.width+H)*3-1\]=B end end end;if C or s.overwrite then for I=j,l do for H=i,k do s.buffer\[((I-1)*s.width+H)*3\]=C end end end end,fillRoundRect=function(s,i,j,k,l,char,B,C)s:drawHLine(i+1,k-1,j,char,B,C)s:drawHLine(i+1,k-1,l,char,B,C)s:drawVLine(j+1,l-1,i,char,B,C)s:drawVLine(j+1,l-1,k,char,B,C)s:fillRect(i+1,j+1,k-1,l-1,char,B,C)end,fillRoundedRect=function(s,i,j,k,l,a3,char,B,C)s:fillRect(i+a3,j,k-a3,l,char,B,C)s:fillRect(i,j+a3,i+a3,l-a3,char,B,C)s:fillRect(k-a3,j+a3,k,l-a3,char,B,C)s:fillPie(i,j,i+a3*2+2,j+a3*2+2,-math.pi,-math.pi/2,char,B,C)s:fillPie(k,j,k-a3*2-2,j+a3*2+2,0,-math.pi/2,char,B,C)s:fillPie(i,l,i+a3*2+2,l-a3*2-2,math.pi,math.pi/2,char,B,C)s:fillPie(k,l,k-a3*2-2,l-a3*2-2,0,math.pi/2,char,B,C)end,drawTriangle=function(s,i,j,k,l,a4,a5,char,B,C)s:drawLine(i,j,k,l,char,B,C)s:drawLine(k,l,a4,a5,char,B,C)s:drawLine(a4,a5,i,j,char,B,C)end,fillTriangle=function(s,i,j,k,l,a4,a5,char,B,C)local a6,a7,a8,a9=i,j,i,j;if k<a6 then a6=k end;if a4<a6 then a6=a4 end;if l<a7 then a7=l end;if a5<a7 then a7=a5 end;if k>a8 then a8=k end;if a4>a8 then a8=a4 end;if l>a9 then a9=l end;if a5>a9 then a9=a5 end;local h,aa,g,min,max=a8-a6+1,a9-a7+1,{},0,0;f(g,h,i-a6+1,j-a7+1,k-a6+1,l-a7+1)f(g,h,k-a6+1,l-a7+1,a4-a6+1,a5-a7+1)f(g,h,a4-a6+1,a5-a7+1,i-a6+1,j-a7+1)for A=1,aa do min,max=nil;for v=1,h do if g\[(A-1)*h+v\]then if not min then min=v end;max=v end end;s:drawHLine(min+a6-1,max+a6-1,A+a7-1,char,B,C)end end,drawTriangles=function(s,W,X,char,B,C)X=X or 1;if X==1 then for v=1,#W,6 do s:drawTriangle(W\[v\],W\[v+1\],W\[v+2\],W\[v+3\],W\[v+4\],W\[v+5\],char,B,C)end elseif X==2 then local Y,Z,ab,ac,_,a0=W\[1\],W\[2\],W\[3\],W\[4\]for v=5,#W,2 do _,a0=W\[v\],W\[v+1\]s:drawTriangle(Y,Z,ab,ac,_,a0,char,B,C)Y,Z,ab,ac=ab,ac,_,a0 end elseif X==3 then local a1,a2,Y,Z,_,a0=W\[1\],W\[2\],W\[3\],W\[4\]for v=5,#W,2 do _,a0=W\[v\],W\[v+1\]s:drawTriangle(a1,a2,Y,Z,_,a0,char,B,C)Y,Z=_,a0 end end end,fillTriangles=function(s,W,X,char,B,C)X=X or 1;if X==1 then for v=1,#W,6 do s:fillTriangle(W\[v\],W\[v+1\],W\[v+2\],W\[v+3\],W\[v+4\],W\[v+5\],char,B,C)end elseif X==2 then local Y,Z,ab,ac,_,a0=W\[1\],W\[2\],W\[3\],W\[4\]for v=5,#W,2 do _,a0=W\[v\],W\[v+1\]s:fillTriangle(Y,Z,ab,ac,_,a0,char,B,C)Y,Z,ab,ac=ab,ac,_,a0 end elseif X==3 then local a1,a2,Y,Z,_,a0=W\[1\],W\[2\],W\[3\],W\[4\]for v=5,#W,2 do _,a0=W\[v\],W\[v+1\]s:fillTriangle(a1,a2,Y,Z,_,a0,char,B,C)Y,Z=_,a0 end end end,drawEllipse=function(s,i,j,k,l,char,B,C)if i>k then local t=i;i,k=k,t end;if j>l then local t=j;j,l=l,t end;local ad,ae,af,h,aa,ag,ah=math.pi*2/16,(i+k)/2,(j+l)/2,(k-i)/2,(l-j)/2,1,1;for v=1,17 do local H,I=a(ae+b(ad*v)*h+0.5),a(af+c(ad*v)*aa+0.5)if v>1 then s:drawLine(ag,ah,H,I,char,B,C)end;ag,ah=H,I end end,fillEllipse=function(s,i,j,k,l,char,B,C)if i>k then local t=i;i,k=k,t end;if j>l then local t=j;j,l=l,t end;local ai,ad,ae,af,h,aa,ag,ah,aj,ak,g=16,math.pi*2/16,(i+k)/2,(j+l)/2,(k-i)/2,(l-j)/2,1,1,k-i+1,l-j+1,{}for v=1,ai+1 do local H,I=a(ae+b(ad*v)*h+0.5),a(af+c(ad*v)*aa+0.5)if v>1 then f(g,aj,ag-i+1,ah-j+1,H-i+1,I-j+1)end;ag,ah=H,I end;for A=1,ak do min,max=nil;for v=1,aj do if g\[(A-1)*aj+v\]then if not min then min=v end;max=v end end;s:drawHLine(min+i-1,max+i-1,A+j-1,char,B,C)end end,drawArc=function(s,i,j,k,l,al,am,char,B,C)if i>k then local t=i;i,k=k,t end;if j>l then local t=j;j,l=l,t end;if al>am then local t=al;al,am=am,t end;local ad,ae,af,h,aa,ag,ah=(am-al)/16,(i+k)/2,(j+l)/2,(k-i)/2,(l-j)/2,1,1;for v=1,17 do local H,I=a(ae+b(ad*v-1+al)*h+0.5),a(af-c(ad*v-1+al)*aa+0.5)if v>1 then s:drawLine(ag,ah,H,I,char,B,C)end;ag,ah=H,I end end,drawPie=function(s,i,j,k,l,al,am,char,B,C)if i>k then local t=i;i,k=k,t end;if j>l then local t=j;j,l=l,t end;if al>am then local t=al;al,am=am,t end;local ad,ae,af,h,aa,ag,ah=(am-al)/16,(i+k)/2,(j+l)/2,(k-i)/2,(l-j)/2,1,1;for v=1,17 do local H,I=a(ae+b(ad*v-1+al)*h+0.5),a(af-c(ad*v-1+al)*aa+0.5)if v>1 then s:drawLine(ag,ah,H,I,char,B,C)end;ag,ah=H,I end;s:drawLine(a(ae+0.5),a(af+0.5),a(ae+b(al)*h+0.5),a(af-c(al)*aa+0.5),char,B,C)s:drawLine(a(ae+0.5),a(af+0.5),a(ae+b(am)*h+0.5),a(af-c(am)*aa+0.5),char,B,C)end,fillPie=function(s,i,j,k,l,al,am,char,B,C)if i>k then local t=i;i,k=k,t end;if j>l then local t=j;j,l=l,t end;if al>am then local t=al;al,am=am,t end;local ad,ae,af,h,aa,ag,ah,aj,ak,g=(am-al)/16,(i+k)/2,(j+l)/2,(k-i)/2,(l-j)/2,1,1,k-i+1,l-j+1,{}for v=1,17 do local H,I=a(ae+b(ad*v-1+al)*h+0.5),a(af-c(ad*v-1+al)*aa+0.5)if v>1 then f(g,aj,ag-i+1,ah-j+1,H-i+1,I-j+1)end;ag,ah=H,I end;f(g,aj,a(ae+0.5)-i+1,a(af+0.5)-j+1,a(ae+b(al)*h+0.5)-i+1,a(af-c(al)*aa+0.5)-j+1)f(g,aj,a(ae+0.5)-i+1,a(af+0.5)-j+1,a(ae+b(am)*h+0.5)-i+1,a(af-c(am)*aa+0.5)-j+1)for A=1,ak do min,max=nil;for v=1,aj do if g\[(A-1)*aj+v\]then if not min then min=v end;max=v end end;if min then s:drawHLine(min+i-1,max+i-1,A+j-1,char,B,C)end end end,floodFill=function(s,H,I,char,B,C)if H<s.x1 or I<s.y1 or H>s.x2 or I>s.y2 then return end;local an,ao,ap,aq={H,I},s.buffer\[((I-1)*s.width+H)*3-2\],s.buffer\[((I-1)*s.width+H)*3-1\],s.buffer\[((I-1)*s.width+H)*3\]if ao==char and ap==B and aq==C then return end;while#an>0 do local ar,as=an\[#an-1\],an\[#an\]an\[#an\]=nil;an\[#an\]=nil;if ar>=s.x1 and as>=s.y1 and ar<=s.x2 and as<=s.y2 then local at,au,av=s.buffer\[((as-1)*s.width+ar)*3-2\],s.buffer\[((as-1)*s.width+ar)*3-1\],s.buffer\[((as-1)*s.width+ar)*3\]if ao==at and ap==au and aq==av then if char or s.overwrite then s.buffer\[((as-1)*s.width+ar)*3-2\]=char end;if B or s.overwrite then s.buffer\[((as-1)*s.width+ar)*3-1\]=B end;if C or s.overwrite then s.buffer\[((as-1)*s.width+ar)*3\]=C end;an\[#an+1\]=ar-1;an\[#an+1\]=as;an\[#an+1\]=ar+1;an\[#an+1\]=as;an\[#an+1\]=ar;an\[#an+1\]=as-1;an\[#an+1\]=ar;an\[#an+1\]=as+1 end end end end,drawSurface=function(s,H,I,u)for A=1,u.height do for v=1,u.width do s:drawPixel(v+H-1,A+I-1,u.buffer\[((A-1)*u.width+v)*3-2\],u.buffer\[((A-1)*u.width+v)*3-1\],u.buffer\[((A-1)*u.width+v)*3\])end end end,drawSurfacePart=function(s,H,I,L,M,N,O,u)if L>N then local t=L;L,N=N,t end;if M>O then local t=M;M,O=O,t end;if N<1 or L>u.width or O<1 or M>u.height then return end;if L<1 then L=1 end;if N>u.width then N=u.width end;if M<1 then M=1 end;if O>u.height then O=u.height end;for A=M,O do for v=L,N do s:drawPixel(H+v-L,I+A-M,u.buffer\[((A-1)*u.width+v)*3-2\],u.buffer\[((A-1)*u.width+v)*3-1\],u.buffer\[((A-1)*u.width+v)*3\])end end end,drawSurfaceScaled=function(s,i,j,k,l,u)local H,h,aw,I,aa,ax=0,0,false,0,0,false;if i<=k then H=i;h=k-i+1 else H=k;h=i-k+1;aw=true end;if j<=l then I=j;aa=l-j+1 else I=l;aa=j-l+1;ax=true end;local ay,az,V,aA=h/u.width,aa/u.height;for A=1,aa do for v=1,h do if aw then V=a((h-v+0.5)/ay)+1 else V=a((v-0.5)/ay)+1 end;if ax then aA=a((aa-A+0.5)/az)+1 else aA=a((A-0.5)/az)+1 end;s:drawPixel(H+v-1,I+A-1,u.buffer\[((aA-1)*u.width+V)*3-2\],u.buffer\[((aA-1)*u.width+V)*3-1\],u.buffer\[((aA-1)*u.width+V)*3\])end end end,drawSurfaceRotated=function(s,H,I,aB,aC,aD,u)local cos,sin,aE=b(aD),c(aD),a(math.sqrt(u.width*u.width+u.height*u.height))H,I=H-a(cos*aB-1+sin*aC-1+0.5),I-a(cos*aC-1-sin*aB-1+0.5)for A=-aE,aE do for v=-aE,aE do local aF,aG=a(v*cos-A*sin),a(v*sin+A*cos)if aF>=0 and aF<u.width and aG>=0 and aG<u.height then s:drawPixel(H+v,I+A,u.buffer\[(aG*u.width+aF)*3+1\],u.buffer\[(aG*u.width+aF)*3+2\],u.buffer\[(aG*u.width+aF)*3+3\])end end end end,shader=function(s,y,i,j,k,l)i,j,k,l=i or s.x1,j or s.y1,k or s.x2,l or s.y2;if i>k then local t=i;i,k=k,t end;if j>l then local t=j;j,l=l,t end;if k<s.x1 or i>s.x2 or l<s.y1 or j>s.y2 then return end;if i<s.x1 then i=s.x1 end;if k>s.x2 then k=s.x2 end;if j<s.y1 then j=s.y1 end;if l>s.y2 then l=s.y2 end;local h,g=k-i+1,{}for A=j,l do for v=i,k do g\[((A-j)*h+v-i)*3+1\],g\[((A-j)*h+v-i)*3+2\],g\[((A-j)*h+v-i)*3+3\]=y(s.buffer\[((A-1)*s.width+v)*3-2\],s.buffer\[((A-1)*s.width+v)*3-1\],s.buffer\[((A-1)*s.width+v)*3\],v,A)end end;for A=j,l do for v=i,k do s.buffer\[((A-1)*s.width+v)*3-2\],s.buffer\[((A-1)*s.width+v)*3-1\],s.buffer\[((A-1)*s.width+v)*3\]=g\[((A-j)*h+v-i)*3+1\],g\[((A-j)*h+v-i)*3+2\],g\[((A-j)*h+v-i)*3+3\]end end end,shift=function(s,H,I,i,j,k,l)i,j,k,l=i or s.x1,j or s.y1,k or s.x2,l or s.y2;if i>k then local t=i;i,k=k,t end;if j>l then local t=j;j,l=l,t end;if k<s.x1 or i>s.x2 or l<s.y1 or j>s.y2 then return end;if i<s.x1 then i=s.x1 end;if k>s.x2 then k=s.x2 end;if j<s.y1 then j=s.y1 end;if l>s.y2 then l=s.y2 end;local h,g=k-i+1,{}for A=j,l do for v=i,k do if v-H>=1 and A-I>=1 and v-H<=s.width and A-I<=s.height then g\[((A-j)*h+v-i)*3+1\],g\[((A-j)*h+v-i)*3+2\],g\[((A-j)*h+v-i)*3+3\]=s.buffer\[((A-I-1)*s.width+v-H)*3-2\],s.buffer\[((A-I-1)*s.width+v-H)*3-1\],s.buffer\[((A-I-1)*s.width+v-H)*3\]end end end;for A=j,l do for v=i,k do s.buffer\[((A-1)*s.width+v)*3-2\],s.buffer\[((A-1)*s.width+v)*3-1\],s.buffer\[((A-1)*s.width+v)*3\]=g\[((A-j)*h+v-i)*3+1\],g\[((A-j)*h+v-i)*3+2\],g\[((A-j)*h+v-i)*3+3\]end end end}function create(h,aa,char,B,C)local s={}for aH,aI in pairs(r)do s\[aH\]=aI end;s.width,s.height,s.x1,s.y1,s.x2,s.y2,s.curX,s.curY,s.overwrite,s.buffer=h,aa,1,1,h,aa,1,1,false,{}if char then for v=1,h*aa do s.buffer\[v*3-2\]=char end end;if B then for v=1,h*aa do s.buffer\[v*3-1\]=B end end;if C then for v=1,h*aa do s.buffer\[v*3\]=C end end;return s end;function load(w)local aJ,y={},fs.open(w,\"r\")for aK in y.readLine do aJ\[#aJ+1\]=aK end;y.close()local aa=#aJ;if aJ\[1\]:byte(1)==30 then local h,v=0,1;while v<=#aJ\[1\]do local char=aJ\[1\]:byte(v)if char==30 or char==31 then v=v+1 else h=h+1 end;v=v+1 end;local s,B,C,v,V,char,z=create(h,aa)for A=1,aa do v=1;V=1;while v<=#aJ\[A\]do char=aJ\[A\]:byte(v)if char==30 then v=v+1;char=aJ\[A\]:byte(v)z=tonumber(aJ\[A\]:sub(v,v),16)if z then B=2^z else B=nil end elseif char==31 then v=v+1;char=aJ\[A\]:byte(v)z=tonumber(aJ\[A\]:sub(v,v),16)if z then C=2^z else C=nil end else s.buffer\[((A-1)*s.width+V)*3-2\]=aJ\[A\]:sub(v,v)s.buffer\[((A-1)*s.width+V)*3-1\]=B;s.buffer\[((A-1)*s.width+V)*3\]=C;V=V+1 end;v=v+1 end end;return s elseif aJ\[1\]:byte(1)==95 then return loadString(aJ\[1\])else local h=0;for v=1,#aJ do if#aJ\[v\]>h then h=#aJ\[v\]end end;local s,z=create(h,aa)for A=1,aa do for v=1,h do z=tonumber(aJ\[A\]:sub(v,v),16)if z then s.buffer\[((A-1)*s.width+v)*3-1\]=2^z end end end;return s end end;function loadString(D)local h,aa,G=tonumber(D:sub(2,5),16),tonumber(D:sub(6,9),16),10;local s=create(h,aa)for A=1,aa do for v=1,h do if D:byte(G)~=95 then s.buffer\[((A-1)*s.width+v)*3-2\]=string.char(tonumber(D:sub(G,G+1),16))end;if D:byte(G+2)~=95 then s.buffer\[((A-1)*s.width+v)*3-1\]=2^tonumber(D:sub(G+2,G+2),16)end;if D:byte(G+3)~=95 then s.buffer\[((A-1)*s.width+v)*3\]=2^tonumber(D:sub(G+3,G+3),16)end;G=G+4 end end;return s end")
- loadConfig()
- resize()
- while running[1] do
- local e, front = {os.pullEventRaw()}, getFront()
- if e[1] == "timer" and e[2] == osTimer then
- osTimer = os.startTimer(0)
- surf:clear(nil, config.skin.bc)
- surf:drawHLine(1, width, 1, nil, config.skin.taskbc)
- local x = 6 - offset
- for i=1,#processes do
- if i == front then
- surf:drawText(x, 1, processes[i].title, nil, config.skin.taskacttc)
- elseif processes[i].minimized then
- surf:drawText(x, 1, processes[i].title, nil, config.skin.taskmintc)
- else
- surf:drawText(x, 1, processes[i].title, nil, config.skin.tasknortc)
- end
- x = x + #processes[i].title + 2
- end
- surf:drawText(1, 1, "Grid", config.skin.gridbc, config.skin.gridtc)
- surf:drawPixel(5, 1, "<", config.skin.taskscrbc, config.skin.taskscrtc)
- surf:drawPixel(width, 1, ">", config.skin.taskscrbc, config.skin.taskscrtc)
- for i=#order,1,-1 do
- local process = processes[order[i]]
- if not process.minimized then
- surf:fillRect(process.x, process.y, process.x + process.width - 1, process.y + process.height - 1, " ", colors.black, colors.white)
- surf:drawHLine(process.x, process.x + process.width - 1, process.y, nil, config.skin.wintopbc, config.skin.wintitletc)
- surf:drawVLine(process.y + 1, process.y + process.height - 1, process.x + process.width - 1, nil, config.skin.winrightbc)
- surf:drawPixel(process.x + process.width - 2, process.y, "-", config.skin.winminbc, config.skin.winmintc)
- surf:drawPixel(process.x + process.width - 1, process.y, "X", config.skin.winclosebc, config.skin.winclosetc)
- surf:drawPixel(process.x + process.width - 1, process.y + process.height - 1, "/", config.skin.winresizebc, config.skin.winresizetc)
- surf:drawText(process.x + 1, process.y, #process.title > process.width - 4 and process.title:sub(1, process.width - 6 < 0 and 0 or process.width - 6)..".." or process.title)
- surf:drawSurface(process.x, process.y + 1, process.surface)
- end
- end
- surf:render(parentTerm)
- parentTerm.setCursorBlink(false)
- if front then
- if processes[front].surface.curX >= 1 and processes[front].surface.curX < processes[front].surface.width and processes[front].surface.curY >= 1 and processes[front].surface.curY < processes[front].surface.height then
- parentTerm.setCursorPos(processes[front].surface.curX + processes[front].x - 1, processes[front].surface.curY + processes[front].y)
- parentTerm.setCursorBlink(processes[front].surface.blink or false)
- end
- end
- elseif e[1] == "term_resize" then
- resize()
- elseif e[1] == "char" or e[1] == "key" or e[1] == "key_up" or e[1] == "paste" then
- if front then
- resumeProcess(front, unpack(e))
- end
- elseif e[1] == "terminate" then
- if front then
- resumeProcess(front, "terminate")
- else
- running[1] = false
- end
- elseif e[1] == "mouse_click" then
- mode = 0
- if e[4] == 1 then
- if e[3] >= 1 and e[3] <= 4 then
- local found = false
- for i=1,#processes do
- if processes[i].path == dir.."startmenu.lua" then
- found = true
- multishell.setFocus(i)
- break
- end
- end
- if not found then
- local f = fs.open(dir.."startmenu.lua", "w")
- f.write(startmenu)
- f.close()
- multishell.setFocus(multishell.launch({shell = parentShell, multishell = multishell}, dir.."startmenu.lua", surface, config, running))
- fs.delete(dir.."startmenu.lua")
- end
- elseif e[3] == 5 then
- offset = offset - math.ceil((width - 6) / 3)
- checkOffset()
- elseif e[3] == width then
- offset = offset + math.ceil((width - 6) / 3)
- checkOffset()
- else
- local x = 6 - offset
- for i=1,#processes do
- if e[3] >= x and e[3] < x + #processes[i].title then
- if i == front then
- processes[i].minimized = true
- else
- multishell.setFocus(i)
- end
- end
- x = x + #processes[i].title + 2
- end
- end
- else
- for i=1,#order do
- if not processes[order[i]].minimized and e[3] >= processes[order[i]].x and e[4] >= processes[order[i]].y and e[3] < processes[order[i]].x + processes[order[i]].width and e[4] < processes[order[i]].y + processes[order[i]].height then
- if order[i] ~= front then
- multishell.setFocus(order[i])
- end
- front = getFront()
- break
- end
- end
- end
- if front then
- if e[3] >= processes[front].x and e[4] > processes[front].y and e[3] < processes[front].x + processes[front].width - 1 and e[4] < processes[front].y + processes[front].height then
- resumeProcess(front, e[1], e[2], e[3] - processes[front].x + 1, e[4] - processes[front].y)
- elseif e[3] == processes[front].x + processes[front].width - 1 and e[4] == processes[front].y then
- local process = processes[front]
- resumeProcess(front, "terminate")
- for i=1,#processes do
- if processes[i] == process then
- removeProcess(i)
- break
- end
- end
- elseif e[3] == processes[front].x + processes[front].width - 2 and e[4] == processes[front].y then
- processes[front].minimized = true
- elseif e[3] >= processes[front].x and e[3] < processes[front].x + processes[front].width - 2 and e[4] == processes[front].y then
- mode = 1
- lockX = e[3]
- lockY = e[4]
- elseif e[3] == processes[front].x + processes[front].width - 1 and e[4] == processes[front].y + processes[front].height - 1 then
- mode = 2
- lockX = e[3]
- lockY = e[4]
- end
- end
- elseif e[1] == "mouse_drag" then
- if front then
- if mode == 0 and e[3] >= processes[front].x and e[4] > processes[front].y and e[3] < processes[front].x + processes[front].width - 1 and e[4] < processes[front].y + processes[front].height then
- resumeProcess(front, e[1], e[2], e[3] - processes[front].x + 1, e[4] - processes[front].y)
- elseif mode == 1 then
- processes[front].x = processes[front].x + e[3] - lockX
- processes[front].y = processes[front].y + e[4] - lockY
- lockX = e[3]
- lockY = e[4]
- if processes[front].y < 2 then
- processes[front].y = 2
- lockY = lockY + 1
- end
- elseif mode == 2 then
- local width = e[3] - processes[front].x + 1
- local height = e[4] - processes[front].y + 1
- resizeProcess(front, width, height)
- end
- end
- elseif e[1] == "mouse_up" or e[2] == "mouse_scroll" then
- if front and mode == 0 then
- if e[3] >= processes[front].x and e[4] > processes[front].y and e[3] < processes[front].x + processes[front].width - 1 and e[4] < processes[front].y + processes[front].height then
- resumeProcess(front, e[1], e[2], e[3] - processes[front].x + 1, e[4] - processes[front].y)
- end
- end
- else
- distributeEvent(unpack(e))
- end
- end
- end
- local ok, err = pcall(run)
- saveConfig()
- if not ok then
- term.redirect(parentTerm)
- printError("GridOS has crashed!\nPlease notify CrazedProgrammer of the error.\nError message:\n"..err)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement