Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local isRecording = false
- local data = {}
- local toggle = 61
- local tnat = {}
- local tArgs = {...}
- local lastt = os.clock()
- local bos = os.pullEvent
- os.pullEvent = os.pullEventRaw
- for i,v in pairs(term) do
- tnat[i] = v
- end
- function term.write(txt)
- if isRecording == true then
- table.insert(data, {os.clock()-lastt, "write", txt})
- lastt = os.clock()
- end
- tnat.write(txt)
- end
- function term.setCursorPos(x, y)
- if isRecording == true then
- table.insert(data, {os.clock()-lastt, "setpos", x, y})
- lastt = os.clock()
- end
- tnat.setCursorPos(x, y)
- end
- function term.setCursorBlink(bool)
- if isRecording == true then
- table.insert(data, {os.clock()-lastt, "blink", bool})
- lastt = os.clock()
- end
- tnat.setCursorBlink(bool)
- end
- function term.clear()
- if isRecording == true then
- table.insert(data, {os.clock()-lastt, "clear"})
- lastt = os.clock()
- end
- tnat.clear()
- end
- function term.clearLine()
- if isRecording == true then
- table.insert(data, {os.clock()-lastt, "clearline"})
- lastt = os.clock()
- end
- tnat.clearLine()
- end
- function term.setTextColor(col)
- if isRecording == true then
- table.insert(data, {os.clock()-lastt, "setcol", col})
- lastt = os.clock()
- end
- tnat.setTextColor(col)
- end
- function term.scroll(num)
- if isRecording == true then
- table.insert(data, {os.clock()-lastt, "scroll", num})
- lastt = os.clock()
- end
- tnat.scroll(num)
- end
- function term.setBackgroundColor(col)
- if isRecording == true then
- table.insert(data, {os.clock()-lastt, "setbg", col})
- lastt = os.clock()
- end
- tnat.setBackgroundColor(col)
- end
- term.setTextColour = term.setTextColor
- term.setBackgroundColour = term.setBackgroundColor
- if #tArgs == 0 then
- print("Usage: srec <record/play> [path]")
- return
- end
- local function a1()
- term.clear()
- term.setCursorPos(1, 1)
- shell.run("shell")
- end
- local function a2()
- while true do
- local event, p1, p2 = os.pullEvent("key")
- if p1 == toggle then
- isRecording = false
- term.setTextColor(colors.white)
- print("What would you like to save recording as?")
- local ty = fs.open("/"..read(), "w")
- ty.write(textutils.serialize(data))
- ty.close()
- os.pullEvent = bos
- break
- end
- end
- end
- local function play(path)
- path = shell.resolve(path)
- if fs.exists(path) and not fs.isDir(path) then
- term.clear()
- term.setCursorPos(1, 1)
- local fr = fs.open(path, "r")
- local sdata = textutils.unserialize(fr.readAll())
- fr.close()
- for i,v in pairs(sdata) do
- if v[2] == "write" then
- term.write(v[3])
- elseif v[2] == "setpos" then
- term.setCursorPos(v[3], v[4])
- elseif v[2] == "blink" then
- term.setCursorBlink(v[3])
- elseif v[2] == "clear" then
- term.clear()
- elseif v[2] == "clearline" then
- term.clearLine()
- elseif v[2] == "setcol" then
- term.setTextColor(v[3])
- elseif v[2] == "setbg" then
- term.setBackgroundColor(v[3])
- elseif v[2] == "scroll" then
- term.scroll(v[3])
- end
- if v[1] > 0.00001 then
- sleep(v[1])
- end
- end
- end
- end
- if tArgs[1]:lower() == "record" then
- isRecording = true
- lastt = os.clock()
- parallel.waitForAny(a1, a2)
- elseif tArgs[1]:lower() == "play" then
- play(tArgs[2])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement