-- typist.lua -- Realistic terminal typing for ComputerCraft 1.7 -- ===== CONFIG ===== local BASE_DELAY = 0.05 local VARIANCE = 0.04 local PUNCT_DELAY = 0.12 local LINE_DELAY = 0.25 -- ===== SETUP ===== local args = { ... } if not args[1] then print("Usage: typist ") return end local filename = args[1] if not fs.exists(filename) then print("File not found.") return end local file = fs.open(filename, "r") if not file then print("Could not open file.") return end math.randomseed(os.time()) local function humanSleep(base) local d = base + (math.random() * VARIANCE * 2 - VARIANCE) if d < 0 then d = 0 end sleep(d) end -- ===== TERMINAL HELPERS ===== local function advanceCursor() local x, y = term.getCursorPos() local w, h = term.getSize() if x > w then x = 1 y = y + 1 end if y > h then term.scroll(1) y = h end term.setCursorPos(x, y) end local function typeChar(c) term.write(c) advanceCursor() if c:match("[%.%,%!%?]") then humanSleep(PUNCT_DELAY) else humanSleep(BASE_DELAY) end end local function newLine() local _, y = term.getCursorPos() local _, h = term.getSize() if y >= h then term.scroll(1) term.setCursorPos(1, h) else term.setCursorPos(1, y + 1) end sleep(LINE_DELAY) end -- ===== MAIN LOOP ===== while true do local line = file.readLine() if not line then break end for i = 1, #line do typeChar(line:sub(i, i)) end newLine() end file.close()