Oh yeah, that stuff is a pain.
Here's my old terminal glasses print funciton
-- Queues prints to display
tPrintQueue = {}
tRemoveTimer = {}
tRemoveText = {}
function gPrint(msg,time,color)
if not msg then
return
elseif type(msg) == "table" then
for i=1,#msg do
gPrint(msg[i],time,color)
end
return
end
local msg = string.format(msg) or ""
local tPrintOrder = {}
local stringWidth = G.getStringWidth(msg)
local lines = math.ceil(stringWidth/displaySizeX)
local time = time or displayMessageTime*lines
local color = color or displayTextColor
local stringLength = #msg
if lines < 2 then
table.insert(tPrintOrder,msg)
else
while true do
for s=math.floor(displaySizeX/8),stringLength+math.floor(displaySizeX/8) do
if not msg then
break
end
local stringWidth = G.getStringWidth(string.sub(msg,1,s))
if stringWidth > displaySizeX-2 then
local endSpace = string.find(string.sub(msg,1,s),"%s.?$")
local lastSpace = string.find(string.sub(msg,1,s),"%s%S-$")
if endSpace then
--line ending in space
table.insert(tPrintOrder,string.sub(msg,1,endSpace-1))
msg = string.sub(msg,endSpace+1,#msg)
elseif lastSpace then
--line not ending in space
table.insert(tPrintOrder,string.sub(msg,1,lastSpace-1))
msg = string.sub(msg,lastSpace+1,#msg)
else
--word longer than line
table.insert(tPrintOrder,string.sub(msg,1,s))
msg = string.sub(msg,s-1,#msg)
end
break
--end of message
elseif s >= #msg then
table.insert(tPrintOrder,msg)
msg = nil
break
end
end
if not msg then
break
end
end
end
if displayDirection == "up" and #tPrintOrder > 1 then
local size = #tPrintOrder+1
local tRet = {}
for i,v in ipairs(tPrintOrder) do
tRet[size-i] = v
end
for i=1,#tRet do
tPrintOrder[i] = tRet[i]
end
end
for i=1,#tPrintOrder do
table.insert(tPrintQueue,tPrintOrder[i])
if time > 0 then
table.insert(tRemoveTimer,os.startTimer(time))
table.insert(tRemoveText,tPrintOrder[i])
end
end
table.insert(tRunning,cDisplay)
end
Note that this is just for seperating the lines properly, not actual rendering. Anyways, what you're currently doing should get you going in the right direction, i mean it should atleast render something on your screen. If you redefine printError aswell that is, in the case of shell errors.