Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sides()
- return "top", "bottom", "left", "right", "front", "back"
- end
- function drawCenteredX(str, y, bgCol, fgCol)
- if fgCol ~= nil then
- term.setTextColor(fgCol)
- end
- term.setBackgroundColor(bgCol)
- local temp = term.getBackgroundColor()
- local length = (w - string.len(str)) / 2
- term.setCursorPos(length, y)
- print(str)
- term.setBackgroundColor(temp)
- end
- function validChar(key)
- if key >= 2 and key <= 13 then
- elseif key >= 16 and key <= 27 then
- return 1
- elseif key >= 30 and key <= 41 then
- return 1
- elseif key >= 43 and key <=53 then
- return 1
- elseif key >= 71 and key <= 83 then
- return 1
- elseif key == 181 or key == 55 then
- return 1
- else
- return 0
- end
- end
- function readCentered(pref, rep)
- term.setBackgroundColor(bgCol)
- term.setTextColor(tbxCol)
- local cin = ""
- local strLen = nil
- local kTemp = nil
- term.setCursorPos((w - 1)/2, h/2)
- --draw prefix if not nil
- if pref ~= nil then
- write(pref)
- end
- while true do
- --super stylish cursor blink!
- term.setCursorBlink(true)
- --ask for keypress
- local key = {os.pullEvent()}
- if key[1] == "char" then
- if kTemp == true then
- --do nothing
- else
- --combine the keystrokes
- cin = cin .. key[2]
- --get length of the string for offset
- strLen = string.len(cin) + string.len(pref)
- --set new cursor position
- term.setCursorPos((w - strLen)/2, h/2)
- --actually draw the string
- if pref ~= nil then
- if rep == nil then
- write(pref .. cin)
- else
- local ciw = string.rep(rep, string.len(cin))
- write(pref .. ciw)
- end
- else
- if rep == nil then
- write(cin)
- else
- local ciw = string.rep(rep, string.len(cin))
- write(ciw)
- end
- end
- end
- elseif key[1] == 'key' then
- if validChar(key[2]) == 1 then
- elseif key[2] == 14 then
- --get length of string for offset
- strLen = string.len(cin)
- --get rid of last letter
- cin = string.sub(cin, 1, strLen - 1)
- if pref ~= nil then
- --get length of string for offset
- strLen = string.len(cin) + string.len(pref)
- else
- strLen = string.len(cin)
- end
- --set new cursor position
- term.setCursorPos((w - strLen)/2, h/2)
- term.clearLine()
- if pref ~= nil then
- if rep == nil then
- write(pref .. cin)
- else
- local ciw = string.rep(rep, string.len(cin))
- write(pref..ciw)
- end
- else
- if rep == nil then
- write(cin)
- else
- local ciw = string.rep(rep, string.len(cin))
- write(ciw)
- end
- end
- elseif key[2] == 28 then
- term.setCursorBlink(false)
- return cin
- end
- end
- end
- term.setCursorBlink(false)
- end
- function getY()
- local coords = {term.getCursorPos()}
- return coords[2]
- end
- function drawRect(x1, y1, x2, y2, bgCol)
- local i = 0
- local j = 0
- term.setCursorPos(x1, y1)
- local temp = term.getBackgroundColor()
- term.setBackgroundColor(bgCol)
- for i = y1, y2 do
- for j = x1, x2 do
- term.setCursorPos(j, i)
- write(' ')
- end
- end
- term.setBackgroundColor(temp)
- end
- function getCol(uname)
- os.loadAPI(usrPath .. uname .. "/settings")
- tb = settings.tbCol
- tbx = settings.tbxCol
- tx = settings.txCol
- bg = settings.bgCol
- stx = settings.stxCol
- os.unloadAPI(usrPath .. uname .. "/settings")
- return tb, tbx, tx, bg, stx
- end
- function drawTableCentered(t, bgCol, fgCol, lSel, uname)
- local i = 0
- local height = (h - #t) / 2
- local longest = 0
- tw = w / 2
- for i = 1, #t do
- len = string.len(t[i])
- if len > longest then
- longest = len
- end
- end
- drawRect(tw - (longest), height, tw + (longest), height + #t + 1, bgCol)
- for i = 1, #t do
- if i == lSel then
- local cols = {}
- if uname == nil then
- cols = {0, 0, 0, 0, stxCol}
- else
- cols = {getCol(uname)}
- end
- drawCenteredX(t[i], height + i, bgCol, cols[5])
- else
- drawCenteredX(t[i], height + i, bgCol, fgCol)
- end
- end
- end
- function getMenuKey()
- local event, param = os.pullEvent()
- if event == "key" then
- if param == 200 then
- return 1
- elseif param == 208 then
- return -1
- elseif param == 28 then
- return 2
- else
- return 0
- end
- elseif lockout ~= nil then
- if event == "timer" then
- return 3
- end
- else
- return 0
- end
- end
- function shutdown()
- os.unloadAPI(rootPath .. "params")
- local file = fs.open(rootPath .. "params", "r")
- local data = file.readAll()
- file.close()
- data = string.gsub(data, 'crash = 1', 'crash = 0')
- file = fs.open(rootPath .. "params", "w")
- file.write(data)
- file.close()
- os.shutdown()
- end
- function restart()
- os.unloadAPI(rootPath .. "params")
- local file = fs.open(rootPath .. "params", "r")
- local data = file.readAll()
- file.close()
- data = string.gsub(data, 'crash = 1', 'crash = 0')
- file = fs.open(rootPath .. "params", "w")
- file.write(data)
- file.close()
- os.reboot()
- end
- function resetCol()
- if term.isColor() then
- tbCol = params.tbColMain
- tbxCol = params.tbxColMain
- txCol = params.txColMain
- bgCol = params.bgCol
- stxCol = params.stxColMain
- else
- tbCol = params.tbMain
- tbxCol = params.tbMain
- txCol = params.txMain
- bgCol = params.bgCol
- stxCol = params.stxMain
- end
- return tbCol, tbxCol, txCol, bgCol, stxCol
- end
- function clear(uname)
- if uname ~= nil then
- cols = {getCol(uname)}
- term.setBackgroundColor(cols[4])
- else
- term.setBackgroundColor(bgCol)
- end
- term.clear()
- term.setCursorPos(1, 1)
- end
- function prgSort()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement