e
This commit is contained in:
1 parent
5111182a4b
commit
abd573f686
64 files changed
+2407
-157
No files matched your search
@@ -0,0 +1,88 @@
|
||||
local screen = {}
|
||||
|
||||
local 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
|
||||
|
||||
sText = tostring(sText)
|
||||
while #sText > 0 do
|
||||
local whitespace = string.match(sText, "^[ \t]+")
|
||||
if whitespace then
|
||||
term.write(whitespace)
|
||||
x, y = term.getCursorPos()
|
||||
sText = string.sub(sText, #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, #text + 1)
|
||||
if #text > w then
|
||||
while #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 + #text - 1 > w then
|
||||
newLine()
|
||||
end
|
||||
term.write(text)
|
||||
x, y = term.getCursorPos()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return nLinesPrinted
|
||||
end
|
||||
|
||||
function screen.print(...)
|
||||
local nLinesPrinted = 0
|
||||
local nLimit = select("#", ...)
|
||||
for n = 1, nLimit do
|
||||
local s = tostring(select(n, ...))
|
||||
if n < nLimit then
|
||||
s = s .. "\t"
|
||||
end
|
||||
nLinesPrinted = nLinesPrinted + write(s)
|
||||
end
|
||||
nLinesPrinted = nLinesPrinted + write("\n")
|
||||
end
|
||||
|
||||
function screen.printInline(...)
|
||||
local nLinesPrinted = 0
|
||||
local nLimit = select("#", ...)
|
||||
for n = 1, nLimit do
|
||||
local s = tostring(select(n, ...))
|
||||
nLinesPrinted = nLinesPrinted + write(s)
|
||||
end
|
||||
end
|
||||
|
||||
function screen.clear()
|
||||
term.clear()
|
||||
end
|
||||
|
||||
screen.id = "screen_1"
|
||||
screen.__UDATA_ID = 1
|
||||
|
||||
newComponent("screen", screen)
|
||||
Reference in new issue
Block a user