Advertisement
PrinceOfCookies

os/.programs

Jan 25th, 2023 (edited)
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | Source Code | 0 0
  1. -- Stops Termination ability
  2. os.pullEvent = os.pullEventRaw
  3. shell.run("cd /")
  4. local tscp = term.setCursorPos -- set cursor pos
  5. local tcl = term.clearLine -- clear line
  6. local tw = term.write -- write
  7. local tc = term.clear -- clear
  8. local tgs = term.getSize -- get size
  9. local tstc = term.setTextColor
  10. local tgtc = term.getTextColor
  11.  
  12. local lightgrey = colors.lightGray
  13. local white = colors.white
  14. local black = colors.black
  15.  
  16. local w, h = tgs()
  17.  
  18. -- Centered Print function
  19.  
  20. function centerPrint(y, s, d)
  21.     local x = math.floor((w - string.len(s)) / 2)
  22.     tscp(x, y)
  23.     tcl()
  24.     if d then
  25.         tstc(lightgrey)
  26.     else
  27.         tstc(white)
  28.     end
  29.     tw(s)
  30. end
  31.  
  32. -- Draw Menu Function
  33.  
  34. local nOption = 1
  35.  
  36. local function drawMenu()
  37.     tc()
  38.     tscp(1,1)
  39.     tstc(colors.yellow)
  40.     tw("CookieOS 1.0.0")
  41.  
  42.     tstc(colors.white)
  43.     tscp(w - 11, 1)
  44.  
  45.     if nOption == 1 then
  46.         tw("Send file")
  47.     elseif nOption == 2 then
  48.         tw("Get file")
  49.     elseif nOption == 3 then
  50.         tw("Back")
  51.     else
  52.     end
  53. end
  54.  
  55.  
  56. -- GUI
  57.  
  58. tc()
  59.  
  60. local function drawFrontend()
  61.     centerPrint(math.floor(h / 2) - 3, "", true)
  62.     centerPrint(math.floor(h / 2) - 2, "Programs", false)
  63.     centerPrint(math.floor(h / 2) - 1, "", true)
  64.     centerPrint(math.floor(h / 2) + 0, (nOption == 1 and "[ Send File ]" or "Send File"), false)
  65.     centerPrint(math.floor(h / 2) + 1, (nOption == 2 and "[ Get File  ]" or "Get File"), false)
  66.     centerPrint(math.floor(h / 2) + 2, (nOption == 3 and "[ Back      ]" or " Back      "), false)
  67. end
  68.  
  69. -- Display
  70.  
  71. drawMenu()
  72. drawFrontend()
  73.  
  74. local cw = 1
  75. local clg = 256
  76. while true do
  77.     local evt, key = os.pullEvent("key")
  78.     if key == 265 then -- Up
  79.         if nOption > 1 then
  80.             nOption = nOption - 1
  81.             drawMenu()
  82.             drawFrontend()
  83.         end
  84.     elseif key == 264 then -- Down
  85.         if nOption < 3 then
  86.             nOption = nOption + 1
  87.             drawMenu()
  88.             drawFrontend()
  89.         end
  90.     elseif key == 257 then
  91.         if tgtc() == cw then
  92.             break
  93.         end
  94.     end
  95. end
  96.  
  97. tc()
  98.  
  99. -- Conditions
  100.  
  101. if nOption == 1 then
  102.     shell.run("os/.sfsecCheck")
  103. elseif nOption == 2 then
  104.     shell.run("ios/.getfile")
  105. else
  106.     shell.run(".menu")
  107. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement