Advertisement
Guest User

fix by Big SHiny Toys

a guest
Sep 4th, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.15 KB | None | 0 0
  1. local running=1
  2. local size={term.getSize()}
  3. function KaoSOS()
  4.     local function count(input)
  5.         if type(input)~="table" then
  6.             print("incorrect input: "..tostring(input))
  7.             sleep(2)
  8.             return
  9.         end
  10.         local int=0
  11.         for a in pairs(input) do
  12.             int=int+1
  13.         end
  14.         return int
  15.     end
  16.    
  17.     local function getlongest(input)
  18.         if type(input)~="table" then
  19.             print("incorrect input")
  20.             return
  21.         end
  22.         local int=0
  23.         for k,v in pairs(input) do
  24.             for a,b in pairs(v) do
  25.                 if string.len(b)>int then
  26.                     int=#b
  27.                 end
  28.             end
  29.         end
  30.         return int
  31.     end
  32.    
  33.     function addparam(params)
  34.         print('Current parameters: ')
  35.         for k,v in pairs(params) do
  36.             print(v)
  37.         end
  38.         write('enter new parameter: ')
  39.         params[(#params or 0)+1]=read()
  40.         return 'added'
  41.     end
  42.    
  43.     function createnew()
  44.         term.clear()
  45.         term.setCursorPos(1,1)
  46.         write('enter new file name: ')
  47.         local new=read()
  48.         if new=='' then
  49.             print('Invalid entry')
  50.             sleep(2)
  51.         elseif fs.exists(new) then
  52.             print('File already exists')
  53.             sleep(2)
  54.         else
  55.             shell.run('edit',new)
  56.         end
  57.     end
  58.    
  59.     function check(input)
  60.         return menu2.generate({{{'run',{function() running=0 shell.run(input) running=1 term.clear() end}}, {'run with parameters',{runwith,input}}},{{'edit',{function() running=0 shell.run("edit",input) os.queueEvent("forceTimer") running=1 term.clear() end}}, {'delete',{fs.delete,input}}}},15,3,2,size[1]-4,size[2]-2)
  61.     end
  62.    
  63.     function runwith(input,params)
  64.         local params=params or {}
  65.         while menu2.generate({{{'done',{function() running=0 shell.run(input,unpack(params)) running=1 term.clear() end}},{'add param',{addparam,params}}}},15,3,2,size[1]-4,size[2]-2)=='added' do
  66.         end
  67.     end
  68.    
  69.     while true do
  70.         local tall={}
  71.         if shell.dir()=='' then
  72.             tall['tdirs']={{}}
  73.         else
  74.             tall['tdirs']={{{'[..\\]',{shell.setDir,shell.resolve("..\\")}}}}
  75.         end
  76.         tall['tfiles']={{{'#new',{createnew}}}}
  77.         for k,v in pairs(fs.list(shell.dir())) do
  78.             if fs.isDir(shell.resolve(v)) then
  79.                 var='tdirs'
  80.             else
  81.                 var='tfiles'
  82.             end
  83.             if #tall[var][#tall[var]]==3 then
  84.                 tall[var][#tall[var]+1]={}
  85.             end
  86.             tall[var][#tall[var]][#tall[var][#tall[var]]+1]={((var=='tdirs' and '['..v..']') or v),{((var=='tdirs' and shell.setDir) or check),shell.resolve(v)}}
  87.         end
  88.         for k,v in pairs(tall['tfiles']) do
  89.             tall['tdirs'][#tall['tdirs']+1]=v
  90.         end
  91.         local size={term.getSize()}
  92.         --drawborder()
  93.         running=1
  94.         menu2.generate(tall['tdirs'],15,3,2,size[1]-4,size[2]-2)
  95.     end
  96. end
  97.  
  98.  
  99.  
  100. local function drawborder()
  101.     local size={term.getSize()}
  102.     for i=1,size[2] do
  103.         term.setCursorPos(2,i)
  104.         if i==1 then
  105.             write('/'..string.rep('-',size[1]-4)..'\\')
  106.         elseif i==size[2] then
  107.             write('\\'..string.rep('-',size[1]-4)..'/')
  108.         else
  109.             write('|')
  110.             term.setCursorPos(size[1]-1,i)
  111.             write('|')
  112.         end
  113.     end
  114. end
  115.  
  116. function cyclingborder(processor,delim)
  117.     while true do
  118.         if processor<=size[1]-4 then
  119.             side='top'
  120.             break
  121.         else
  122.             processor=processor-(size[1]-2)
  123.             if processor<=size[2] then
  124.                 side='right'
  125.                 break
  126.             else
  127.                 processor=processor-size[2]
  128.                 if processor<=size[1]-4 then
  129.                     side='bottom'
  130.                     break
  131.                 else
  132.                     processor=processor-(size[1]-2)
  133.                     if processor<=size[2] then
  134.                         side='left'
  135.                         break
  136.                     else
  137.                         processor=processor-size[2]
  138.                     end
  139.                 end
  140.             end
  141.         end
  142.     end
  143.     term.setCursorPos((side=='top' and processor+2) or (side=='bottom' and size[1]-processor-1) or (side=='left' and 2) or (side=='right' and size[1]-1),(side=='top' and 1) or (side=='bottom' and size[2]) or (side=='left' and size[2]-processor) or (side=='right' and processor))
  144.     write(delim or '*')
  145. end
  146.  
  147. function localSleep( _nTime )
  148.     local timer = os.startTimer( _nTime )
  149.     repeat
  150.         local sEvent, param = os.pullEvent( "timer" )
  151.     until param == timer or sEvent == "forceTimer"
  152. end
  153.  
  154. co1=coroutine.create(function() local a=0 while true do a=a+1 drawborder() cyclingborder(a) cyclingborder(a+1) cyclingborder(a+2) cyclingborder(a+3) localSleep(0.1) end end)
  155. co2=coroutine.create(KaoSOS)
  156. term.clear()
  157. os.queueEvent('start')
  158. while true do
  159.     events={os.pullEvent()}
  160.     coroutine.resume(co2,unpack(events))
  161.     if running==1 then coroutine.resume(co1,unpack(events)) end
  162. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement