Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- FreshApi (1.1b)
- function centerText (text)
- local w, h = term.getSize()
- term.setCursorPos(math.floor(w / 2 - text:len() / 2 + .5), math.floor(h / 2 + .5))
- write(text)
- end
- function centerPrint (text)
- local textLen = string.len(text)
- local screenW,_ = term.getSize()
- local xCoords = tonumber(math.ceil((screenW / 2) - (textLen / 2)))
- local _,termY = term.getCursorPos()
- term.setCursorPos(xCoords,termY)
- print(text)
- return xCoords
- end
- function drawLine ()
- term.write("---------------------------------------------------")
- end
- function line ()
- return "---------------------------------------------------"
- end
- function slowCenterPrint (text, time)
- local textLen = string.len(text)
- local screenW,_ = term.getSize()
- local xCoords = tonumber(math.ceil((screenW / 2) - (textLen / 2)))
- local _,termY = term.getCursorPos()
- term.setCursorPos(xCoords,termY)
- textutils.slowWrite(text, time)
- return xCoords
- end
- function drawMenu(tab, t,d)
- wybor = 1
- w,h = term.getSize()
- scr = 0
- while true do
- c,v = term.getSize()
- if #tab > 10 then
- tabL = 10
- else
- tabL = #tab
- end
- a = 0
- for i=1,tabL do
- a = a + 1
- if t == nil and d == nil then
- term.setCursorPos(1, a + math.floor(h / 2 - .5) - #tab / 2 + .5)
- else
- term.setCursorPos(t, d + a - 1)
- end
- term.clearLine()
- if a+scr == wybor then
- if t == nil and d == nil then
- centerPrint("[".. tab[i+scr].. "]")
- else
- write("[".. tostring(tab[i+scr]).. "]")
- end
- else
- if t == nil and d == nil then
- centerPrint(tab[i+scr])
- else
- write(tostring(tab[i+scr]))
- end
- end
- end
- event, key = os.pullEvent("key")
- if key == 200 and wybor>1 then
- if wybor > 10 then
- scr = scr - 1
- end
- wybor = wybor - 1
- elseif key == 208 and wybor<#tab then
- wybor = wybor + 1
- if wybor > 10 then
- scr = scr + 1
- end
- elseif key == 28 then
- term.clear()
- return wybor
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement