function compareTables(tbl1, tbl2, len)
local equal = true
for i = 1,len do
if tbl1[i] ~= tbl2[i] then
equal = false
break
end
end
return equal
end
local function uRead(reader)
term.setCursorBlink(reader.vBlink)
[color=#ff0000]local str = ""
local x, y = term.getCursorPos()
local pos = 1
local w, h = term.getSize()
if reader.vChar[1] then
function drawstr()
for i = 1,#str do
term.write(reader.vChar[2])
end
end
else
function drawstr()
term.write(str)
end
end
local function redraw()
setPos(x, y)
term.write(string.rep(" ", w - x + 1))
setPos(x, y)
drawstr()
setPos(x + pos - 1, y)
end[/color]
while true do
local e, p1, p2, p3, p4 = os.pullEvent()
local einfo = {e, p1, p2, p3, p4}
local rinfo = reader.vStop
if compareTables(einfo, rinfo, #rinfo) then
write("\n")
break
elseif e == "key" then
if p1 == 205 then
if pos <= str:len() then
pos = pos + 1
end
redraw()
elseif p1 == 203 then
if pos > 1 then
pos = pos - 1
end
redraw()
elseif p1 == 14 then
if pos > 1 then
pos = pos - 1
str = str:sub(1, pos - 1)..str:sub(pos + 1)
redraw()
end
end
[color=#ff0000] elseif e == "char" then
str = str:sub(1, pos - 1)..p1..str:sub(pos)
pos = pos + 1
redraw()
end[/color]
[color=#ff0000] redraw()[/color]
end
return str
end
function newReader()
local reader = {
["vBlink"] = true,
["vCharlimit"] = 0,
["vReadlimit"] = 0,
["vChar"] = {false, nil},
["vStop"] = {"key", 28},
}
function reader.blink(bool)
reader.vBlink = bool end
function reader.charlimit(limit)
reader.vCharlimit = limit end
function reader.readlimit(limit)
reader.vReadlimit = limit end
function reader.char(char)
if char == nil then
reader.vChar = {false, nil}
else
if char == false then
char = ""
else
char = tostring(char)
end
reader.vChar = {true, char}
end
end
function reader.stop(...)
reader.vStop = {...} end
function reader.run()
uRead(reader) end
return reader
end