if not term.isColor() then
  print("Advanced computer required")
  error()
end

local sides = peripheral.getNames()
local treefarms = {}
for _, side in pairs(sides) do
  if peripheral.getType(side) == "warpdriveLaserTreeFarm" then
    print("Wrapping " .. side)
    table.insert(treefarms, peripheral.wrap(side))
  end
end

local label = os.getComputerLabel()
if label then
else
  label = "" .. os.getComputerID()
end
term.setBackgroundColor(colors.black)
term.clear()
term.setBackgroundColor(colors.lime)
term.setCursorPos(1, 1)
print(label)

if #treefarms == 0 then
  term.setBackgroundColor(colors.red)
  term.setTextColor(colors.white)
  print("No laser tree farm detected")
else
  for key, treefarm in pairs(treefarms) do
    term.setCursorPos(1, 2 + key)
    local isEnabled = treefarm.enable()
    if not isEnabled then
      term.setBackgroundColor(colors.black)
      term.setTextColor(colors.gray)
      term.write("Laser tree farm " .. key .. " of " .. #treefarms .. " is already stopped")
    else
      treefarm.enable(false)
      term.setBackgroundColor(colors.lime)
      term.setTextColor(colors.blue)
      term.write("Laser tree farm " .. key .. " of " .. #treefarms .. " has been stopped")
    end
  end
end

term.setBackgroundColor(colors.black)
term.setTextColor(colors.white)

print()
