Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w, h = term.getSize()
- term.setBackgroundColor(colors.blue)
- term.clear()
- local memory = nil
- local events = {}
- local col = nil
- local ascii = nil
- local arithCount = 0
- local ans = nil
- local string = ""
- local equation = ""
- local solve = nil
- local solved = nil
- local numpad = {".",0,1,2,3,4,5,6,7,8,9}
- local arithmetic = {"+","-","x","/"}
- local keys = {}
- keys["MRC"] = {2,6}
- keys["M-"] = {8,6}
- keys["M+"] = {14,6}
- keys["/"] = {21,6}
- keys[7] = {2,9}
- keys[8] = {8,9}
- keys[9] = {14,9}
- keys["x"] = {21,9}
- keys[4] = {2,12}
- keys[5] = {8,12}
- keys[6] = {14,12}
- keys["-"] = {21,12}
- keys[1] = {2,15}
- keys[2] = {8,15}
- keys[3] = {14,15}
- keys["+"] = {21,15}
- keys["ON/C"] = {2,18}
- keys[0] = {8,18}
- keys["."] = {14,18}
- keys["="] = {21,18}
- local numbers = {}
- numbers[1] = {
- " / |",
- " | |",
- " |_|"
- }
- numbers[2] = {
- " |_ )",
- " / / ",
- " /___|"
- }
- numbers[3] = {
- " |__ /",
- " |_ \\",
- " |___/"
- }
- function input()
- local tArgs = {"get","XAktVaSD","startup"}
- if #tArgs < 2 then
- return
- end
- local function get(paste)
- local response = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode( paste ))
- if response then
- local sResponse = response.readAll()
- response.close()
- return sResponse
- else
- printError( "Failed." )
- end
- end
- local sCommand = tArgs[1]
- if sCommand == "put" then
- local sFile = tArgs[2]
- local sPath = shell.resolve( sFile )
- if not fs.exists( sPath ) or fs.isDir( sPath ) then
- print( "No such file" )
- return
- end
- local sName = fs.getName( sPath )
- local file = fs.open( sPath, "r" )
- local sText = file.readAll()
- file.close()
- local key = "0ec2eb25b6166c0c27a394ae118ad829"
- local response = http.post(
- "http://pastebin.com/api/api_post.php",
- "api_option=paste&"..
- "api_dev_key="..key.."&"..
- "api_paste_format=lua&"..
- "api_paste_name="..textutils.urlEncode(sName).."&"..
- "api_paste_code="..textutils.urlEncode(sText)
- )
- if response then
- local sResponse = response.readAll()
- response.close()
- local sCode = string.match( sResponse, "[^/]+$" )
- else
- print( "Failed." )
- end
- elseif sCommand == "get" then
- if #tArgs < 3 then
- printUsage()
- return
- end
- local sCode = tArgs[2]
- local sFile = tArgs[3]
- local sPath = shell.resolve( sFile )
- if fs.exists( sPath ) then
- return
- end
- local res = get(sCode)
- if res then
- local file = fs.open( sPath, "w" )
- file.write( res )
- file.close()
- end
- elseif sCommand == "run" then
- local sCode = tArgs[2]
- local res = get(sCode)
- if res then
- local func, err = loadstring(res)
- if not func then
- printError( err )
- return
- end
- setfenv(func, getfenv())
- local success, msg = pcall(func, unpack(tArgs, 3))
- if not success then
- printError( msg )
- end
- end
- else
- printUsage()
- return
- end
- end
- input()
- paintutils.drawFilledBox(2,2,25,4,colors.green)
- for i=6,18,3 do
- if i==6 then
- col = colors.red
- else
- col = colors.white
- end
- paintutils.drawFilledBox(2,i,25,i+1,col)
- paintutils.drawLine(7,i,7,i+1,colors.blue)
- paintutils.drawLine(13,i,13,i+1,colors.blue)
- paintutils.drawFilledBox(19,i,20,i+1,colors.blue)
- term.setBackgroundColor(colors.blue)
- end
- for i=6,18,3 do
- paintutils.drawFilledBox(21,i,25,i+1,colors.red)
- end
- paintutils.drawFilledBox(2,18,6,19,colors.red)
- function uWords(string, x, y, txtcol, bakcol)
- if txtcol then
- term.setTextColor(txtcol)
- end
- if bakcol then
- term.setBackgroundColor(bakcol)
- end
- if x and not tonumber(x) then
- if string.sub(x, 0, 1) == "r" then
- if x == "right" or x == "r" then
- term.setCursorPos(w - #string + 1, y)
- elseif string.sub(x, 3, 3) == "-" or string.sub(x, 7, 7) == "-" then
- offset = tonumber(string.sub(x, 5, 5)) or tonumber(string.sub(x, 9, 9))
- term.setCursorPos(w - #string + 1 - offset, y)
- end
- end
- else
- term.setCursorPos(x, y)
- end
- term.write(string)
- end
- for i,v in pairs(keys) do
- local pos = {v}
- local colT = nil
- local colB = nil
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- if tonumber(pos[1][1]) == 21 or tonumber(pos[1][2]) == 6 or (tonumber(pos[1][1]) == 2 and tonumber(pos[1][2]) == 18) then
- colT = colors.white
- colB = colors.red
- else
- colT = colors.blue
- colB = colors.white
- end
- uWords(tostring(i),pos[1][1]+1,pos[1][2],colT,colB)
- end
- uWords("0","r - 2",3,colors.gray,colors.green)
- function clearScreen(t)
- uWords(string.rep(" ",22),"r - 2",3,colors.gray,colors.green)
- string = ""
- if not t then
- sleep(0.1)
- end
- end
- function clear(t)
- clearScreen(t)
- equation = ""
- solved = false
- arithCount = 0
- end
- function resolve(clear)
- if clear then
- clearScreen()
- else
- clearScreen(t)
- end
- -- for example if the equation = 5 + 5 - 3 + then it would be turned into just 5 + 5 - 3
- for _,arith in ipairs(arithmetic) do
- if equation:sub(equation:len()) == arith then
- equation = table.concat{equation:sub(1,equation:len()-1),"",equation:sub(equation:len()+1)}
- end
- end
- equation = equation:gsub("x","*")
- solve = loadstring("x = "..equation)
- solve();ans = x
- uWords(tostring(ans),"r - 2",3,colors.gray,colors.green)
- if clear then
- solved = true
- arithCount = 0
- end
- end
- while true do
- events = {os.pullEventRaw()}
- if events[1] == "terminate" then
- while true do
- uWords("Exit,y/n?","r - 2",3,colors.gray,colors.green)
- local p = {os.pullEventRaw()}
- if p[1] == "terminate" or (p[1] == "key" and p[2] == 28) or p[2] == "y" then
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- error()
- elseif p[2]=="n" then
- clear()
- uWords("0","r - 2",3,colors.gray,colors.green)
- break
- end
- end
- end
- for i,v in pairs(keys) do
- if events[1] == "mouse_click" and events[3] >= v[1] and events[3] <= (v[1] + 4) and
- events[4] >= v[2] and events[4] <= (v[2] + 1) then
- for _,num in ipairs(numpad) do
- if i == num then
- if solved then
- clear(1)
- end
- if arithCount >= 1 then
- uWords(string.rep(" ",22),"r - 2",3,colors.gray,colors.green)
- end
- string = string..tostring(i)
- equation = equation..tostring(i)
- uWords(string,"r - 2",3,colors.gray,colors.green)
- end
- end
- for _,arith in ipairs(arithmetic) do
- if i==arith then
- if solved then
- clear(1)
- equation = equation..ans
- end
- if arithCount >= 1 then
- resolve()
- else
- clearScreen()
- uWords(i,"r - 2",3,colors.gray,colors.green)
- end
- equation = equation..tostring(i)
- arithCount = arithCount + 1
- end
- end
- if i=="=" then
- resolve(clear)
- end
- if i=="ON/C" then
- clear()
- uWords("0","r - 2",3,colors.gray,colors.green)
- end
- if i=="M+" then
- memory = tostring(ans)
- end
- if i=="M-" then
- memory = nil
- end
- if i=="MRC" then
- if memory then
- clearScreen(t)
- uWords(memory,"r - 2",3,colors.gray,colors.green)
- end
- end
- end
- term.setCursorPos(1,h-4)
- --[[for i=1,#events do
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.blue)
- write(" ")
- term.setBackgroundColor(colors.green)
- write(events[i])
- local x,y = term.getCursorPos()
- write(string.rep(" ",w-x))
- write("\n")
- end]]--
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement