Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local x,y = term.getSize()
- local function cPrint( txt ) --Version 2.0 of cPrint
- local function printC( text )
- x2,y2 = term.getCursorPos()
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
- write(text.. "\n")
- end
- if type(txt) == "string" then
- printC( txt )
- elseif type(txt) == "table" then
- for i=1,#txt do
- printC( txt[i] )
- end
- end
- end
- function drawTop()
- term.setBackgroundColour( colors.white )
- term.clear()
- term.setCursorPos(1,1)
- term.setBackgroundColour( colors.black )
- term.clearLine()
- term.setTextColour( colors.white )
- print("TurtleBrowse v1.0 - CCFan11")
- print( string.rep( "=", x ) )
- end
- function _( xz )
- term.setTextColour( colors.orange )
- if xz then
- write("|")
- else
- print("|")
- end
- term.setTextColour( colors.black )
- end
- drawTop()
- term.setBackgroundColour( colors.orange )
- term.clearLine()
- print()
- term.clearLine()
- local xx, yy = term.getCursorPos()
- term.clearLine()
- cPrint("TurtleBrowse")
- term.clearLine()
- cPrint("Your first stop for ComputerCraft scripts.")
- term.clearLine()
- print()
- term.setBackgroundColour( colors.gray )
- term.clearLine()
- print(" TurtleScripts.com")
- print()
- term.setBackgroundColour( colors.white )
- term.setTextColour( colors.black )
- print("Welcome to TurtleBrowse, TurtleBrowse is a program created by CCFan11 that allows users to easily browse TurtleScripts with a nice and user friendly GUI.")
- local selection = 1
- while true do
- term.setCursorPos(1,y-3)
- term.setTextColour( colors.orange )
- print("Menu------+")
- term.setTextColour( colors.black )
- if selection == 1 then
- write("[>] Browse") _()
- else
- write("[ ] Browse") _()
- end
- if selection == 2 then
- write("[>] Upload") _()
- else
- write("[ ] Upload") _()
- end
- if selection == 3 then
- write("[>] Exit ") _( true )
- else
- write("[ ] Exit ") _( true )
- end
- local event, key = os.pullEvent("key")
- if key == keys.up then
- if selection ~= 1 then selection = selection-1 end
- elseif key == keys.down then
- if selection ~= 3 then selection = selection+1 end
- elseif key == keys.enter then
- if selection == 3 then
- term.setBackgroundColour( colors.black )
- term.clear()
- term.setCursorPos(1,1)
- error()
- end
- break
- end
- end
- drawTop()
- term.setTextColour( colors.black )
- if selection == 2 then
- term.setTextColour( colors.red )
- print("Coming soon...")
- error()
- else
- term.setBackgroundColour( colors.white )
- print("Downloader\n")
- write("Enter Post ID: ")
- local sID = read()
- print("Retrieving Post...")
- local response = http.get("http://api.turtlescripts.com/getFileRAW/" ..sID)
- if response ~= nil then
- local sCode = response.readAll()
- local sInfo = http.get("http://api.turtlescripts.com/getProject/" ..sID).readAll()
- local tLines = {}
- local currentLine = 1
- local currentDownload = 0
- function redrawLines()
- term.clear()
- term.setCursorPos(1,1)
- for i=1,#tLines do--currentLine,y-3 do
- if i == 2 then
- term.setTextColour( colors.green )
- print( tLines[i] )
- elseif i == 3 then
- term.setTextColour( colors.blue )
- local _, xzvc = term.getCursorPos()
- currentDownload = xzvc - currentLine
- print( tLines[i] )
- else
- print()
- local start = string.find(sInfo, "\"postName\":\"")
- local enddd = string.find(sInfo, "\"", start+13)
- term.setTextColour( colors.gray )
- print( string.sub( sInfo, start+12, enddd-1 ) )
- print()
- term.setTextColour( colors.green )
- print( "Description" )
- local start = string.find(sInfo, "\"postDescription\":\"")
- local enddd = string.find(sInfo, "\"", start+20)
- term.setTextColour( colors.red )
- print( string.sub( sInfo, start+19, enddd-1 ) )
- print()
- end
- end
- term.scroll( currentLine )
- term.setCursorPos(1,y-1)
- term.setTextColour( colors.red )
- term.setBackgroundColour( colors.black )
- print("------------+")
- write("Click to esc|")
- term.setBackgroundColour( colors.white )
- end
- function load()
- tLines[1] = "EVERYTAHANG!!!"
- tLines[2] = "Download"
- tLines[3] = "Click here to download"
- end
- load()
- redrawLines()
- while true do
- local event, key, xz, yz = os.pullEvent()
- if event == "key" then
- if key == keys.up and currentLine ~= 1 then
- currentLine = currentLine -1
- redrawLines()
- elseif key == keys.down and currentLine ~= #tLines then
- currentLine = currentLine +1
- redrawLines()
- end
- elseif event == "mouse_click" and key == 1 then
- if xz < 23 and yz == currentDownload then
- term.setTextColour( colors.blue )
- term.setCursorPos(1,currentDownload)
- term.clearLine()
- write("Downloading...")
- sleep(1)
- term.setTextColour( colors.blue )
- term.setCursorPos(1,currentDownload)
- fs.delete( sID )
- file = fs.open( sID, "w" )
- file.write( sCode )
- file.close()
- write("Done! Saved as " ..sID )
- elseif xz < 34 and yz == y then
- shell.run( shell.getRunningProgram() )
- error()
- end
- end
- end
- else
- print("Invalid Post ID. (Example: gjdgxt)")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement