Advertisement
LDDestroier

PasteCCan - Pastebin Client (ComputerCraft)

Jan 11th, 2016
578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.07 KB | None | 0 0
  1. --[[
  2.  pastebin get w8RHW808 pcan
  3.  std pb w8RHW808 pcan
  4.  std ld pcan <name>
  5. --]]
  6.  
  7. local username
  8. local password
  9.  
  10. local doSave = false --it IS unencrypted, so defaults to no.
  11.  
  12. --Uses AgentE382's Pastebin API implementation. You made this much easier, I must say!
  13. local currentpath = fs.getDir(shell.getRunningProgram())
  14. local savepath = fs.combine(currentpath,".userdata")
  15. local apipath = fs.combine(currentpath,"pb")
  16. if not fs.exists(apipath) then
  17.     print("Pastebin API not found! Downloading...")
  18.     local program = http.get("http://pastebin.com/raw/5SJ0d1mV")
  19.     if not program then
  20.         print("FAIL!")
  21.         error("Could not connect to pastebin...")
  22.     else
  23.         program = program.readAll()
  24.     end
  25.     local file = fs.open(apipath,"w")
  26.     file.writeLine(program)
  27.     file.close()
  28.     print("Twas a success!")
  29. end
  30.  
  31. os.loadAPI(apipath)
  32.  
  33. less = function(...) --My entire 'less' program, modified for this application.
  34.    
  35.     local tArg = {...}
  36.     local programName = fs.getName(shell.getRunningProgram())
  37.    
  38.     local oldbgcolor, oldtxtcolor = term.getBackgroundColor(), term.getTextColor()
  39.    
  40.     local renderTable = function(tab, start, ending, rightscroll, txtcolor, bgcolor)
  41.         term.setCursorPos(1,2)
  42.         local buffer = ""
  43.         local scr_x, scr_y = term.getSize()
  44.         term.setTextColor(txtcolor)
  45.         term.setBackgroundColor(bgcolor)
  46.         term.clear()
  47.         local bezelSize = #tostring(#tab)
  48.         for a = start,ending-1 do
  49.             if tab[a] then
  50.                 term.setTextColor(colors.black)
  51.                 term.setBackgroundColor(colors.lightGray)
  52.                 local bezel = tostring(a)
  53.                 local bezel = bezel..string.rep(" ",bezelSize-#bezel)
  54.                 write(bezel)
  55.                 term.setTextColor(txtcolor)
  56.                 term.setBackgroundColor(bgcolor)
  57.                 write( string.sub(buffer..tab[a],rightscroll+1,rightscroll+scr_x-bezelSize) )
  58.                 if a ~= ending-1 then
  59.                     write("\n")
  60.                 end
  61.             else
  62.                 term.setBackgroundColor(colors.lightGray)
  63.                 term.clearLine()
  64.             end
  65.         end
  66.     end
  67.    
  68.     local tableFind = function(tab, str)
  69.         for a = 1, #tab do
  70.             if tab[a] == str then
  71.                 return true, a
  72.             end
  73.         end
  74.         return false
  75.     end
  76.    
  77.     local tableStringFind = function(tab, str)
  78.         local output = {}
  79.         for a = 1, #tab do
  80.             local finder = {string.find(tab[a],str)}
  81.             if finder ~= {} then
  82.                 table.insert(finder,a)
  83.                 table.insert(output,finder)
  84.             end
  85.         end
  86.         return output
  87.     end
  88.    
  89.     local function displayCredits()
  90.         local credits = {
  91.             "LESS unix command",
  92.             "programmed by",
  93.             "EldidiStroyrr",
  94.             "",
  95.             "Coding started at",
  96.             "January 1st, 2016",
  97.             "",
  98.             "For normal CC1.7x computers, you're",
  99.             "good to go!",
  100.         }
  101.         term.setBackgroundColor(colors.gray)
  102.         if term.isColor() then term.setTextColor(colors.yellow) else term.setTextColor(colors.white) end
  103.         term.clear()
  104.         local scr_x, scr_y = term.getSize()
  105.         for a = 1, #credits+12 do
  106.             local msg = credits[a/2]
  107.             if a % 2 == 0 and msg then
  108.                 term.setCursorPos((scr_x/2)-(#msg/2),scr_y)
  109.                 write(string.upper(msg))
  110.             end
  111.             sleep(0.4)
  112.             term.scroll(1)
  113.         end
  114.         term.setBackgroundColor(colors.black)
  115.         term.clear()
  116.         term.setCursorPos(1,1)
  117.         return "butts"
  118.     end
  119.    
  120.     local getTableFromFile = function(filename)
  121.         if not filename then
  122.             return false
  123.         end
  124.         if not fs.exists(filename) then
  125.             return false
  126.         end
  127.         local file = fs.open(filename,"r")
  128.         local line = ""
  129.         local output = {}
  130.         while line do
  131.             line = file.readLine()
  132.             table.insert(output,line)
  133.         end
  134.         return output
  135.     end
  136.    
  137.     local switches = {}
  138.     for a = 1, #tArg do
  139.         if string.sub(tArg[a],1,1) == "-" then
  140.             table.insert(switches,string.sub(tArg[a],2,2))
  141.         end
  142.     end
  143.    
  144.     local lessfile
  145.     local tArgFileNo = 1
  146.     local dumpFile = nil
  147.    
  148.     if tableFind(tArg,"-d") or tableFind(tArg,"-D") then
  149.         local _, dumpPos
  150.         if tableFind(tArg,"-d") then
  151.             _, dumpPos = tableFind(tArg,"-d")
  152.             dumpPos = dumpPos + 1
  153.         else
  154.             _, dumpPos = tableFind(tArg,"-D")
  155.             dumpPos = dumpPos + 1
  156.         end
  157.         dumpFile = tArg[dumpPos]
  158.         if fs.isReadOnly(dumpFile) then
  159.             error("That path is read only.")
  160.         end
  161.         tArgFileNo = tArgFileNo + 2
  162.         if tableFind(tArg,"-a") then
  163.             lessfile = tArg[tArgFileNo]
  164.         else
  165.             lessfile = fs.combine(fs.getDir(shell.getRunningProgram()),tArg[tArgFileNo])
  166.         end
  167.     end
  168.     if tableFind(tArg,"-u") then
  169.         local _, urlPos = tableFind(tArg,"-u")
  170.         urlPos = urlPos + 1
  171.         local url = tArg[urlPos]
  172.         tArgFileNo = tArgFileNo + 2
  173.         write("Connecting...")
  174.         local internetFile = http.get(url)
  175.         if not internetFile then
  176.             print("FAILED!")
  177.             return false
  178.         end
  179.         internetFile = internetFile.readAll()
  180.         if #internetFile > fs.getFreeSpace("/") then --1 byte for every character, plus one
  181.             error("You don't have enough space!")
  182.         end
  183.         local file = fs.open(".temp","w")
  184.         file.write(internetFile)
  185.         file.close()
  186.         lessfile = ".temp"
  187.     else
  188.         lessfile = tArg[tArgFileNo]
  189.     end
  190.    
  191.     if dumpFile then
  192.         local file
  193.         if tableFind(tArg,"-d") then
  194.             file = fs.open(dumpFile,"w")
  195.             print("Dumped to '"..dumpFile.."'")
  196.         else
  197.             file = fs.open(dumpFile,"a")
  198.             print("Appended to '"..dumpFile.."'")
  199.         end
  200.         local file2 = fs.open(lessfile,"r")
  201.         file.write(file2.readAll())
  202.         file.close()
  203.         file2.close()
  204.         return true
  205.     end
  206.    
  207.     local lessfilecontents = getTableFromFile(lessfile)
  208.     local longestStringLen = 0
  209.     for a = 1, #lessfilecontents do
  210.         if #lessfilecontents[a] > longestStringLen then
  211.             longestStringLen = #lessfilecontents[a]
  212.         end
  213.     end
  214.    
  215.     local scr_x, scr_y = term.getSize()
  216.     local scrollX, scrollY = 0, 0
  217.     local event, var1, var2, var3
  218.    
  219.     local function draw()
  220.         term.setCursorPos(1,1)
  221.         renderTable(lessfilecontents,scrollY+1,scrollY+scr_y,scrollX,colors.white,colors.gray)
  222.         term.setCursorPos(1,1)
  223.         term.setTextColor(colors.white)
  224.         term.setBackgroundColor(colors.black)
  225.         term.clearLine()
  226.         if not isGuest then
  227.             write("(E)dit,(R)emove,")
  228.         end
  229.         write("(D)ownload")
  230.     end
  231.    
  232.     draw()
  233.    
  234.     local allInput = function()
  235.         local alternateScroll = false
  236.         local scr_x, scr_y = term.getSize()
  237.         local lineHistory = {}
  238.         while true do
  239.             repeat
  240.                 event, var1, var2, var3 = os.pullEvent()
  241.             until event == "key" or event == "char" or event == "mouse_scroll" or event == "key_up"
  242.             oldScrollX, oldScrollY = scrollX, scrollY
  243.             if event == "key" or event == "char" then
  244.                 if var1 == 38 then --'l' to go to line
  245.                     term.setCursorPos(1,2)
  246.                     term.setBackgroundColor(colors.black)
  247.                     term.setTextColor(colors.white)
  248.                     term.clearLine()
  249.                     write("Goto line: ")
  250.                     sleep(0)
  251.                     local lineno = tonumber(read(nil,lineHistory))
  252.                     if lineno then
  253.                         term.setCursorPos(1,1)
  254.                         if lineno < 1 then
  255.                             write("Huh? Line "..tostring(lineno).."?")
  256.                             sleep(1.2)
  257.                         elseif lineno > #lessfilecontents then
  258.                             write("Too high a number! (lines="..#lessfilecontents..")")
  259.                             sleep(1.2)
  260.                         else
  261.                             table.insert(lineHistory)
  262.                             scrollY = lineno-1 or 1
  263.                         end
  264.                     end
  265.                     draw()
  266.                 end
  267.                 if var1 == 200 or var1 == 21 then --up arrow or 'y'
  268.                     if scrollY > 0 then
  269.                         scrollY = scrollY - 1
  270.                     end
  271.                 elseif var1 == 208 then --down arrow
  272.                     if scrollY < #lessfilecontents-1 then
  273.                         scrollY = scrollY + 1
  274.                     end
  275.                 elseif var1 == 21 then --'u'
  276.                     if scrollY-math.floor(scr_y/2) > 0 then
  277.                         scrollY = scrollY - math.floor(scr_y/2)
  278.                     end
  279.                 elseif var1 == 203 then --left arrow
  280.                     if scrollX > 0 then
  281.                         scrollX = scrollX - 1
  282.                     end
  283.                 elseif var1 == 205 then --right arrow
  284.                     if scrollX < longestStringLen then
  285.                         scrollX = scrollX + 1
  286.                     end
  287.                 end
  288.                 if var1 == 45 or var1 == 16 then --'X' or 'Q' to quit
  289.                     sleep(0)
  290.                     break
  291.                 end
  292.                 if var1 == 29 then --left ctrl
  293.                     alternateScroll = true
  294.                 end
  295.                 if var1 == 199 or var1 == "g" then --home
  296.                     if alternateScroll then
  297.                         scrollX = 0
  298.                     else
  299.                         scrollY = 0
  300.                     end
  301.                 end
  302.                 if var1 == 207 or var1 == "G" then --end
  303.                     if alternateScroll then
  304.                         scrollX = longestStringLen
  305.                     else
  306.                         scrollY = #lessfilecontents-scr_y+1
  307.                     end
  308.                 end
  309.                 if var1 == 201 or var1 == "b" then --page up
  310.                     if not alternateScroll then
  311.                         scrollY = scrollY - scr_y
  312.                         if scrollY < 0 then scrollY = 0 end
  313.                     else
  314.                         scrollX = scrollX - scr_x
  315.                         if scrollX < 0 then scrollX = 0 end
  316.                     end
  317.                 end
  318.                 if var1 == 209 or var1 == "f" then --page down
  319.                     if not alternateScroll then
  320.                         scrollY = scrollY + scr_y
  321.                         if scrollY > #lessfilecontents-1 then scrollY = #lessfilecontents-1 end
  322.                     else
  323.                         scrollX = scrollX + scr_x
  324.                         if scrollX > longestStringLen then scrollX = longestStringLen end
  325.                     end
  326.                 end
  327.                 if var1 == "e" and not isGuest then --edit current paste
  328.                     term.setCursorPos(1,1)
  329.                     term.setTextColor(colors.white)
  330.                     term.setBackgroundColor(colors.black)
  331.                     write("Not working as of yet!")
  332.                     sleep(0.8)
  333.                     --[[
  334.                     shell.run("edit",lessfile)
  335.                     local file = fs.open(lessfile,"r")
  336.                     local contents = file.readAll()
  337.                     file.close()
  338.                     local status = pb.create(contents,userkey,selectedFileName,nil,0,"N")
  339.                     --]]
  340.                     draw()
  341.                 elseif var1 == "d" then --download to file
  342.                     term.setCursorPos(1,2)
  343.                     term.setBackgroundColor(colors.black)
  344.                     term.setTextColor(colors.white)
  345.                     term.clearLine()
  346.                     write("DL to: /")
  347.                     sleep(0)
  348.                     local dlpath = fs.combine("",read())
  349.                     if fs.exists(fs.getDir(dlpath)) and not fs.exists(dlpath) then
  350.                         fs.copy(lessfile, dlpath)
  351.                         term.setCursorPos(1,2)
  352.                         term.clearLine()
  353.                         write("Done!")
  354.                         sleep(0.5)
  355.                     else
  356.                         term.setCursorPos(1,2)
  357.                         term.clearLine()
  358.                         write("Bad path!")
  359.                         sleep(0.5)
  360.                     end
  361.                     draw()
  362.                 end
  363.                 if var1 == "r" then --remove file
  364.                     term.setCursorPos(1,2)
  365.                     term.setBackgroundColor(colors.black)
  366.                     term.setTextColor(colors.white)
  367.                     term.clearLine()
  368.                     write("Y-you sure?? [Y,N]")
  369.                     repeat
  370.                         event, key = os.pullEvent("char")
  371.                         key = string.lower(key)
  372.                     until string.find("yn",key)
  373.                     if key == "y" then
  374.                         pb.delete(userkey,selectedFileCode)
  375.                         return
  376.                     else
  377.                         term.setCursorPos(1,2)
  378.                         term.setBackgroundColor(colors.black)
  379.                         term.setTextColor(colors.white)
  380.                         term.clearLine()
  381.                         write("Phew!")
  382.                         sleep(0.5)
  383.                         draw()
  384.                     end
  385.                 end
  386.             elseif event == "mouse_scroll" then
  387.                 if not alternateScroll then
  388.                     if var1 == -1 then
  389.                         if scrollY > 0 then
  390.                             scrollY = scrollY - 1
  391.                         end
  392.                     elseif var1 == 1 then
  393.                         if scrollY < #lessfilecontents-1 then
  394.                             scrollY = scrollY + 1
  395.                         end
  396.                     end
  397.                 else
  398.                     if var1 == -1 then
  399.                         if scrollX > 0 then
  400.                             scrollX = scrollX - 1
  401.                         end
  402.                     elseif var1 == 1 then
  403.                         if scrollX < longestStringLen then
  404.                             scrollX = scrollX + 1
  405.                         end
  406.                     end
  407.                 end
  408.             elseif event == "key_up" then
  409.                 if var1 == 29 then --left ctrl
  410.                     alternateScroll = false
  411.                 end
  412.             end
  413.             if scrollX ~= oldScrollX or scrollY ~= oldScrollY then --Yay! Flicker reduction!
  414.                 draw()
  415.             end
  416.         end
  417.     end
  418.     return allInput()
  419. end
  420.  
  421.  
  422.  
  423. local fadeIn = function()
  424.     term.setBackgroundColor(colors.black)
  425.     term.clear()
  426.     sleep(0)
  427.     term.setBackgroundColor(colors.gray)
  428.     term.clear()
  429.     sleep(0)
  430.     term.setBackgroundColor(colors.lightGray)
  431.     term.clear()
  432.     sleep(0)
  433.     term.setBackgroundColor(colors.white)
  434.     term.clear()
  435.     term.setTextColor(colors.black)
  436. end
  437.  
  438. local fadeOut = function()
  439.     term.setBackgroundColor(colors.white)
  440.     term.clear()
  441.     sleep(0)
  442.     term.setBackgroundColor(colors.lightGray)
  443.     term.clear()
  444.     sleep(0)
  445.     term.setBackgroundColor(colors.gray)
  446.     term.clear()
  447.     sleep(0)
  448.     term.setBackgroundColor(colors.black)
  449.     term.clear()
  450.     term.setTextColor(colors.white)
  451. end
  452.  
  453. local cwrite = function(txt)
  454.     local posX, posY = term.getCursorPos()
  455.     local scr_x, scr_y = term.getSize()
  456.     term.setCursorPos(math.ceil(scr_x/2)-(#txt/2)+1,posY)
  457.     write(txt)
  458. end
  459.  
  460. local cprint = function(txt)
  461.     cwrite(txt)
  462.     write("\n")
  463. end
  464.  
  465. local isGuest = false
  466. userkey = nil
  467. local status
  468.  
  469. local loginPrompt = function()
  470.     if username and password then
  471.         status, userkey = pcall(pb.login,username,password)
  472.         if status then
  473.             userkey = tostring(userkey)
  474.         end
  475.         updatePasteList(not status)
  476.         return status
  477.     else
  478.         isGuest = false
  479.         fadeIn()
  480.         term.setCursorPos(1,2)
  481.         cprint("CC Pastebin Client")
  482.         cprint("[BETA]")
  483.         term.setCursorPos(1,6)
  484.         repeat
  485.             cprint("Enter username:")
  486.             cprint("(do blank for guest)")
  487.             term.setBackgroundColor(colors.lightGray)
  488.             term.clearLine()
  489.             sleep(0)
  490.             username = read()
  491.             if username == "" then
  492.                 isGuest = true
  493.             else
  494.                 term.setBackgroundColor(colors.white)
  495.                 cprint("Enter password:")
  496.                 term.setBackgroundColor(colors.lightGray)
  497.                 term.clearLine()
  498.                 sleep(0)
  499.                 password = read("*")
  500.                 term.setBackgroundColor(colors.white)
  501.                 status, userkey = pcall(pb.login,username,password)
  502.                 if status then
  503.                     userkey = tostring(userkey)
  504.                 end
  505.                 if userkey == "Bad API request, invalid login" then
  506.                     cprint("Invalid credentials!")
  507.                 else
  508.                     isGuest = false
  509.                     if doSave then
  510.                         local file = fs.open(savepath,"w")
  511.                         file.write(username.."\n"..password)
  512.                         file.close()
  513.                     end
  514.                 end
  515.             end
  516.         until (userkey ~= "Bad API request, invalid login" and status) or isGuest == true
  517.         updatePasteList(isGuest)
  518.     end
  519. end
  520.  
  521. local renderThingie = function(tbl,txtcolor,bgcolor)
  522.     local oldbg,oldtxt = term.getBackgroundColor(), term.getTextColor()
  523.     for a = 1, #tbl do
  524.         term.setTextColor(txtcolor)
  525.         term.setBackgroundColor(bgcolor)
  526.         term.clearLine()
  527.         print(tbl[a])
  528.     end
  529.     term.setTextColor(oldtxt)
  530.     term.setBackgroundColor(oldbg)
  531. end
  532.  
  533. local selectedFileName
  534.  
  535. local displayData = function(menuNumber)
  536.     term.clear()
  537.     term.setCursorPos(1,1)
  538.     print("Viewing...")
  539.     selectedFileName = menuCodes[menuNumber][2]
  540.     selectedFileCode = menuCodes[menuNumber][1]
  541.     less("-u", "http://pastebin.com/raw/"..menuCodes[menuNumber][1])
  542.     selectedFileName = nil
  543.     selectedFileCode = nil
  544.     term.setBackgroundColor(colors.gray)
  545.     term.setTextColor(colors.white)
  546.     pageNo = 1
  547.     updatePasteList(isGuest)
  548. end
  549.  
  550. local trend = false --show trendy pastes or your own
  551. local pageNo = 1
  552. local pastes
  553.  
  554. updatePasteList = function(trendy)
  555.     if trendy then
  556.         pastes = pb.trending()
  557.     else
  558.         pastes = pb.list(userkey,1024)
  559.     end
  560.     local scr_x, scr_y = term.getSize()
  561.     term.setCursorPos(1,1)
  562.     menuPages = {}
  563.     buffer = {}
  564.     rawData = {}
  565.     for a = 1, #pastes do
  566.         table.insert(rawData,{string.sub(pastes[a].title,1,scr_x),pastes[a].format_long,pastes[a].size.." bytes",pastes[a].hits.." hits"})
  567.     end
  568.     for a = 1, #rawData do
  569.         table.insert(buffer,rawData[a])
  570.         if a % math.floor((scr_y/5)-0.1) == 0 then
  571.             table.insert(menuPages,buffer)
  572.             buffer = {}
  573.         end
  574.     end
  575.     if #buffer > 0 then
  576.         table.insert(menuPages,buffer)
  577.         buffer = {}
  578.     end
  579.     return pastes
  580. end
  581.  
  582. local displayPastes = function()
  583.     updatePasteList(isGuest)
  584.     while true do
  585.         term.setBackgroundColor(colors.gray)
  586.         term.setTextColor(colors.white)
  587.         term.clear()
  588.         term.setCursorPos(1,1)
  589.         menuCodes = {}
  590.         cprint(tostring(pageNo).."/"..#menuPages)
  591.         for a = 1, #menuPages[pageNo] do
  592.             local pgob = pastes[(#menuPages[pageNo]*(pageNo-1))+a]
  593.             table.insert(menuCodes,{pgob.key,pgob.title})
  594.             renderThingie({"["..a.."]",table.unpack(menuPages[pageNo][a])},colors.black,colors.lightGray)
  595.             if a ~= #menuPages[pageNo] then write("\n") end
  596.         end
  597.         local scr_x, scr_y = term.getSize()
  598.         term.setCursorPos(1,scr_y)
  599.         if isGuest then
  600.             term.setBackgroundColor(colors.white)
  601.             term.setTextColor(colors.black)
  602.         else
  603.             term.setBackgroundColor(colors.gray)
  604.             term.setTextColor(colors.white)
  605.         end
  606.         local msg = "(T)rend,(R)fr,(N)ew,(F)ind"
  607.         term.clearLine()
  608.         cwrite(msg)
  609.         local event, key
  610.         repeat
  611.             event, key, x, y = os.pullEvent()
  612.         until event == "key" or event == "char"
  613.         if event == "key" then
  614.             key = keys.getName(key)
  615.             if key == "t" and userkey then
  616.                 isGuest = not isGuest
  617.                 pageNo = 1
  618.                 updatePasteList(isGuest)
  619.             end
  620.             if key == "f" then
  621.                 term.setCursorPos(1,1)
  622.                 term.setBackgroundColor(colors.black)
  623.                 term.setTextColor(colors.white)
  624.                 term.clearLine()
  625.                 write("Enter paste ID: ")
  626.                 sleep(0)
  627.                 local pbid = read()
  628.                 term.setCursorPos(1,1)
  629.                 term.clearLine()
  630.                 less("-u","http://pastebin.com/raw/"..pbid)
  631.             end
  632.             if key == "n" then
  633.                 term.setCursorPos(1,1)
  634.                 term.setBackgroundColor(colors.black)
  635.                 term.setTextColor(colors.white)
  636.                 term.clearLine()
  637.                 write("NEW: ")
  638.                 sleep(0)
  639.                 local newname = read()
  640.                 if newname ~= "" then
  641.                     term.setCursorPos(1,1)
  642.                     term.setBackgroundColor(colors.black)
  643.                     term.setTextColor(colors.white)
  644.                     term.clearLine()
  645.                     write("Private? [Y,N]")
  646.                     repeat
  647.                         event, key = os.pullEvent("char")
  648.                         key = string.lower(key)
  649.                     until string.find("yn",key)
  650.                     local isPrivate = 0
  651.                     if key == "y" then
  652.                         isPrivate = 1
  653.                     else
  654.                         isPrivate = 0
  655.                     end
  656.                     if fs.exists(".temp") then fs.delete(".temp") end
  657.                     shell.run("edit","/.temp")
  658.                     local file = fs.open("/.temp","r")
  659.                     local contents = file.readAll()
  660.                     file.close()
  661.                     pb.create(contents,userkey,newname,nil,isPrivate,"N")
  662.                     updatePasteList(isGuest)
  663.                 end
  664.             end
  665.             if key == "r" or key == "f5" then --refresh pastes
  666.                 pageNo = 1
  667.                 updatePasteList(isGuest)
  668.             end
  669.             if key == "left" then
  670.                 if pageNo > 1 then
  671.                     pageNo = pageNo - 1
  672.                 else
  673.                     pageNo = #menuPages
  674.                 end
  675.             end
  676.             if key == "right" then
  677.                 if pageNo < #menuPages then
  678.                     pageNo = pageNo + 1
  679.                 else
  680.                     pageNo = 1
  681.                 end
  682.             end
  683.             if key == "q" then
  684.                 term.setBackgroundColor(colors.black)
  685.                 term.setTextColor(colors.white)
  686.                 term.clear()
  687.                 term.setCursorPos(1,1)
  688.                 sleep(0)
  689.                 return
  690.             end
  691.         elseif event == "char" then
  692.             if tonumber(key) then
  693.                 if #menuPages[pageNo] >= tonumber(key) then
  694.                     displayData(tonumber(key))
  695.                 end
  696.             end
  697.         end
  698.     end
  699. end
  700. if (fs.exists(savepath)) and (not fs.isDir(savepath)) then
  701.     local file = fs.open(savepath,"r")
  702.     username = file.readLine()
  703.     password = file.readLine()
  704.     file.close()
  705.     status, userkey = pcall(pb.login,u,p)
  706.     if not status then
  707.         loginPrompt()
  708.     else
  709.         updatePasteList(true)
  710.     end
  711. else
  712.     loginPrompt()
  713. end
  714. displayPastes()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement