Advertisement
FluttyProger

GeekTyper.lua

Sep 12th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local event = require("event")
  2. local term = require("term")
  3. local shell = require("shell")
  4.  
  5. local args = shell.parse(...)
  6. local path = " "
  7. local speed = 2
  8. if #args == 1 then
  9.   path = args[1]
  10. elseif #args == 2 then
  11.   path = args[1]
  12.   speed = tonumber(args[2])
  13. else
  14.   print("Usage: typer FILE [speed]")
  15.   print("FILE - путь к файлу")
  16.   print("speed - опционально, сколько будет печататься букв при нажитии кнопки")
  17.   os.exit(0)
  18. end
  19.  
  20. term.clear()
  21.  
  22. local file = io.open(path)
  23.  
  24. local function counts(test)
  25.   local numb=1
  26.   while true do
  27.     local subs = string.sub(test,1,speed*numb)
  28.     local lens = string.len(subs)
  29.     local subs2 = string.sub(test,1,speed*numb+1)
  30.     local lens2 = string.len(subs2)
  31.     numb=numb+1
  32.     if lens==lens2 then
  33.       return numb-1
  34.     end
  35.   end
  36. end
  37.  
  38. local function doubling(linen,mi)
  39.     local n1 = (speed*mi)-(speed-1)
  40.     local n2 = speed*mi
  41.     local subs = string.sub(linen,n1,n2)
  42.     return subs
  43. end
  44.  
  45. for line in file:lines() do
  46.   local count= counts(line)
  47.   for i=1,count do
  48.   event.pull("key_up")
  49.     if event.pull("key_up") then
  50.       io.write(doubling(line,i))
  51.     end
  52.   end
  53.   io.write("\n")
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement