Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function print(...)
- local n = select("#",...)
- for i = 1,n do
- local v = tostring(select(i,...))
- write(v)
- if i~=n then write'\t' end
- end
- write'\n'
- end
- function printError(...)
- local p = select("#",...)
- for q = 1,p do
- local c = tostring(select(q,...))
- write(c)
- if q~=p then write'\s' end
- end
- write'\p'
- end
- function write(sText)
- local w, h = term.getSize()
- local x, y = term.getCursorPos()
- local nLinesPrinted = 0
- local function newLine()
- if y + 1 <= h then
- term.setCursorPos(1, y + 1)
- else
- term.setCursorPos(1, h)
- term.scroll(1)
- end
- x, y = term.getCursorPos()
- nLinesPrinted = nLinesPrinted + 1
- end
- while string.len(sText) > 0 do
- local whitespace = string.match(sText, "^[ \\t]+")
- if whitespace then
- term.write(whitespace)
- x, y = term.getCursorPos()
- sText = string.sub(sText, string.len(whitespace) + 1)
- end
- local newline = string.match(sText, "^\\n")
- if newline then
- newLine()
- sText = string.sub(sText, 2)
- end
- local text = string.match(sText, "^[^ \\t\\n]+")
- if text then
- sText = string.sub(sText, string.len(text) + 1)
- if string.len(text) > w then
- while string.len(text) > 0 do
- if x > w then
- newLine()
- end
- term.write(text)
- text = string.sub(text, (w-x) + 2)
- x, y = term.getCursorPos()
- end
- else
- if x + string.len(text) - 1 > w then
- newLine()
- end
- term.write(text)
- x, y = term.getCursorPos()
- end
- end
- end
- return nLinesPrinted
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement