Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cosUtils.centerPrintTable(y, w, items, numOp, slow, col, margins, win)
- win = win and win or term
- local ts = tostring
- cosUtils.logToOS("Color: " .. ts(col) .. " | Slow: " .. ts(slow) .. " | NumOp: " .. ts(numOp) .. " | Margins: " .. ts(margins))
- col = col and col or colors.black
- slow = slow == nil and false or slow
- numOp = numOp and numOp or 0
- margins = margins == nil and true or margins
- cosUtils.logToOS("Color: " .. ts(col) .. " | Slow: " .. ts(slow) .. " | NumOp: " .. ts(numOp) .. " | Margins: " .. ts(margins))
- -- Calculate the longest line
- local longestLine = 0
- for _, item in ipairs(items) do
- if #item > longestLine then
- longestLine = #item
- end
- end
- -- Set Box Dimensions
- local wMarg, hMarg = margins and 4 or 0, margins and 2 or 0
- local boxWidth = longestLine + wMarg -- 1 margin on each side + 2 for borders
- local boxHeight = #items + hMarg -- 1 margin on top and bottom + 2 for borders
- -- Calculate the starting position
- local x = math.floor((w - boxWidth) / 2)
- local yStart = y
- -- Draw the box around the menu
- cosUtils.drawBox(win, x, yStart, boxWidth, boxHeight)
- -- Print the menu items inside the box
- for i, item in ipairs(items) do
- local text = item
- local xPos = math.floor((w - #text) / 2)
- yStart = margins and yStart or yStart - 1
- win.setCursorPos(xPos, yStart + i)
- win.setBackgroundColor(col)
- if slow then
- textutils.slowWrite(text, 9)
- else
- win.write(text)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement