local monitor = peripheral.wrap("top")

function split(sep, str)
  local t, ll
  t = {}
  ll = 0
  if(#str == 1) then return {str} end
  while true do
    l = string.find(str, sep, ll, true)
    if l ~= nil then
      table.insert(t, string.sub(str, ll, l-1))
      ll = l + 1
    else
      table.insert(t, string.sub(str, ll))
      break
    end
  end
  return t
end

function updateTps()
  local success, output = commands.exec("/cofh tps")
  monitor.clear()
  monitor.setCursorPos(1, 1)
  monitor.setTextScale(1.5)
  for key, value in pairs(output) do
    monitor.setCursorPos(5, (key - 1) * 2 + 1)
    local splitted = split(": ", value)
    monitor.write(splitted[1])
    monitor.setCursorPos(15, (key - 1) * 2 + 2)
    monitor.write(splitted[2])
  end
end

while true do
  updateTps()
  os.sleep(1)
end
