Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local osScrW,osScrH=51,19
- local tick=0.05
- local osWork=true
- local osRunProgram
- local logo=
- [[
- # ##
- #### #
- #### #
- #### #
- #### BurOs
- ]]
- local defTC,defBC=
- term.getTextColor(),
- term.getBackgroundColor()
- local osCurKey
- local osAll={system_frames={},frames={}}
- local osWindows={}
- local function table_find(t,a)
- for i,v in pairs(t) do
- if v==a then
- return i
- end
- end
- end
- local function osInstT(s,rW,rH)
- if s:find('\n') then
- local cNs=0
- local sN=''
- for c in s:gmatch('.') do
- if c~='\n' then
- cNs=(cNs>=rW) and 1 or cNs+1
- sN=sN..c
- else
- for i=1,rW-cNs do
- sN=sN..' '
- end
- cNs=0
- end
- end
- s=sN
- end
- for i=1,rW*rH-#s do
- s=s..' '
- end
- local t={}
- for y=0,rH do
- local st=y*rW+(y>0 and 1 or 0)
- local en=st+rW
- local l=s:sub(st,en)
- local cs={}
- for c in l:gmatch('.') do
- table.insert(cs,c)
- end
- table.insert(t,cs)
- end
- return t
- end
- local function osInitFrame(system)
- local sets={
- x=1,y=1,ox=0,oy=0,
- width=osScrW,height=osScrH,
- color=defBC,text='',visible=true,
- textColor=defTC,xvic=0,yvic=0
- }
- function sets:change(args)
- for i,v in pairs(args) do
- if sets[i] then
- sets[i]=v
- end
- end
- end
- local source=osAll[system and 'system_frames' or 'frames']
- table.insert(source,sets)
- function sets:destroy()
- local id=table_find(source,self)
- table.remove(source,id)
- end
- return sets
- end
- local function osDrawFrame(rX,rY,rW,rH,rC,t,tC)
- if t then
- tC=tC or defTC
- t=osInstT(t,rW,rH)
- else
- tC=rC
- end
- for y=0,rH-1 do
- term.setCursorPos(rX,y+rY)
- for x=0,rW-1 do
- term.setTextColor(tC)
- term.setBackgroundColor(rC)
- term.write(t and t[y+1][x+1]or ' ')
- end
- end
- end
- local function osDrawAll()
- for _,f in pairs(osAll)do
- for _,r in pairs(f)do
- if r.visible then
- osDrawFrame(
- r.x+r.ox,
- r.y+r.oy,
- r.width,
- r.height,
- r.color,
- r.text,
- r.textColor
- )
- end
- end
- end
- end
- local function osInitWindow()
- local other={}
- function other:change(args)
- for i,v in pairs(args) do
- self[i]=v
- end
- end
- local main=osInitFrame()
- local sets={
- grab=osInitFrame(),
- close=osInitFrame(),
- main=main,
- other=other
- }
- function sets:stabilize()
- local grab,close,main,other=self.grab,self.close,self.main,self.other
- grab.width=main.width-1
- grab.height=1
- close.x=grab.x+grab.width
- close.y=grab.y
- close.height=1
- close.width=1
- main.x=grab.x
- main.y=grab.y+1
- for _,i in pairs(other) do
- if type(i)=='table' then
- i.ox=main.x-1
- i.oy=main.y-1
- end
- end
- end
- sets:stabilize()
- function sets:change(args)
- for i,v in pairs(args) do
- if self[i] then
- self[i]:change(v)
- end
- end
- self:stabilize()
- end
- sets:change({main={color=colors.white,textColor=colors.black},grab={color=colors.blue,text='window',yvic=1},close={color=colors.red,text='X'}})
- function sets.grab:m1drag(x,y)
- local grab=sets.grab
- grab.x=x-math.floor(grab.width/2);grab.y=y-math.floor(grab.height/2)
- sets:stabilize()
- end
- function sets:addFrame(n,i)
- self.other[n]=i
- end
- function sets:getFrame(n)
- return self.other[n]
- end
- function sets:remFrame(n)
- self.other[n]=nil
- end
- function sets:desFrame(n)
- self.other[n]:destroy()
- self.other[n]=nil
- end
- function sets:destroy()
- local grab,close,main,other=self.grab,self.close,self.main,self.other
- grab:destroy()
- close:destroy()
- main:destroy()
- for _,i in pairs(other) do
- if type(i)=='table' then
- i:destroy()
- end
- end
- local id=table_find(osWindows,self)
- table.remove(osWindows,id)
- end
- function sets.close:m1click()
- sets:destroy()
- end
- table.insert(osWindows,sets)
- return sets
- end
- local function mouseFB(t,m,x,y)
- t='m'..tostring(m)..t
- local source=osAll[#osAll.system_frames>0 and 'system_frames' or 'frames']
- for i=#source,1,-1 do
- local b=source[i]
- local bx,by=b.x+b.ox,b.y+b.oy
- if x>=bx-b.xvic and y>=by-b.yvic and x<bx+b.width+b.xvic and y<by+b.height+b.yvic then
- if b[t] then
- b[t](b,x,y)
- end
- break
- end
- end
- end
- local function osMouseClick()
- while osWork do
- local e,m,x,y=os.pullEvent('mouse_click')
- mouseFB('click',m,x,y)
- end
- end
- local function osMouseDrag()
- while osWork do
- local e,m,x,y=os.pullEvent('mouse_drag')
- mouseFB('drag',m,x,y)
- end
- end
- local function osClear()
- term.clear()
- osDrawFrame(1,1,osScrW,osScrH,defBC)
- term.setCursorPos(1,1)
- end
- local function osInput()
- while true do
- local e,k=os.pullEvent('key')
- osCurKey=k
- end
- end
- local function osRender()
- while osWork do
- osDrawAll()
- os.sleep(tick)
- osClear()
- end
- end
- local function osIntro()
- local introScr=osInitFrame()
- local text='BUR OS v0.01 Starting...\n'..logo..'\nloading...\n'
- introScr:change({text,color=colors.blue})
- os.sleep(1)
- for i=1,10 do
- os.sleep(0.1)
- local loading=''
- for a=1,i do
- loading=loading..'#'
- end
- introScr.text=text..tostring(i*10)..'%:'..loading
- end
- introScr:destroy()
- end
- local function osOutro(message)
- local outroScr=osInitFrame()
- outroScr:change({text=message,color=colors.red})
- os.sleep(1)
- outroScr:destroy()
- end
- local function osAlert(message,w,h)
- local alertWin=osInitWindow()
- local ok=osInitFrame(true)
- ok:change({text='OK',width=2,height=1,x=math.floor(w/2),y=h-1})
- function ok:m1click()
- alertWin:destroy()
- end
- alertWin:addFrame('ok',ok)
- alertWin:change({main={width=w,height=h,text=message},grab={x=math.floor((osScrW-w)/2),y=math.floor((osScrH-h)/2),color=colors.red}})
- end
- local function osChoiceList(step,x,y,args,event)
- local size=-1
- for _,v in pairs(args) do
- size=math.max(size,#v)
- end
- local frames={}
- for i,t in pairs(args) do
- local b=osInitFrame(true)
- b:change({x=x,y=y+(i-1)*step,width=size,height=1,color=colors.white,textColor=colors.black,text=t})
- function b:m1click()
- for _,f in pairs(frames) do
- f:destroy()
- end
- event(args[i])
- end
- table.insert(frames,b)
- end
- end
- local function startMenu(x,y)
- y=y-1
- local pathHis={}
- local path=''
- local function showFiles()
- osChoiceList(-1,x,y,{'[cancel]','[shutdown]','[reboot]','<--',table.unpack(fs.list(path))},
- function(res)
- if res:sub(-4,-1)=='.lua' then
- osWork=false
- osRunProgram=path:sub(2)..'\\'..res
- elseif res=='[shutdown]' or res=='[reboot]' then
- osOutro(res);os[res:sub(2,-2)]()
- elseif res=='[cancel]' then
- return
- elseif res=='<--' and #pathHis>0 then
- path=table.remove(pathHis)
- elseif res~='<--' then
- table.insert(pathHis,path)
- path=path..'\\'..res
- end
- showFiles()
- end)
- end
- showFiles()
- end
- local function osMain()
- osIntro()
- local osBackground=osInitFrame()
- osBackground:change({color=colors.lightBlue })
- local osStart=osInitFrame()
- osStart:change({width=5,height=1,color=colors.red,text='start',y=osScrH})
- function osStart:m1click(x,y)
- startMenu(1,y)
- end
- local b=osInitFrame()
- b:change({text='PRESS ME :)',color=colors.red,width=11,height=1})
- function b:m1click()
- osAlert('Uberi ruki ot pc Vovi >:(',24,4)
- end
- local w=osInitWindow()
- w:change({main={width=9,height=6,text='Vova krutoi'},grab={x=5,y=5}})
- end
- parallel.waitForAll(osMain,osRender,osMouseClick,osMouseDrag)
- term.setBackgroundColor(defBC);term.setTextColor(defTC)
- if osRunProgram then
- shell.run(osRunProgram)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement