Advertisement
GravityScore

Lightshot

Jan 11th, 2013
1,951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.01 KB | None | 0 0
  1.  
  2. --  
  3. --  Lighshot Screen Recorder
  4. --  Made by GravityScore
  5. --  
  6.  
  7.  
  8. --  -------- Variables
  9.  
  10. --  Lower the loop rate to decrease recording lag but to decrease compression
  11. --  Do not set to below 50 else the file could become really big
  12. local loopRate = 300
  13.  
  14. -- Version
  15. local version = "1.5"
  16.  
  17. -- Terminal
  18. local oldTerm = {}
  19. local newTerm = {}
  20. local w, h = term.getSize()
  21.  
  22. -- Events
  23. local event_exitRecording = "lightshot_exitRecordingEvent"
  24.  
  25. -- Locations
  26. local lightshotURL = "https://raw.github.com/GravityScore/Lightshot/master/lightshot.lua"
  27. local lightshotLocation = "/" .. shell.getRunningProgram()
  28. local recordLocation = "/.lightshot_recording"
  29.  
  30. -- Variables
  31. local clock = 0
  32. local nfaRecording = false
  33. local paused = false
  34. local handle = nil
  35.  
  36. local recordHeader = [[
  37. --  
  38. --  Recorded by Lightshot
  39. --  
  40.  
  41. local function sp(...) return sleep(...) end
  42. local function c(...) return term.write(...) end
  43. local function d(...) return term.setCursorPos(...) end
  44. local function e(...) return term.setBackgroundColor(...) end
  45. local function f(...) return term.setTextColor(...) end
  46. local function g(...) return term.clear(...) end
  47. local function h(...) return term.clearLine() end
  48. local function i(...) return term.setCursorBlink(...) end
  49. local function j(...) return term.scroll(...) end
  50.  
  51. -- sD here...
  52.  
  53. ]]
  54.  
  55.  
  56. --  -------- Utilities
  57.  
  58. local function modRead(properties)
  59.     local w, h = term.getSize()
  60.     local defaults = {replaceChar = nil, history = nil, visibleLength = nil, textLength = nil,
  61.         liveUpdates = nil, exitOnKey = nil}
  62.     if not properties then properties = {} end
  63.     for k, v in pairs(defaults) do if not properties[k] then properties[k] = v end end
  64.     if properties.replaceChar then properties.replaceChar = properties.replaceChar:sub(1, 1) end
  65.     if not properties.visibleLength then properties.visibleLength = w end
  66.  
  67.     local sx, sy = term.getCursorPos()
  68.     local line = ""
  69.     local pos = 0
  70.     local historyPos = nil
  71.  
  72.     local function redraw(repl)
  73.         local scroll = 0
  74.         if properties.visibleLength and sx + pos > properties.visibleLength + 1 then
  75.             scroll = (sx + pos) - (properties.visibleLength + 1)
  76.         end
  77.  
  78.         term.setCursorPos(sx, sy)
  79.         local a = repl or properties.replaceChar
  80.         if a then term.write(string.rep(a, line:len() - scroll))
  81.         else term.write(line:sub(scroll + 1, -1)) end
  82.         term.setCursorPos(sx + pos - scroll, sy)
  83.     end
  84.  
  85.     local function sendLiveUpdates(event, ...)
  86.         if type(properties.liveUpdates) == "function" then
  87.             local ox, oy = term.getCursorPos()
  88.             properties.liveUpdates(line, event, ...)
  89.             if a == true and data == nil then
  90.                 term.setCursorBlink(false)
  91.                 return line
  92.             elseif a == true and data ~= nil then
  93.                 term.setCursorBlink(false)
  94.                 return data
  95.             end
  96.             term.setCursorPos(ox, oy)
  97.         end
  98.     end
  99.  
  100.     term.setCursorBlink(true)
  101.     while true do
  102.         local e, but, x, y, p4, p5 = os.pullEvent()
  103.  
  104.         if e == "char" then
  105.             local s = false
  106.             if properties.textLength and line:len() < properties.textLength then s = true
  107.             elseif not properties.textLength then s = true end
  108.  
  109.             local canType = true
  110.             if not properties.grantPrint and properties.refusePrint then
  111.                 local canTypeKeys = {}
  112.                 if type(properties.refusePrint) == "table" then
  113.                     for _, v in pairs(properties.refusePrint) do
  114.                         table.insert(canTypeKeys, tostring(v):sub(1, 1))
  115.                     end
  116.                 elseif type(properties.refusePrint) == "string" then
  117.                     for char in properties.refusePrint:gmatch(".") do
  118.                         table.insert(canTypeKeys, char)
  119.                     end
  120.                 end
  121.                 for _, v in pairs(canTypeKeys) do if but == v then canType = false end end
  122.             elseif properties.grantPrint then
  123.                 canType = false
  124.                 local canTypeKeys = {}
  125.                 if type(properties.grantPrint) == "table" then
  126.                     for _, v in pairs(properties.grantPrint) do
  127.                         table.insert(canTypeKeys, tostring(v):sub(1, 1))
  128.                     end
  129.                 elseif type(properties.grantPrint) == "string" then
  130.                     for char in properties.grantPrint:gmatch(".") do
  131.                         table.insert(canTypeKeys, char)
  132.                     end
  133.                 end
  134.                 for _, v in pairs(canTypeKeys) do if but == v then canType = true end end
  135.             end
  136.  
  137.             if s and canType then
  138.                 line = line:sub(1, pos) .. but .. line:sub(pos + 1, -1)
  139.                 pos = pos + 1
  140.                 redraw()
  141.             end
  142.         elseif e == "key" then
  143.             if but == keys.enter then break
  144.             elseif but == keys.left then if pos > 0 then pos = pos - 1 redraw() end
  145.             elseif but == keys.right then if pos < line:len() then pos = pos + 1 redraw() end
  146.             elseif (but == keys.up or but == keys.down) and properties.history then
  147.                 redraw(" ")
  148.                 if but == keys.up then
  149.                     if historyPos == nil and #properties.history > 0 then
  150.                         historyPos = #properties.history
  151.                     elseif historyPos > 1 then
  152.                         historyPos = historyPos - 1
  153.                     end
  154.                 elseif but == keys.down then
  155.                     if historyPos == #properties.history then historyPos = nil
  156.                     elseif historyPos ~= nil then historyPos = historyPos + 1 end
  157.                 end
  158.  
  159.                 if properties.history and historyPos then
  160.                     line = properties.history[historyPos]
  161.                     pos = line:len()
  162.                 else
  163.                     line = ""
  164.                     pos = 0
  165.                 end
  166.  
  167.                 redraw()
  168.                 sendLiveUpdates("history")
  169.             elseif but == keys.backspace and pos > 0 then
  170.                 redraw(" ")
  171.                 line = line:sub(1, pos - 1) .. line:sub(pos + 1, -1)
  172.                 pos = pos - 1
  173.                 redraw()
  174.                 sendLiveUpdates("delete")
  175.             elseif but == keys.home then
  176.                 pos = 0
  177.                 redraw()
  178.             elseif but == keys.delete and pos < line:len() then
  179.                 redraw(" ")
  180.                 line = line:sub(1, pos) .. line:sub(pos + 2, -1)
  181.                 redraw()
  182.                 sendLiveUpdates("delete")
  183.             elseif but == keys["end"] then
  184.                 pos = line:len()
  185.                 redraw()
  186.             elseif properties.exitOnKey then
  187.                 if but == properties.exitOnKey or (properties.exitOnKey == "control" and
  188.                         (but == 29 or but == 157)) then
  189.                     term.setCursorBlink(false)
  190.                     return nil
  191.                 end
  192.             end
  193.         end
  194.  
  195.         sendLiveUpdates(e, but, x, y, p4, p5)
  196.     end
  197.  
  198.     term.setCursorBlink(false)
  199.     if line ~= nil then line = line:gsub("^%s*(.-)%s*$", "%1") end
  200.     return line
  201. end
  202.  
  203. local function centerPrint(text, ny)
  204.     if type(text) == "table" then for _, v in pairs(text) do centerPrint(v) end
  205.     else
  206.         local x, y = term.getCursorPos()
  207.         local w, h = term.getSize()
  208.         term.setCursorPos(w/2 - text:len()/2 + (#text % 2 == 0 and 1 or 0), ny or y)
  209.         print(text)
  210.     end
  211. end
  212.  
  213.  
  214. --  -------- Updating
  215.  
  216. local function download(url, path)
  217.     for i = 1, 3 do
  218.         local response = http.get(url)
  219.         if response then
  220.             local data = response.readAll()
  221.             response.close()
  222.             if path then
  223.                 local f = io.open(path, "w")
  224.                 f:write(data)
  225.                 f:close()
  226.             end
  227.             return true
  228.         end
  229.     end
  230.  
  231.     return false
  232. end
  233.  
  234. local function updateClient()
  235.     local updateLocation = "/.lightshot-update"
  236.     fs.delete(updateLocation)
  237.  
  238.     download(lightshotURL, updateLocation)
  239.     local a = io.open(updateLocation, "r")
  240.     local b = io.open(lightshotLocation, "r")
  241.     local new = a:read("*a")
  242.     local cur = b:read("*a")
  243.     a:close()
  244.     b:close()
  245.  
  246.     if cur ~= new then
  247.         fs.delete(lightshotLocation)
  248.         fs.move(updateLocation, lightshotLocation)
  249.         return true
  250.     else
  251.         fs.delete(updateLocation)
  252.         return false
  253.     end
  254. end
  255.  
  256.  
  257. --  -------- Compression
  258.  
  259. local sD = {{}}
  260. local cD = {}
  261.  
  262. local function proccessFunction(data)
  263.     if data:len() < 8 then
  264.         if data:sub(-1,-1) == "]" then return "[[" .. data .. "] .. \"]\""
  265.         else return "[[" .. data .. "]]" end
  266.     end
  267.     if cD[v] then return cD[v] end
  268.     for k, v in pairs(sD[#sD]) do
  269.         if v == data then
  270.             cD[v] = ("sD[" .. #sD .. "][" .. k .. "]")
  271.             return("sD[" .. #sD .. "][" .. k .. "]")
  272.         end
  273.     end
  274.     table.insert(sD[#sD], data)
  275.     local returnData = ("sD[".. #sD .. "][" .. #sD[#sD] .. "]")
  276.     if #sD[#sD] > loopRate then sD[#sD + 1] = {} end
  277.     return returnData
  278. end
  279.  
  280.  
  281. --  -------- Terminal Override
  282.  
  283. local function add(...)
  284.     if not handle then
  285.         if fs.exists(recordLocation) then
  286.             handle = io.open(recordLocation, "a")
  287.         else
  288.             handle = io.open(recordLocation, "w")
  289.         end
  290.     end
  291.  
  292.     for _, v in pairs({...}) do
  293.         handle:write(v)
  294.     end
  295. end
  296.  
  297. local bg, tc, blnk = -1, -1, nil
  298. for k, v in pairs(term.native) do oldTerm[k] = v end
  299.  
  300. newTerm.write = function(...)
  301.     local text = ""
  302.     for k, v in pairs({...}) do text = text .. tostring(v) end
  303.  
  304.     local a = ""
  305.     if not paused and os.clock() - clock > 0 then
  306.         a = "sp(" .. os.clock() - clock .. ") "
  307.     end
  308.     text = proccessFunction(text)
  309.     local b = "c(" .. text .. ")\n"
  310.  
  311.     add(a .. b)
  312.     clock = os.clock()
  313.  
  314.     if not nfaRecording then return oldTerm.write(...) end
  315. end
  316.  
  317. newTerm.setCursorPos = function(x, y)
  318.     local a = ""
  319.     if not paused and os.clock() - clock > 0 then
  320.         a = "sp(" .. os.clock() - clock .. ") "
  321.     end
  322.     add(a .. "d(" .. tostring(x) .. ", " .. tostring(y) .. ")\n")
  323.     clock = os.clock()
  324.  
  325.     return oldTerm.setCursorPos(x, y)
  326. end
  327.  
  328. newTerm.getCursorPos = function(...) return oldTerm.getCursorPos(...) end
  329.  
  330. newTerm.setBackgroundColor = function(col)
  331.     if bg ~= col then
  332.         local a = ""
  333.         if not paused and not nfaRecording and os.clock() - clock > 0 then
  334.             a = "sp(" .. os.clock() - clock .. ") "
  335.         end
  336.  
  337.         add(a .. "e(" .. tostring(col) .. ")\n")
  338.         clock = os.clock()
  339.         bg = col
  340.     end
  341.  
  342.     return oldTerm.setBackgroundColor(col)
  343. end
  344.  
  345. newTerm.setTextColor = function(col)
  346.     if tc ~= col then
  347.         local a = ""
  348.         if not paused and not nfaRecording and os.clock() - clock > 0 then
  349.             a = "sp(" .. os.clock() - clock .. ") "
  350.         end
  351.  
  352.         add(a .. "f(" .. tostring(col) .. ")\n")
  353.         clock = os.clock()
  354.         tc = col
  355.     end
  356.  
  357.     return oldTerm.setTextColor(col)
  358. end
  359.  
  360. newTerm.setBackgroundColour = function(col) return term.setBackgroundColor(col) end
  361. newTerm.setTextColour = function(col) return term.setTextColor(col) end
  362.  
  363. newTerm.clear = function(...)
  364.     local a = ""
  365.     if not paused and os.clock() - clock > 0 then
  366.         a = "sp(" .. os.clock() - clock .. ") "
  367.     end
  368.     add(a .. "g()\n")
  369.     clock = os.clock()
  370.  
  371.     return oldTerm.clear(...)
  372. end
  373.  
  374. newTerm.clearLine = function(...)
  375.     local a = ""
  376.     if not paused and os.clock() - clock > 0 then
  377.         a = "sp(" .. os.clock() - clock .. ") "
  378.     end
  379.     add(a .. "h()\n")
  380.     clock = os.clock()
  381.  
  382.     return oldTerm.clearLine(...)
  383. end
  384.  
  385. newTerm.setCursorBlink = function(flag)
  386.     if flag ~= blnk then
  387.         local a = ""
  388.         if not paused and os.clock() - clock > 0 then
  389.             a = "sp(" .. os.clock() - clock .. ") "
  390.         end
  391.         add(a .. "i(" .. tostring(flag) .. ")\n")
  392.         clock = os.clock()
  393.         blnk = flag
  394.     end
  395.  
  396.     return oldTerm.setCursorBlink(flag)
  397. end
  398.  
  399. newTerm.scroll = function(n)
  400.     local a = ""
  401.     if not paused and os.clock() - clock > 0 then
  402.         a = "sp(" .. os.clock() - clock .. ") "
  403.     end
  404.     add(a .. "j(" .. tostring(n) .. ")\n")
  405.     clock = os.clock()
  406.  
  407.     return oldTerm.scroll(n)
  408. end
  409.  
  410. newTerm.getSize = function(...) return oldTerm.getSize(...) end
  411. newTerm.redirect = function(...) return oldTerm.redirect(...) end
  412. newTerm.restore = function(...) return oldTerm.restore(...) end
  413. newTerm.isColor = function(...) return oldTerm.isColor and oldTerm.isColor(...) end
  414. newTerm.isColour = function(...) return term.isColor(...) end
  415.  
  416.  
  417. --  -------- Recording
  418.  
  419. local function record(location)
  420.     while true do
  421.         local e, key = os.pullEventRaw()
  422.         if (e == "key" and key == 59) or e == event_exitRecording or e == "terminate" then
  423.             local a = ""
  424.             if os.clock() - clock > 0 then a = "sp(" .. os.clock() - clock .. ") " end
  425.             add(a)
  426.  
  427.             add("\n\nterm.setCursorBlink(false)\n")
  428.             add("if term.isColor() then term.setTextColor(colors.yellow)\n")
  429.             add("else term.setTextColor(colors.white) end\n")
  430.             add("term.setBackgroundColor(colors.black)\n")
  431.             add("term.clear()\n")
  432.             add("term.setCursorPos(1, 1)\n")
  433.             add("print(\"End of Recording!\")\n")
  434.  
  435.             local sd = "local sD = " .. textutils.serialize(sD) .. "\n"
  436.  
  437.             term.restore()
  438.             term.setCursorBlink(false)
  439.  
  440.             handle:close()
  441.             handle = nil
  442.             local f = io.open(recordLocation, "r")
  443.             local ncont = f:read("*a")
  444.             f:close()
  445.  
  446.             ncont = ncont:gsub("%-%- sD here...\n", sd)
  447.             local f = io.open(location, "w")
  448.             f:write(ncont)
  449.             f:close()
  450.             fs.delete(recordLocation)
  451.  
  452.             break
  453.         elseif e == "key" and key == 61 then
  454.             paused = not paused
  455.             if paused then
  456.                 add("sp(2)\n")
  457.             end
  458.         end
  459.     end
  460. end
  461.  
  462.  
  463. --  -------- Movie
  464.  
  465. local function loadNfa(path)
  466.     local ret = {}
  467.     if fs.exists(path) and not fs.isDir(path) then
  468.         local f = io.open(path, "r")
  469.         local l = f:read("*l")
  470.         local curFrame = ""
  471.         while l do
  472.             if l ~= "" and l ~= "~" then curFrame = curFrame .. l .. "\n"
  473.             elseif l == "~" then
  474.                 table.insert(ret, curFrame)
  475.                 curFrame = ""
  476.             end
  477.             l = f:read("*l")
  478.         end
  479.         f:close()
  480.     end
  481.  
  482.     return ret
  483. end
  484.  
  485. local function movie(location, duration)
  486.     nfaRecording = true
  487.     local frames = loadNfa(location)
  488.     if frames ~= {} then
  489.         for i, v in ipairs(frames) do
  490.             term.setTextColor(colors.white)
  491.             term.setBackgroundColor(colors.black)
  492.             term.clear()
  493.  
  494.             local tempImageLocation = "/.lightshot-temp-image"
  495.             local f = io.open(tempImageLocation, "w")
  496.             f:write(v)
  497.             f:close()
  498.             local a = paintutils.loadImage(tempImageLocation)
  499.             paintutils.drawImage(a, 1, 1)
  500.             fs.delete(tempImageLocation)
  501.             add("sp(" .. duration .. ")\n")
  502.         end
  503.  
  504.         add("sp(" .. duration .. ")\n")
  505.     end
  506.  
  507.     add("\n\nterm.setCursorBlink(false)\n")
  508.     add("if term.isColor() then term.setTextColor(colors.yellow)\n")
  509.     add("else term.setTextColor(colors.white) end\n")
  510.     add("term.setBackgroundColor(colors.black)\n")
  511.     add("term.clear()\n")
  512.     add("term.setCursorPos(1, 1)\n")
  513.     add("print(\"The End! :D\")\n")
  514.  
  515.     nfaRecording = false
  516.     term.restore()
  517.     term.setCursorBlink(false)
  518.     if term.isColor() then term.setTextColor(colors.yellow)
  519.     else term.setTextColor(colors.white) end
  520.     term.setBackgroundColor(colors.black)
  521.     term.clear()
  522.     term.setCursorPos(1, 1)
  523.     print("Movie Recorded Successfully!")
  524.  
  525.     handle:close()
  526.     handle = nil
  527.     local f = io.open(recordLocation, "r")
  528.     local ncont = f:read("*a")
  529.     f:close()
  530.  
  531.     local sd = "local sD = " .. textutils.serialize(sD) .. "\n"
  532.     ncont = ncont:gsub("%-%- sD here...\n", sd)
  533.     local f = io.open(location, "w")
  534.     f:write(ncont)
  535.     f:close()
  536.     fs.delete(recordLocation)
  537. end
  538.  
  539.  
  540. --  -------- Main
  541.  
  542. local theme = {}
  543. if term.isColor and term.isColor() then
  544.     theme = {
  545.         ["prompt"] = "cyan",
  546.         ["promptHighlight"] = "lightBlue",
  547.         ["textColor"] = "white",
  548.     }
  549. else
  550.     theme = {
  551.         ["prompt"] = "black",
  552.         ["promptHighlight"] = "black",
  553.         ["textColor"] = "white",
  554.     }
  555. end
  556.  
  557. local function drawButton(v, sel)
  558.     if sel then term.setBackgroundColor(v.highlight or colors[theme.promptHighlight])
  559.     else term.setBackgroundColor(v.bg or colors[theme.prompt]) end
  560.     term.setTextColor(v.tc or colors[theme.textColor])
  561.     for i = -1, 1 do
  562.         term.setCursorPos(v[2], v[3] + i)
  563.         term.write(string.rep(" ", v[1]:len() + 4))
  564.     end
  565.  
  566.     term.setCursorPos(v[2], v[3])
  567.     if sel then
  568.         term.setBackgroundColor(v.highlight or colors[theme.promptHighlight])
  569.         term.write(" > ")
  570.     else term.write(" - ") end
  571.     term.write(v[1] .. " ")
  572. end
  573.  
  574. local function prompt(list, dir)
  575.     local function draw(sel)
  576.         for i, v in ipairs(list) do
  577.             if i == sel then term.setBackgroundColor(v.highlight or colors[theme.promptHighlight])
  578.             else term.setBackgroundColor(v.bg or colors[theme.prompt]) end
  579.             term.setTextColor(v.tc or colors[theme.textColor])
  580.             for i = -1, 1 do
  581.                 term.setCursorPos(v[2], v[3] + i)
  582.                 term.write(string.rep(" ", v[1]:len() + 4))
  583.             end
  584.  
  585.             term.setCursorPos(v[2], v[3])
  586.             if i == sel then
  587.                 term.setBackgroundColor(v.highlight or colors[theme.promptHighlight])
  588.                 term.write(" > ")
  589.             else term.write(" - ") end
  590.             term.write(v[1] .. " ")
  591.         end
  592.     end
  593.  
  594.     local sel = 1
  595.     draw(sel)
  596.  
  597.     while true do
  598.         local e, but, x, y = os.pullEvent()
  599.         if e == "key" and but == 28 then return list[sel][1]
  600.         elseif e == "key" and but == 200 and sel > 1 then
  601.             sel = sel - 1
  602.             draw(sel)
  603.         elseif e == "key" and but == 208 and ((err == true and sel < #list - 1) or (sel < #list)) then
  604.             sel = sel + 1
  605.             draw(sel)
  606.         elseif e == "key" and but == 203 and sel > 2 then
  607.             sel = sel - 2
  608.             draw(sel)
  609.         elseif e == "key" and but == 205 and sel < 3 then
  610.             sel = sel + 2
  611.             draw(sel)
  612.         elseif e == "mouse_click" then
  613.             for i, v in ipairs(list) do
  614.                 if x >= v[2] - 1 and x <= v[2] + v[1]:len() + 3 and y >= v[3] - 1 and y <= v[3] + 1 then
  615.                     return list[i][1]
  616.                 end
  617.             end
  618.         end
  619.     end
  620. end
  621.  
  622. local function menu()
  623.     term.setBackgroundColor(colors.gray)
  624.     term.setTextColor(colors.white)
  625.     term.clear()
  626.     term.setCursorPos(1, 1)
  627.  
  628.     term.setBackgroundColor(colors.lightGray)
  629.     for i = 2, 4 do term.setCursorPos(1, i) term.clearLine() end
  630.     term.setCursorPos(3, 3)
  631.     term.write("Lightshot " .. version)
  632.  
  633.     local opt = prompt({{"Record a Video", w/2 - 16, 9}, {"Record an Animation", w/2 - 21, 13},
  634.         {"Update Lightshot", w/2 + 4, 9}, {"Exit", w/2 + 4, 13, bg = (term.isColor and term.isColor())
  635.         and colors.red or colors.black, highlight = (term.isColor and term.isColor()) and colors.pink
  636.         or colors.black}}, "vertical")
  637.     if opt == "Record a Video" or opt == "Record an Animation" then
  638.         term.setBackgroundColor(colors.gray)
  639.         for i = 7, 14 do term.setCursorPos(1, i) term.clearLine() end
  640.         term.setBackgroundColor(colors.cyan)
  641.         for i = 8, 11 do term.setCursorPos(7, i) term.write(string.rep(" ", w - 14)) end
  642.         drawButton({"Control to Return to Menu", 7, 14}, true)
  643.         term.setBackgroundColor(colors.cyan)
  644.         term.setCursorPos(8, 9)
  645.         term.write("Where to save the recording?")
  646.         term.setCursorPos(9, 10)
  647.         term.write("/")
  648.         local loc = modRead({visibleLength = w - 14, exitOnKey = "control"})
  649.         if not loc or loc == "" then return "menu" end
  650.  
  651.         term.setCursorPos(8, 9)
  652.         term.write(string.rep(" ", 28))
  653.         term.setCursorPos(8, 9)
  654.         loc = "/" .. loc
  655.         if fs.isReadOnly(loc) then term.write("File is Read Only!") sleep(1.6) return "menu"
  656.         elseif fs.isDir(loc) then term.write("Location is a directory!") sleep(1.6) return "menu"
  657.         elseif opt == "Record a Video" then
  658.             if fs.exists(loc) then fs.delete(loc) end
  659.             term.setTextColor(colors.white)
  660.             term.setBackgroundColor(colors.black)
  661.             term.clear()
  662.             term.setCursorPos(2, 5)
  663.             term.write("Press F1 to end the recording")
  664.             term.setCursorPos(2, 6)
  665.             term.write("Press F3 to pause or unpause the recording")
  666.  
  667.             if term.isColor and term.isColor() then term.setTextColor(colors.yellow) end
  668.             for i = 1, 3 do
  669.                 term.setCursorPos(2, 3)
  670.                 term.clearLine()
  671.                 term.write("Recording in " .. 4 - i .. "...")
  672.                 sleep(1)
  673.             end
  674.  
  675.             return "record", loc
  676.         elseif opt == "Record an Animation" then
  677.             if loc:sub(-4, -1) ~= ".nfa" then
  678.                 term.write("File Not An nPaintPro Animation!")
  679.                 sleep(1.6)
  680.                 return "menu"
  681.             end
  682.  
  683.             term.setCursorPos(8, 9)
  684.             term.write("Duration between frames (seconds):")
  685.             term.setCursorPos(9, 10)
  686.             term.write(string.rep(" ", w - 16))
  687.             term.setCursorPos(9, 10)
  688.             local dur = modRead({visibleLength = w - 14, exitOnKey = "control"})
  689.             if not dur or dur == "" then return "menu" end
  690.  
  691.             term.setCursorPos(8, 9)
  692.             term.write(string.rep(" ", 38))
  693.             term.setCursorPos(8, 9)
  694.             dur = tonumber(dur)
  695.             if not dur then term.write("Duration must be an integer!") sleep(1.6) return "menu"
  696.             else return "tomovie", loc, dur end
  697.         end
  698.     elseif opt == "Update Lightshot" then
  699.         term.setTextColor(colors.white)
  700.         term.setBackgroundColor(colors.lightGray)
  701.         term.setCursorPos(3, 3)
  702.         term.clearLine()
  703.         term.write("Checking for Updates...")
  704.         term.setCursorPos(3, 3)
  705.         if updateClient() then
  706.             term.clearLine()
  707.             term.write("Updated!")
  708.             sleep(1.6)
  709.             opt = "Exit"
  710.         else
  711.             term.clearLine()
  712.             term.write("No Updates Found!")
  713.             sleep(1.6)
  714.             return "menu"
  715.         end
  716.     end if opt == "Exit" then return nil end
  717. end
  718.  
  719. local function main()
  720.     local action, location, duration = "menu", nil, nil
  721.     while action == "menu" do action, location, duration = menu() end
  722.  
  723.     if action and location then
  724.         clock = os.clock()
  725.         add(recordHeader)
  726.         term.redirect(newTerm)
  727.  
  728.         term.setTextColor(colors.white)
  729.         term.setBackgroundColor(colors.black)
  730.         term.clear()
  731.         term.setCursorPos(1, 1)
  732.         if action == "record" then
  733.             parallel.waitForAny(function()
  734.                 record(location)
  735.             end, function()
  736.                 term.setBackgroundColor(colors.black)
  737.                 term.setTextColor(colors.white)
  738.                 term.clear()
  739.                 term.setCursorPos(1, 1)
  740.  
  741. --[[
  742.                 -- Run startup
  743.                 if fs.exists("/startup") and not fs.isDir("/startup") then shell.run("/startup") end
  744.                 term.setBackgroundColor(colors.black)
  745.                 term.setTextColor(colors.white)
  746.                 term.clear()
  747.                 term.setCursorPos(1, 1)
  748. ]]--
  749.  
  750.                 -- Run shell
  751.                 shell.run("/rom/programs/shell")
  752.                 os.queueEvent(event_exitRecording)
  753.             end)
  754.  
  755.             if term.isColor() then term.setTextColor(colors.yellow)
  756.             else term.setTextColor(colors.white) end
  757.             term.setBackgroundColor(colors.black)
  758.             term.clear()
  759.             term.setCursorPos(2, 3)
  760.             print("Recording Saved!")
  761.             sleep(1.1)
  762.         elseif action == "tomovie" then
  763.             movie(location, duration)
  764.         end
  765.     else
  766.         return "exit"
  767.     end
  768. end
  769.  
  770. -- Run
  771. local oldDir = shell.dir()
  772. while main() ~= "exit" do end
  773. shell.setDir(oldDir)
  774.  
  775. -- Exit Message
  776. term.setBackgroundColor(colors.black)
  777. term.setTextColor(colors.white)
  778. term.clear()
  779. term.setCursorPos(1, 1)
  780. centerPrint("Thanks for Using Lightshot " .. version .. "!")
  781. centerPrint("Made by GravityScore and 1lann")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement