Guest User

startup

a guest
Sep 27th, 2015
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.30 KB | None | 0 0
  1. -- Codename Power
  2. -- Innovation starts here.
  3. -- All code in one file
  4. -- Hybrid OS
  5.  
  6. --[ INIT ]--
  7.  
  8. function center(y,str)
  9.   local w,h = term.getSize()
  10.   local x = term.getCursorPos()
  11.   x = math.floor(math.max((w / 2) - (#str / 2)),0)
  12.   term.setCursorPos(x,y)
  13.   print(str)
  14. end
  15.  
  16. function centerSP(y,str)
  17.   local w,h = term.getSize()
  18.   local x = term.getCursorPos()
  19.   x = math.floor(math.max((w / 2) - (#str / 2)),0)
  20.   term.setCursorPos(x,y)
  21.   textutils.slowPrint(str)
  22. end
  23.  
  24. function centerW(y,str)
  25.   local w,h = term.getSize()
  26.   local x = term.getCursorPos()
  27.   x = math.floor(math.max((w / 2) - (#str / 2)),0)
  28.   term.setCursorPos(x,y)
  29.   term.write(str)
  30. end
  31.  
  32. function clearScr()
  33.   term.clear()
  34.   term.setCursorPos(1,1)
  35. end
  36.  
  37. function bg(c)
  38.   term.setBackgroundColor(c)
  39.   clearScr()
  40. end
  41.  
  42. function fadeIn()
  43.   bg(colors.black)
  44.   sleep(0.1)
  45.   bg(colors.gray)
  46.   sleep(0.1)
  47.   bg(colors.lightGray)
  48.   sleep(0.1)
  49.   bg(colors.white)
  50. end
  51.  
  52. a = [[
  53. 49999
  54. 99999
  55. 99999
  56. 99999
  57. ddddd
  58. ]]
  59. f = fs.open("/.img","w")
  60. f.writeLine(a)
  61. f.close()
  62. f = nil
  63. img = paintutils.loadImage("/.img")
  64. f = fs.open("/.version","r")
  65. ver = f.readAll()
  66. f.close()
  67. f = nil
  68. function wip()
  69.   bg(colors.red)
  70.   term.setTextColor(colors.white)
  71.   centerSP(10,"Work in progress!")
  72.   centerSP(12,"Either not working, buggy or")
  73.   centerSP(13,"not done yet!")
  74.   center(15,"You can help contribute!")
  75.   center(16,"Go to github.com/MCFunRide/Codename-Hybrid")
  76.   center(17,"If you wish to fix bits of code!")
  77.   sleep(3)
  78.   desktop()
  79. end
  80. function bios()
  81.   print(":)")
  82. end
  83. function shellProg()
  84.   term.clear()
  85.   term.setCursorPos(1,1)
  86.   function os.version()
  87.     return "Codename Hybrid Shell 1.0"
  88.   end
  89.   shell.run("multishell")
  90. end
  91. function fileMan()
  92.   m = 0
  93.   local w,h = term.getSize()
  94.   curDir = "/"
  95.   function drawMenu(filename)
  96.     m = 1
  97.     term.setCursorPos(25,3)
  98.     term.setBackgroundColor(colors.orange)
  99.     print(" "..filename.." ")
  100.     term.setCursorPos(25,4)
  101.     print(" Delete    ")
  102.     term.setCursorPos(25,5)
  103.     print(" Rename    ")
  104.     term.setCursorPos(25,6)
  105.     print(" Edit      ")
  106.   end
  107.    
  108.   function drawDir()
  109.     l = fs.list(curDir)
  110.     bg(colors.white)
  111.     paintutils.drawLine(1,1,w,1,colors.gray)
  112.     term.setCursorPos(1,1)
  113.     term.setTextColor(colors.white)
  114.     print("File Manager")
  115.     term.setBackgroundColor(colors.white)
  116.     if m == 1 then
  117.       drawMenu(l[y2])
  118.     end
  119.     for i,v in pairs(l) do
  120.       if fs.isDir(v) then
  121.         term.setTextColor(colors.green)
  122.         print(v)
  123.         term.setTextColor(colors.black)
  124.       elseif v == ".img" then
  125.       elseif v == ".version" then
  126.       else
  127.         term.setTextColor(colors.black)
  128.         print(v)
  129.       end
  130.     end
  131.   end
  132.   drawDir()
  133.   m = 0
  134.   function code()
  135.     while true do
  136.       e2,b2,x2,y2 = os.pullEvent("mouse_click")
  137.       if l[y2] then
  138.         term.setCursorPos(1,10)
  139.         print("Event grabbed. File exists in table")
  140.         if fs.exists(l[y2]) then
  141.           print("File exists")
  142.             print("Pos works")
  143.             if fs.isDir(l[y2]) then
  144.               print("Dir")
  145.               curDir = "/"..l[y2]
  146.               drawDir()
  147.             else
  148.               print("File")
  149.               drawMenu(l[y2])
  150.             end
  151.           end
  152.        
  153.       elseif x == 51 and y == 1 then
  154.         desktop()
  155.       elseif x >= 25 and x <= 37 and y == 4 and m == 1 then
  156.         if curDir == "/" then
  157.           fs.delete(l[y2])
  158.         else
  159.           fs.delete(curDir.."/"..l[y2])
  160.         end
  161.       elseif x >= 25 and x <= 37 and y == 5 and m == 1 then
  162.         term.setCursorPos(25,7)
  163.         write("New Name: ")
  164.         new = read()
  165.         if curDir == "/" then
  166.           fs.rename(l[y2],new)
  167.         else
  168.           fs.rename(curDir.."/"..l[y2])
  169.         end
  170.       elseif x >= 25 and x <= 37 and y == 5 and m == 1 then
  171.         if curDir == "/" then
  172.           shell.run("edit "..l[y2])
  173.         else
  174.           shell.run("edit "..curDir.."/"..l[y2])
  175.         end
  176.       end
  177.     end
  178.   end
  179.   code()
  180. end
  181.  
  182.  
  183.  
  184.  
  185. function desktop()
  186.   local w,h = term.getSize()
  187.   function drawDesk()
  188.     bg(colors.white)
  189.     local w,h = term.getSize()
  190.     paintutils.drawLine(1,h,w,h,colors.gray)
  191.     paintutils.drawLine(1,h,5,19,colors.green)
  192.     term.setCursorPos(1,h)
  193.     term.setTextColor(colors.white)
  194.     write("Start")
  195.     term.setCursorPos(w-8,19)
  196.     term.setBackgroundColor(colors.gray)
  197.     write(textutils.formatTime(os.time(),false))
  198.     if menu == 1 then
  199.       pList()
  200.     end
  201.   end
  202.   function pList()
  203.     term.setCursorPos(1,h-1)
  204.     print("          ")
  205.     term.setCursorPos(1,h-2)
  206.     print(" Shutdown ")
  207.     term.setCursorPos(1,h-3)
  208.     print("          ")
  209.     term.setCursorPos(1,h-4)
  210.     print(" File Man ")
  211.     term.setCursorPos(1,h-5)
  212.     print("          ")
  213.     term.setCursorPos(1,h-6)
  214.     print(" Shell    ")
  215.     term.setCursorPos(1,h-7)
  216.     print("          ")
  217.     term.setCursorPos(1,h-8)
  218.     print(" About    ")
  219.     term.setCursorPos(1,h-9)
  220.     print("          ")
  221.   end
  222.   menu = 0
  223.   a = false
  224.   drawDesk()
  225.   repeat
  226.     t = os.startTimer(1)
  227.     e,b,x,y = os.pullEvent()
  228.     if e == "mouse_click" then
  229.       if x >= 1 and x <= 11 and y == h-2  and menu == 1 then
  230.         os.shutdown()
  231.       elseif x >= 1 and x <= 6 and y == 19 and menu == 0 then
  232.         menu = 1
  233.         drawDesk()
  234.       elseif x >= 1 and x <= 6 and y == 19 and menu == 1 then
  235.         menu = 0
  236.         drawDesk()
  237.       elseif x >= 1 and x <= 11 and y == h-4 and menu == 1 then
  238.         wip()
  239.         a = true
  240.       elseif x >= 1 and x <= 11 and y == h-6 and menu == 1 then
  241.         shellProg()
  242.         a = true
  243.       elseif x >= 1 and x <= 11 and y == h-8 and menu == 1 then
  244.         about()
  245.         a = true
  246.       end
  247.     elseif e == "timer" and b == t then
  248.       drawDesk()                            
  249.       end
  250.     until a
  251.   end
  252.  
  253. --[ Beginning ]--
  254.  
  255. fadeIn()
  256. paintutils.drawImage(img,23,5)
  257. term.setBackgroundColor(colors.white)
  258. term.setTextColor(colors.gray)
  259. center(11,"Codename Hybrid")
  260. center(12,"All in one.")
  261.  
  262. term.setTextColor(colors.blue)
  263. centerW(19,"Press ALT for system setup.")
  264. local t = os.startTimer(3)
  265. b = false
  266. repeat
  267. e = {os.pullEvent()}
  268. if e[1] == "timer" and e[2] == t then
  269.   b = true
  270.   desktop()
  271. elseif e[1] == "key" and e[2] == 56 then
  272.   b = true
  273.   bios()
  274. end
  275. until b
Advertisement
Add Comment
Please, Sign In to add comment