Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getVersion()
- return 1.006
- end
- --justifying functions
- function writeC(string,manX,manY,peripheral) --center justified
- if not peripheral then mon = term else mon = peripheral end
- local x,y=mon.getSize()
- local y = y/2
- local b = string.len(string)/2
- local x = (x/2)-b
- if manX==0 and manY==0 then
- mon.setCursorPos(x,y)
- mon.write(string)
- elseif manX==0 and manY~=0 then
- mon.setCursorPos(x,manY)
- mon.write(string)
- elseif manX~=0 and manY==0 then
- mon.setCursorPos(x+manX,y)
- mon.write(string)
- else error("Manual selection of X and Y is not necessary")
- end
- end
- function writeRT(string,manX,manY,peripheral) --right justified
- if not peripheral then mon = term else mon = peripheral end
- local x,y=mon.getSize()
- local b = string.len(string)
- local x = x-b
- if manX==0 and manY==0 then
- mon.setCursorPos(x,1)
- mon.write(string)
- elseif manX~=0 and manY~=0 then
- mon.setCursorPos(x+manX,manY)
- mon.write(string)
- elseif manX~=0 and manY==0 then
- mon.setCursorPos(x+manX,1)
- mon.write(string)
- elseif manX==0 and manY~=0 then
- mon.setCursorPos(x,manY)
- mon.write(string)
- else error("Manual selection of X and Y is not necessary")
- end
- end
- function fractionWrite(string,percentageX,percentageY,peripheral) --fraction justified. Usage would be as api.fractionWrite("This is the string",(1/3),(2/3))
- if not peripheral then mon = term else mon = peripheral end
- local x,y = mon.getSize()
- local b = string.len(string)
- local x = x*percentageX
- local y = y*percentageY
- if percentageX ~= 0 and percentageY ~= 0 then
- mon.setCursorPos(x,y)
- mon.write(string)
- else error("X or Y result must be greater than 0")
- end
- end
- --pattern functions
- function writeV(string,wX,wY,peripheral) --will write the string in a vertical line for each character.
- if not peripheral then mon = term else mon = peripheral end
- local function separate(input) --Good for making on screen tables.
- local chars = {}
- for x=1,string.len(input) do
- table.insert(chars,string.sub(input,x,x))
- end
- return chars
- end
- local sepString = separate(string)
- local pY = wY - 1
- local tX,tY = mon.getSize()
- term.setCursorPos(wX,wY)
- if wX ~= nil and wX ~= 0 then
- if wY ~= nil and wY ~= 0 then
- for i = 1,#sepString do
- if pY<=tY then
- mon.setCursorPos(wX,pY+1)
- mon.write(sepString[i])
- elseif pY>tY then
- mon.setCursorPos(wX,(pY-i)+1)
- mon.write(sepString[i])
- end
- end
- else error("Y coordinate cannot be nil or 0")
- end
- else error("X coordinate cannot be nil or 0")
- end
- end
- --clearing functions
- function clear(x,y,peripheral) --will clear the screen, and return to the specified x,y position
- if not peripheral then mon = term else mon = peripheral end
- mon.clear()
- mon.setCursorPos(x,y)
- end
- function clearLine(x,y,peripheral) --will clear the specified line.
- if not peripheral then mon = term else mon = peripheral end
- local tX,tY = term.getCursorPos()
- mon.setCursorPos(x,y)
- mon.clearLine()
- mon.setCursorPos(tX,tY)
- end
- -- limit read function
- function limitRead(limX, rChar)
- term.setCursorBlink(true)
- local origX, origY = term.getCursorPos()
- local returnString = ""
- while true do
- local xPos, yPos = term.getCursorPos()
- local event, p1, p2 = os.pullEvent()
- if event == "char" then
- returnString = returnString..p1
- if not rChar then
- if not limX then
- write(p1)
- else
- if string.len(returnString) >= limX then
- term.setCursorPos(origX, origY)
- write(string.sub(returnString, (string.len(returnString)-limX)+1))
- elseif string.len(returnString) < limX then
- write(p1)
- end
- end
- else
- if not limX then
- write(rChar)
- else
- if string.len(returnString) >= limX then
- term.setCursorPos(origX, origY)
- write(string.rep(rChar, limX))
- elseif string.len(returnString) < limX then
- write(rChar)
- end
- end
- end
- elseif event == "key" and p1 == 14 then --backspace
- returnString = string.sub(returnString, 1, (string.len(returnString))-1)
- term.setCursorPos(xPos-1,yPos)
- write(" ")
- term.setCursorPos(origX, origY)
- if string.len(returnString) >= limX then
- if not rChar then
- write(string.sub(returnString, (string.len(returnString)-limX)+1))
- else
- write(string.rep(rChar,limX))
- end
- else
- if not rChar then
- write(returnString)
- else
- write(string.rep(rChar, string.len(returnString)))
- end
- end
- elseif event == "key" and p1 == 28 then --enter
- break
- end
- end
- term.setCursorBlink(false)
- return returnString
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement