Advertisement
jkulvich

CC: Running Line

Jan 19th, 2023 (edited)
927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.01 KB | None | 0 0
  1. -- AUTOMATIC INSTALLATION
  2. -- 1. Execute: 'pastebin run dRKxpGwC install'
  3. -- 2. Wait for reboot
  4. -- 3. Stop current programm (CTRL+T or button near shutdown)
  5. -- 4. Edit 'lines' file
  6. -- 5. Reboot
  7.  
  8. -- MANUAL INSTALLATION
  9. -- 1. Create file 'lines' with texts
  10. -- 2. Create 'startup.lua' with code: 'shell.execute("runline")'
  11. -- 3. Download the script: 'pastebin get dRKxpGwC runline.lua'
  12. -- 4. Reboot your Computer
  13.  
  14. -- LINES file
  15. -- Each new line is a new running line
  16. -- Special directives starts with #
  17. -- Directives key and value divides by :
  18. -- Here is directives:
  19. -- #fg:[color_name] -- #fg:red
  20. -- #bg:[color_name] -- #bg:black
  21. -- #dl:[run_delay]  -- #dl:0.1
  22.  
  23. local args = { ... }
  24. local file, delay = args[1], args[2]
  25.  
  26. if file == "install" then
  27.   -- Downloading main script
  28.   local req = http.get("https://pastebin.com/raw/dRKxpGwC")
  29.   local f_runline = io.open("runline.lua", "w+")
  30.   f_runline:write(req:readAll())
  31.   f_runline:close()
  32.   req:close()
  33.   -- Configuring startup
  34.   local f_startup = io.open("startup.lua", "w+")
  35.   f_startup:write("shell.execute('runline', 'lines', '0.2')")
  36.   f_startup:close()
  37.   -- Creating lines example
  38.   local f_lines = io.open("lines", "w+")
  39.   f_lines:write(":: RUNNING LINE ::\n")
  40.   f_lines:write(":: EXAMPLE TEXT ::")
  41.   f_lines:close()
  42.   -- Rebooting
  43.   os.reboot()
  44. end
  45.  
  46. local function write(text, fg, bg)
  47.  local mons = { peripheral.find("monitor") }
  48.  for _, mon in pairs(mons) do
  49.   mon.setTextColor(fg)
  50.   mon.setBackgroundColor(bg)
  51.   mon.clear()
  52.   mon.setTextScale(5)
  53.   mon.setCursorPos(1, 1)
  54.   mon.write(text)
  55.  end
  56. end
  57.  
  58. local function runline(line, delay, fg, bg)
  59.   local pad = "                "
  60.   local line = pad .. line .. pad
  61.   for i = 1, #line, 1 do
  62.     write(string.sub(line, i, i+16), fg, bg)
  63.     os.sleep(delay)
  64.   end  
  65. end
  66.  
  67. local function runlist(list, delay)
  68.   local fg = colors.white
  69.   local bg = colors.black
  70.   local dl = delay
  71.   while true do
  72.     for i = 1, #list do
  73.       if string.sub(list[i], 1, 1) == "#" then
  74.         -- Parsing directive
  75.         local directive = string.sub(list[i], 2, -1)
  76.         dparts = {}
  77.         for dpart in string.gmatch(directive, "([^:]+)") do
  78.             dparts[#dparts+1] = dpart
  79.         end
  80.         if dparts[1] == "fg" then
  81.           fg = colors[dparts[2]]
  82.         end
  83.         if dparts[1] == "bg" then
  84.           bg = colors[dparts[2]]
  85.         end
  86.         if dparts[1] == "dl" then
  87.           dl = tonumber(dparts[2])
  88.         end
  89.       else
  90.         -- Running line
  91.         runline(list[i], dl, fg, bg)
  92.       end
  93.     end
  94.   end
  95. end
  96.  
  97. while true do
  98.   local lines = {
  99.     ":: RUNNING LINE ::",
  100.     "Pass the filename arg, or create lines file"
  101.   }
  102.  
  103.   if file == nil then
  104.     local h = fs.open("lines", "r")
  105.     if h ~= nil then
  106.       h.close()
  107.       file = "lines"
  108.     end
  109.   end
  110.  
  111.   if file ~= nil then
  112.     lines = {}
  113.     for line in io.lines(file) do
  114.       lines[#lines+1] = line
  115.     end
  116.   end
  117.  
  118.   if delay == nil then
  119.     delay = 0.2
  120.   end
  121.  
  122.   runlist(lines, tonumber(delay))
  123. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement