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

function showTps()
  local mon = peripheral.wrap("top")
  local success, tpsLines = commands.exec("/cofh tps")
  mon.clear()
  mon.setTextScale(1.5)
  for idx, line in pairs(tpsLines) do
    local splitLine = split(": ", line)
    mon.setCursorPos(1, (idx - 1) * 2 + 1)
    mon.setTextColor(colors.yellow)
    mon.write(splitLine[1])
    mon.setCursorPos(11, (idx - 1) * 2 + 2)
    mon.setTextColor(colors.orange)
    mon.write(splitLine[2])
  end
end

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