Advertisement
Guest User

API 1.2.1

a guest
Jun 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- KekApi (1.2.1)
  2.  
  3.  
  4. function centerText (text)
  5.  local w, h = term.getSize()
  6.  term.setCursorPos(math.floor(w / 2 - text:len() / 2 + .5), math.floor(h / 2 + .5))
  7.  write(text)
  8. end
  9.  
  10. function centerPrint (text)
  11.  local textLen = string.len(text)
  12.  local screenW,_ = term.getSize()
  13.  local xCoords = tonumber(math.ceil((screenW / 2) - (textLen / 2)))
  14.  local _,termY = term.getCursorPos()
  15.  term.setCursorPos(xCoords,termY)
  16.  print(text)
  17.  return xCoords
  18. end
  19.  
  20. function writeLine ()
  21.  term.write("--------------------------------------------------")
  22. end
  23.  
  24. function slowCenterPrint (text, time)
  25.  local textLen = string.len(text)
  26.  local screenW,_ = term.getSize()
  27.  local xCoords = tonumber(math.ceil((screenW / 2) - (textLen / 2))) -- Da Ba Dee xD
  28.  local _,termY = term.getCursorPos()
  29.  term.setCursorPos(xCoords,termY)
  30.  textutils.slowWrite(text, time)
  31.  return xCoords
  32. end
  33.  
  34. function drawMenu(tab, t,d)
  35.  wybor = 1
  36.  back = term.getBackgroundColor()
  37.  w,h = term.getSize()
  38.  scr = 0
  39.  while true do
  40.   c,v = term.getSize()
  41.   if #tab > 10 then
  42.    tabL = 10
  43.   else
  44.    tabL = #tab
  45.   end
  46.   a = 0
  47.   for i=1,tabL do
  48.    a = a + 1
  49.    if t == nil and d == nil then
  50.     term.setCursorPos(1, a + math.floor(h / 2 - .5) - #tab / 2 + .5)
  51.    else
  52.     term.setCursorPos(t, d + a - 1)
  53.    end
  54.    term.clearLine()
  55.    if a+scr == wybor then
  56.     term.setBackgroundColor(colors.lightGray)
  57.    else
  58.     term.setBackgroundColor(back)
  59.    end
  60.    if t == nil and d == nil then
  61.     centerPrint(" ".. tab[i+scr].. " ")
  62.    else write(" ".. tostring(tab[i+scr]).. " ") end
  63.    term.setBackgroundColor(back)
  64.   end
  65.   event, key = os.pullEvent("key")
  66.   if key == keys.up and wybor>1 then
  67.    if wybor > 10 then
  68.     scr = scr - 1
  69.    end
  70.    wybor = wybor - 1
  71.   elseif key == keys.down and wybor<#tab then
  72.    wybor = wybor + 1
  73.    if wybor > 10 then
  74.     scr = scr + 1
  75.    end
  76.   elseif key == keys.enter then
  77.    term.clear()
  78.    return wybor
  79.   end
  80.  end  
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement