I created a couple new functions based on tomass1996's Str Utiles Api.

Original is here and Github here

My fork with the new functions is here

chunkSpace(str,width) is the brother to chunk with the exception that my new function looks for the closest space so whole words are wrapped instead of splitting at the character width.

pageTextTable(table,height) is the companion function to chunkSpace. pageTextTable takes a of strings (generated by chunkSpace for instance) and splits the table into pages based on the height provided. This is useful for Printers and Monitors

In action https://www.youtube.com/watch?v=MsGTMk931FQ


Really long string:

Spoiler
local str = "It was while gliding through these latter waters that one serene and moonlight night, when all the waves rolled by like scrolls of silver; and, by their soft, suffusing seethings, made what seemed a silvery silence, not a solitude; on such a silent night a silvery jet was seen far in advance of the white bubbles at the bow. Lit up by the moon, it looked celestial; seemed some plumed and glittering god uprising from the sea. Fedallah first descried this jet. For of these moonlight nights, it was his wont to mount to the main-mast head, and stand a look-out there, with the same precision as if it had been day. And yet, though herds of whales were seen by night, not one whaleman in a hundred would venture a lowering for them. You may think with what emotions, then, the seamen beheld this old Oriental perched aloft at such unusual hours; his turban and the moon, companions in one sky. But when, after spending his uniform interval there for several successive nights without uttering a single sound; when, after all this silence, his unearthly voice was heard announcing that silvery, moon-lit jet, every reclining mariner started to his feet as if some winged spirit had lighted in the rigging, and hailed the mortal crew. \"There she blows!\" Had the trump of judgment blown, they could not have quivered more; yet still they felt no terror; rather pleasure. For though it was a most unwonted hour, yet so impressive was the cry, and so deliriously exciting, that almost every soul on board instinctively desired a lowering. Walking the deck with quick, side-lunging strides, Ahab commanded the t'gallant sails and royals to be set, and every stunsail spread. The best man in the ship must take the helm. Then, with every mast-head manned, the piled-up craft rolled down before the wind. The strange, upheaving, lifting tendency of the taffrail breeze filling the hollows of so many sails, made the buoyant, hovering deck to feel like air beneath the feet; while still she rushed along, as if two antagonistic influences were struggling in her—one to mount direct to heaven, the other to drive yawingly to some horizontal goal. And had you watched Ahab's face that night, you would have thought that in him also two different things were warring. While his one live leg made lively echoes along the deck, every stroke of his dead limb sounded like a coffin-tap. On life and death this old man walked. But though the ship so swiftly sped, and though from every eye, like arrows, the eager glances shot, yet the silvery jet was no more seen that night. Every sailor swore he saw it once, but not a second time. This midnight-spout had almost grown a forgotten thing, when, some days after, lo! at the same silent hour, it was again announced: again it was descried by all; but upon making sail to overtake it, once more it disappeared as if it had never been. And so it served us night after night, till no one heeded it but to wonder at it. Mysteriously jetted into the clear moonlight, or starlight, as the case might be; disappearing again for one whole day, or two days, or three; and somehow seeming at every distinct repetition to be advancing still further and further in our van, this solitary jet seemed for ever alluring us on. Nor with the immemorial superstition of their race, and in accordance with the preternaturalness, as it seemed, which in many things invested the Pequod, were there wanting some of the seamen who swore that whenever and wherever descried; at however remote times, or in however far apart latitudes and longitudes, that unnearable spout was cast by one self-same whale; and that whale, Moby Dick. For a time, there reigned, too, a sense of peculiar dread at this flitting apparition, as if it were treacherously beckoning us on and on, in order that the monster might turn round upon us, and rend us at last in the remotest and most savage seas. These temporary apprehensions, so vague but so awful, derived a wondrous potency from the contrasting serenity of the weather, in which, beneath all its blue blandness, some thought there lurked a devilish charm, as for days and days we voyaged along, through seas so wearily, lonesomely mild, that all space, in repugnance to our vengeful errand, seemed vacating itself of life before our urn-like prow."

Usage:
Spoiler

local monitor = peripheral.find("monitor")
monitor.clear()
local maxw, maxh = monitor.getSize()


local pages = StrUtils.pageTextTable(StrUtils.chunkSpace(str,maxw-1),maxh-3)
for page,lines in pairs(pages) do
  monitor.clear()
  if (page ~= 1) then
	local rightSide = "Page "..page.." of "..#pages
	monitor.setCursorPos(maxw-#rightSide+1,1)
	monitor.write(rightSide)
  end
  monitor.setCursorPos(1,1)
  monitor.write("Moby Dick")
  monitor.setCursorPos(2,3)
  for index,line in pairs(lines) do
	local _, cY = monitor.getCursorPos()
	monitor.write(line)
	monitor.setCursorPos(2,cY+1)
  end
  sleep(2)
end