Guest User

chameleon efi - spaghetti code monster?

a guest
Feb 2nd, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. --[[
  2.  
  3. Chameleon EFI
  4. v1.0
  5.  
  6. ]]--
  7. fs.delete("/boot.log")
  8.  
  9. local w, h = term.getSize()
  10.  
  11. isDebug = false
  12.  
  13. Chameleon = {
  14. Log = {
  15. l = function(level, msg)
  16. local msg = "\n[" .. os.time() .. "] [" .. level .. "] " .. tostring(msg)
  17. if isDebug then
  18. print(msg)
  19. end
  20. local h = fs.open("/boot.log", "a")
  21. h.write(msg)
  22. h.close()
  23. end,
  24. },
  25. printc = function(text, y)
  26. local w, h = term.getSize()
  27. x = math.ceil(math.ceil((w / 2) - (#text / 2)), 0)+1
  28. term.setCursorPos(x, y)
  29. write(text)
  30. return x
  31. end,
  32. drawlogo = function(x,y)
  33. local bg = term.getBackgroundColor()
  34. local fg = term.getTextColor()
  35. if term.isColor() then
  36. paintutils.drawLine(x,y,x,y+2, colors.lime)
  37. paintutils.drawLine(x,y+2,x+2,y+2, colors.lime)
  38. paintutils.drawLine(x,y,x+1,y,colors.lime)
  39. paintutils.drawPixel(x+2,y,colors.white)
  40. paintutils.drawPixel(x+3,y,colors.black)
  41. else
  42. paintutils.drawLine(x,y,x,y+3, colors.white)
  43. paintutils.drawLine(x,y+3,x+2,y+3, colors.white)
  44. paintutils.drawLine(x,y,x+1,y,colors.white)
  45. paintutils.drawPixel(x+2,y,colors.white)
  46. paintutils.drawPixel(x+3,y,colors.white)
  47. end
  48. term.setBackgroundColor(bg)
  49. term.setTextColor(fg)
  50. end,
  51. Status = "",
  52. Running = true
  53. }
  54.  
  55. startupKey = function()
  56. while true do
  57. local event, arg = os.pullEvent()
  58. if event=='chameleon_ready' then
  59. Chameleon.Log.l("BOOT", "No key. Starting normally.")
  60. return nil
  61. elseif event == "key" then
  62. Chameleon.Log.l("BOOT", "Boot Key: "..arg)
  63. return arg
  64. end
  65. end
  66. end
  67.  
  68. local function BootScreen()
  69. local c = 0
  70. while Chameleon.Running do
  71.  
  72. paintutils.drawFilledBox(1,h - 6, w, h, colors.gray)
  73.  
  74. if c == 0 then
  75. term.setCursorPos(w / 2 - 1, h - 3)
  76. term.write("0 o o")
  77. elseif c == 1 then
  78. term.setCursorPos(w / 2 - 1, h - 3)
  79. term.write("o 0 o")
  80. elseif c == 2 then
  81. term.setCursorPos(w / 2 - 1, h - 3)
  82. term.write("o o 0")
  83. end
  84. c = c + 1
  85. if c > 2 then
  86. c = 0
  87. end
  88.  
  89. term.setTextColor(colors.lightGray)
  90. Chameleon.printc(Chameleon.Status, h - 5)
  91. term.setTextColor(colors.white)
  92.  
  93. Chameleon.drawlogo(w / 2, h / 2 - 2)
  94.  
  95. sleep(0.5)
  96. end
  97. end
  98.  
  99. parallel.waitForAll(function() sleep(2) os.queueEvent('chameleon_ready') end, function() key = startupKey() end)
  100.  
  101. if key == keys.z then
  102. Chameleon.Log.l("BOOT", "Starting shell, goodbye!")
  103. term.setBackgroundColor(colors.black)
  104. term.setTextColor(colors.white)
  105. term.clear()
  106. term.setCursorPos(1,1)
  107.  
  108. print("Chameleon is no longer running.")
  109. print("You are in the system shell, run exit to reboot.")
  110. os.run(getfenv(), "/rom/programs/shell")
  111.  
  112. os.reboot()
  113. elseif key == keys.x then
  114. Chameleon.Log.l("BOOT", "Custom boot script")
  115. term.setBackgroundColor(colors.gray)
  116. term.setTextColor(colors.lightGray)
  117. term.clear()
  118. Chameleon.printc("Custom Bootup Script", h - 3)
  119. Chameleon.printc("Please type in a boot script to start.", h - 2)
  120. term.setCursorPos(1,h)
  121.  
  122. term.setBackgroundColor(colors.black)
  123. term.setTextColor(colors.white)
  124. term.clearLine()
  125. script = read()
  126.  
  127. pcall(function()shell.run(script)end) --this is a placeholder by the way, give me slack.
  128.  
  129. os.reboot()
  130. end
  131.  
  132. term.setBackgroundColor(colors.gray)
  133. term.clear()
  134. parallel.waitForAll(function() BootScreen() end, function() os.run(getfenv(), "/boot") end)
  135.  
  136. local r = ChameleonDone() --this is called after the startup script is done executing
  137. --ChameleonDone is used for executing the actual code.
  138. print(r[2])
Advertisement
Add Comment
Please, Sign In to add comment