Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function xPrint(str, x, y)
- term.setCursorPos(x, y)
- term.write(str)
- end
- function printCentered(str, y)
- term.setCursorPos(w/2 - #str/2 + 1, y)
- term.write(str)
- end
- function printRight(str, y, xoffset)
- xoffset = xoffset or 0
- term.setCursorPos(w - xoffset - (#str - 1), y)
- term.write(str)
- end
- function printLeft(str, y, xoffset)
- xoffset = xoffset or 0
- term.setCursorPos(1 + xoffset, y)
- term.write(str)
- end
- function printSpacedOut(tab, y, leftEdge, rightEdge)
- rightEdge = rightEdge or w
- leftEdge = leftEdge or 0
- local letters = 0
- for i in pairs(tab) do
- letters = letters + #tab[i]
- end
- local freeSpace = (rightEdge-leftEdge)+1-letters
- term.setCursorPos(leftEdge, y)
- if (freeSpace/(#tab+1))%1 == 0 then
- for i in ipairs(tab) do
- term.write(string.rep(" ", freeSpace/(#tab+1))..tab[i])
- end
- elseif (freeSpace/(#tab))%2 == 0 then
- term.write(string.rep(" ", (freeSpace/#tab)/2))
- for i in ipairs(tab) do
- term.write(tab[i]..string.rep(" ", freeSpace/#tab))
- end
- elseif freeSpace == #tab-1 then
- term.write(tab[1])
- for i = 2, #tab do
- term.write(" "..tab[i])
- end
- else
- local spacing
- for i in ipairs(tab) do
- spacing = round(freeSpace/(#tab-i+2))
- term.write(string.rep(" ", spacing)..tab[i])
- freeSpace = freeSpace - spacing
- end
- end
- end
- --tab must be a list of strings with no string longer than space
- function printWrapped(tab, x, y, space, sep)
- local sep = sep or " "
- local spaceLeft = space
- local leftEdge = x
- for word = 1, #tab do
- if space < #tab[word] + #sep then
- return false
- elseif spaceLeft >= #tab[word]+#sep then
- xPrint(tab[word]..sep, x, y)
- spaceLeft = spaceLeft - (#tab[word]+#sep)
- x += #tab[word]+#sep
- else
- y++
- spaceLeft = space
- xPrint(tab[word]..sep, x, y)
- spaceLeft = spaceLeft - (#tab[word]+#sep)
- x = leftEdge + (#tab[word]+#sep)
- end
- end
- return y
- end
- function verticalLine(x, y1, y2, startSymbol, endSymbol)
- for i = y1, y2 do
- xPrint("|", x, i)
- end
- if startSymbol then
- xPrint(startSymbol, x, y1)
- xPrint((endSymbol or startSymbol), x, y2)
- end
- end
- function split(inputstr, sep)
- if inputstr == nil then
- return nil
- elseif sep == nil then
- sep = "%s"
- end
- local t, i = {}, 1
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- return t
- end
- function round(float, dez, half)
- half = half or 0.5
- dez = dez or 1
- return math.floor(float/dez+half)*dez
- end
- function close()
- term.clear()
- term.setCursorPos(1,1)
- if term.isColor() then
- term.setTextColor(colors.yellow)
- print(os.version())
- term.setTextColor(colors.white)
- else
- print(os.version())
- end
- term.setCursorPos(1, 2)
- end
Advertisement
Add Comment
Please, Sign In to add comment