local xSize, ySize = term.getSize()
local comp = false

local usualText = function(string,xPos,yPos)
	term.setCursorPos(xPos,yPos)
	term.write(string)
end

function main(...)
	local waitFor = true
	local x = arg[1]
	local y = arg[2]
	local maxLenth = 3
	local output = nil
	for i=3,#arg do
		if #arg[i] > maxLenth then
			maxLenth = #arg[i]
		end
	end
	maxLenth = maxLenth + 1
	local xend = x+maxLenth
	local yend = y+#arg-1
	if x+maxLenth > xSize then
		xend = x
		x = x-maxLenth
	end
	if y+#arg > ySize then
		yend = y
		y = y-#arg+1
	end
	paintutils.drawFilledBox(x,y,xend,yend,colors.gray)
	term.setTextColor(colors.white)
	for i=3,#arg do
		usualText(arg[i],x+math.floor((maxLenth-1)/2)-math.floor(#arg[i]/2)+1,y+i-2)
	end
	while waitFor do
		event, side, xp, yp = os.pullEvent()
		if event == 'mouse_click' then 
			for i=1,#arg-2 do
				if xp >= x and xp <= xend and yp >= y and yp <= yend then
					if yp == y+i then
						paintutils.drawFilledBox(x,y+i,xend,y+i,colors.lightGray)
						usualText(arg[i+2],x+math.floor((maxLenth-1)/2)-math.floor(#arg[i+2]/2)+1,y+i)
						sleep(0.1)
						output = arg[i+2]
					end
				end
			end
			return output
		end
	end
end