Advertisement
CaptainSpaceCat

SkyOS

May 28th, 2015
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.74 KB | None | 0 0
  1. if not fs.exists("SkyOS_set") then
  2.   oTemp = fs.open("SkyOS_set", "w")
  3.   oTemp.writeLine("startup = false")
  4.   oTemp.writeLine("backgroundColor = 4")
  5.   oTemp.writeLine("textColor = 1")
  6.   oTemp.writeLine("backgroundColorSet = 12")
  7.   oTemp.writeLine("textColorSet = 1")
  8.   oTemp.close()
  9. end
  10. if not fs.exists("lick") then
  11.   oTemp = fs.open("lick", "w")
  12.   oTemp.writeLine("term.setBackgroundColor(colors.magenta)")
  13.   oTemp.writeLine("term.setTextColor(colors.white)")
  14.   oTemp.writeLine("print(\"slurp\")")
  15.   oTemp.close()
  16. end
  17.  
  18. local uInputPrev = {}
  19. local iColors = {}
  20. for i = 0, 15 do
  21.   iColors[i + 1] = 2 ^ i
  22. end
  23. function clear(keepvars)
  24.   os.loadAPI("SkyOS_set")
  25.   if SkyOS_set.backimg then
  26.     paintutils.drawImage(backimg[1], backimg[2], backimg[3])   -------background images(currently unsupported)
  27.   end
  28.   term.setCursorBlink(true)
  29.   termW, termH = term.getSize()
  30.   term.setBackgroundColor(iColors[SkyOS_set.backgroundColor])
  31.   term.clear()
  32.   words("Settings", termW - 7, 1, iColors[SkyOS_set.textColorSet], iColors[SkyOS_set.backgroundColorSet])
  33.   words("SkyOS V0.7", 1, 1, iColors[SkyOS_set.textColor], iColors[SkyOS_set.backgroundColor])
  34.   words(">", 1, 2)
  35.   uInput = ""
  36.   uInputNum = 0
  37.   --uInputPrev = {}
  38.   os.startTimer(.05)
  39. end
  40.  
  41. function newline()
  42.   words(">", _, _, iColors[SkyOS_set.textColor], iColors[SkyOS_set.backgroundColor])
  43.   uInput = ""
  44. end
  45.  
  46. function words(string, x, y, txtcol, bakcol)
  47.   if x and y then
  48.     term.setCursorPos(x, y)
  49.   end
  50.   if txtcol then
  51.     term.setTextColor(txtcol)
  52.   end
  53.   if bakcol then
  54.     term.setBackgroundColor(bakcol)
  55.   end
  56.   write(string)
  57. end
  58.  
  59. function delete()
  60.   uInput = string.sub(uInput, 1, #uInput - 1)
  61.   if currentX <= 1 then
  62.     words(" ", termW, currentY - 1)
  63.     term.setCursorPos(termW, currentY - 1)
  64.     currentY = currentY - 1
  65.     currentX = termW
  66.   else
  67.     words(" ", currentX - 1, currentY)
  68.     term.setCursorPos(currentX - 1, currentY)
  69.     currentX = currentX - 1
  70.   end
  71. end
  72.  
  73. function tick()
  74.   currentX, currentY = term.getCursorPos()
  75.   words("Settings", termW - 7, 1, iColors[SkyOS_set.textColorSet], iColors[SkyOS_set.backgroundColorSet])
  76.   term.setCursorPos(currentX, currentY)
  77.   if currentX == termW + 1 then
  78.     term.setCursorPos(1, currentY + 1)
  79.   end
  80.   if currentY == termH + 1 then
  81.     term.scroll(1)
  82.   end
  83.   term.setBackgroundColor(iColors[SkyOS_set.backgroundColor])
  84.   term.setTextColor(iColors[SkyOS_set.textColor])
  85.   os.startTimer(.05)
  86. end
  87.  
  88. function clickCheck(x, y, x2, y2, type)
  89.   if type then
  90.     if type == "left" then
  91.       type = 1
  92.     elseif type == "right" then
  93.       type = 2
  94.     end
  95.     if events[2] == type and events[3] >= x and events[3] <= x2 and events[4] >= y and events[4] <= y2 then
  96.       return true
  97.     else
  98.       return false
  99.     end
  100.   else
  101.     if events[3] >= x and events[3] <= x2 and events[4] >= y and events[4] <= y2 then
  102.       return true
  103.     else
  104.       return false
  105.     end
  106.   end
  107. end
  108.  
  109. function enter()
  110.   words("\n")
  111.   if uInput ~= "" then
  112.     table.insert(uInputPrev, 1, uInput)
  113.   end
  114.   if uInput == "exitOS()" then
  115.     shell.exit()
  116.   end
  117.   if SkyOS_set.backgroundColor ~= 15 then
  118.     term.setBackgroundColor(iColors[SkyOS_set.backgroundColor])
  119.   else
  120.     term.setBackgroundColor(colors.black)
  121.   end
  122.   runAttempt = shell.run(uInput)
  123.   term.setBackgroundColor(iColors[SkyOS_set.backgroundColor])
  124.   if string.sub(uInput, 1, 4) == "edit" then
  125.     clear()
  126.   else
  127.     newline()
  128.   end
  129.   uInput = ""
  130.   uInputNum = 0
  131. end
  132.  
  133. function colorbar(y, var1, var2)
  134.   for i = 1, 16 do
  135.     term.setCursorPos(i, y)
  136.     term.setBackgroundColor(iColors[i])
  137.     if i == 1 then
  138.       term.setTextColor(colors.black)
  139.     else
  140.       term.setTextColor(colors.white)
  141.     end
  142.     if var1 == i then
  143.       term.write("O")
  144.     elseif var2 == i then
  145.       term.write(".")
  146.     else
  147.       term.write(" ")
  148.     end
  149.   end
  150. end
  151.  
  152. function changeVars(changeBK, changeTC, changeST)
  153.   shell.run("copy SkyOS_set temp")
  154.   oTemp = fs.open("SkyOS_set", "w")
  155.   for line in io.lines("temp") do
  156.     if changeBK == "sky" and string.sub(line, 0, 16) == "backgroundColor " then
  157.       oTemp.writeLine("backgroundColor = " .. events[3])
  158.     elseif changeBK == "set" and string.sub(line, 0, 18) == "backgroundColorSet" then
  159.       oTemp.writeLine("backgroundColorSet = " .. events[3])
  160.     elseif changeTC == "sky" and string.sub(line, 0, 10) == "textColor " then
  161.         oTemp.writeLine("textColor = " .. events[3])
  162.     elseif changeTC == "set" and string.sub(line, 0, 12) == "textColorSet" then
  163.         oTemp.writeLine("textColorSet = " .. events[3])
  164.     elseif changeST and string.sub(line, 0, 7) == "startup" then
  165.       oTempStartup = fs.open("startup", "w")
  166.       if changeST == 1 then
  167.         oTemp.writeLine("startup = true")
  168.         oTempStartup.writeLine("shell.run(\"SkyOS\")")
  169.       elseif changeST == 0 then
  170.         oTemp.writeLine("startup = false")
  171.       end
  172.       oTempStartup.flush()
  173.       oTempStartup.close()
  174.     else
  175.       oTemp.writeLine(line)
  176.     end
  177.   end
  178.   oTemp.flush()
  179.   oTemp.close()
  180.   shell.run("delete temp")
  181. end
  182.  
  183. function settings()
  184.   term.setCursorBlink(false)
  185.   term.setBackgroundColor(iColors[SkyOS_set.backgroundColorSet])
  186.   term.clear()
  187.   words("Settings", termW/2 - 3, 1, iColors[SkyOS_set.textColorSet], iColors[SkyOS_set.backgroundColorSet])
  188.   words("Run SkyOS on Startup", 1, 3)
  189.   words("SkyOS Colors", 1, 6)
  190.   words("Settings Tab Colors", 1, 9)
  191.   words("L Click = Background", 1, termH - 1)
  192.   words("R Click = Text", 1, termH)
  193.   words("Back", termW - 3, termH)
  194.   while not donesettings do
  195.     os.loadAPI("SkyOS_set")
  196.     if SkyOS_set.startup == true then
  197.       words("     No", 1, 4, iColors[SkyOS_set.textColorSet], iColors[SkyOS_set.backgroundColorSet])
  198.       words("Yes", 1, 4, colors.yellow, colors.lightBlue)
  199.       oTemp = fs.open("startup", "w")
  200.       oTemp.writeLine("shell.run(\"" .. shell.getRunningProgram() .. "\")")
  201.       oTemp.close()
  202.     elseif SkyOS_set.startup == false then
  203.       words("     No", 1, 4, colors.yellow, colors.lightBlue)
  204.       words("Yes  ", 1, 4, iColors[SkyOS_set.textColorSet], iColors[SkyOS_set.backgroundColorSet])
  205.       if fs.exists("startup") then
  206.         shell.run("delete startup")
  207.       end
  208.     end
  209.     colorbar(7, SkyOS_set.backgroundColor, SkyOS_set.textColor)
  210.     colorbar(10, SkyOS_set.backgroundColorSet, SkyOS_set.textColorSet)
  211.     events = {os.pullEventRaw()}
  212.     if events[1] == "mouse_click" then
  213.       if clickCheck(1, 4, 3, 4, "left") and SkyOS_set.startup ~= true then
  214.         changeVars(_, _, 1)
  215.       elseif clickCheck(6, 4, 7, 4, "left") and SkyOS_set.startup ~= false then
  216.         changeVars(_, _, 0)
  217.       end
  218.       if clickCheck(1, 7, 16, 7) then
  219.         if events[2] == 1 and events[3] ~= SkyOS_set.textColor then
  220.           changeVars("sky")
  221.         elseif events[2] == 2 and events[3] ~= SkyOS_set.backgroundColor then
  222.           changeVars(_, "sky")
  223.         end
  224.       end
  225.       if clickCheck(1, 10, 16, 10) then
  226.         if events[2] == 1 and events[3] ~= SkyOS_set.textColorSet then
  227.           changeVars("set")
  228.         elseif events[2] == 2 and events[3] ~= SkyOS_set.backgroundColorSet then
  229.           changeVars(_, "set")
  230.         end
  231.       end
  232.       if clickCheck(termW - 3, termH, termW, termH, "left") then
  233.         words("Back", termW - 3, termH, _, colors.red)
  234.         sleep(.2)
  235.         donesettings = true
  236.       end
  237.     end
  238.   end
  239.   clear()
  240. end
  241.  
  242. clear()
  243. while true do
  244.   events = {}
  245.   events = {os.pullEventRaw()}
  246.   if events[1] == "timer" then
  247.     tick()
  248.   end
  249.   if events[1] == "paste" then
  250.     term.write(events[2])
  251.     uInput = uInput .. events[2]
  252.   elseif events[1] == "char" then
  253.     term.write(events[2])
  254.     uInput = uInput .. events[2]
  255.   elseif events[1] == "key" then
  256.     if events[2] == 14 and #uInput > 0 then
  257.       delete()
  258.     elseif events[2] == 28 then
  259.       enter()
  260.     elseif events[2] == 200 and uInputPrev then
  261.       if #uInputPrev > uInputNum then
  262.         for i = 1, #uInput do
  263.           delete()
  264.         end
  265.         uInputNum = uInputNum + 1
  266.         uInput = uInputPrev[uInputNum]
  267.         words(uInput)
  268.       end
  269.     elseif events[2] == 208 then
  270.       for i = 1, #uInput do
  271.         delete()
  272.       end
  273.       if uInputNum > 1 then
  274.         uInputNum = uInputNum - 1
  275.         uInput = uInputPrev[uInputNum]
  276.       else
  277.         uInputNum = 0
  278.         uInput = ""
  279.       end
  280.       words(uInput)
  281.     end
  282.   end
  283.   if events[1] == "mouse_click" then
  284.     if clickCheck(termW - 7, 1, termW, 1, "left") then
  285.       words("Settings", termW - 7, 1, colors.white, colors.orange)
  286.       sleep(.2)
  287.       donesettings = false
  288.       settings()
  289.     end
  290.   end
  291.   if events[1] == "terminate" then
  292.     words("\nTerminated", _, _, colors.red)
  293.     words("\nRebooting", _, _, colors.yellow)
  294.     shell.run("reboot")
  295.   end
  296. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement