v0.4.0 - Aaaand event.lua is no longer working. FUUUUUUUUU
This commit is contained in:
+18
-15
@@ -2,30 +2,33 @@ local event = {}
|
||||
|
||||
local ocelot = component.proxy(component.list("ocelot")())
|
||||
|
||||
function event.pull(evtype, timeout)
|
||||
function event.pull(evtype, ...)
|
||||
local timeout = ...
|
||||
checkArg(1, evtype, "string", "nil")
|
||||
checkArg(2, timeout, "number", "nil")
|
||||
local startTime = computer.uptime()
|
||||
local args
|
||||
local args = {}
|
||||
local finished = false
|
||||
repeat
|
||||
for i = 1, #evmgr.eventQueue do
|
||||
ocelot.log(tostring(evmgr.eventQueue[i][1]).." ("..type(evmgr.eventQueue[i][1]).."), "..tostring(evmgr.eventQueue[i][2]))
|
||||
--ocelot.log(tostring(evmgr.eventQueue[i][3]))
|
||||
--ocelot.log(tostring(evmgr.eventQueue[i][4]))
|
||||
if evmgr.eventQueue[i][1] >= startTime and (evmgr.eventQueue[i][2] == evtype or not evtype) then
|
||||
args = evmgr.eventQueue[i]
|
||||
if evmgr.eventQueue[i][2] == evtype or not evtype then
|
||||
args = table.copy(evmgr.eventQueue[i])
|
||||
table.remove(evmgr.eventQueue, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
if not args then
|
||||
if evtype then
|
||||
finished = args[1] == evtype
|
||||
end
|
||||
if timeout then
|
||||
finished = computer.uptime() >= startTime + timeout
|
||||
end
|
||||
if not finished then
|
||||
coroutine.yield()
|
||||
end
|
||||
until args and not timeout or args and timeout and (args or computer.uptime() >= startTime + timeout)
|
||||
if args then
|
||||
--[[ table.remove(args, 1)
|
||||
return table.unpack(args) ]]
|
||||
return args[2]
|
||||
end
|
||||
until finished
|
||||
ocelot.log(tostring(args[1]))
|
||||
return table.unpack(args)
|
||||
end
|
||||
|
||||
return event
|
||||
return event
|
||||
+36
-6
@@ -1,5 +1,11 @@
|
||||
|
||||
local event = import("event")
|
||||
--local keyboard = import("keyboard")
|
||||
|
||||
local gpu = component.proxy(component.list("gpu")()) -- replace with component.gpu once implemented
|
||||
local lineNumber = 1
|
||||
local ocelot = component.proxy(component.list("ocelot")())
|
||||
_G.termlib = {}
|
||||
termlib.nextPosX, termlib.nextPosY = 1, 1
|
||||
|
||||
function _G.print(text)
|
||||
local xRes, yRes = gpu.getResolution()
|
||||
@@ -9,17 +15,41 @@ function _G.print(text)
|
||||
local printText = tostring(text):gsub("\t", " ")
|
||||
for line in printText:gmatch("([^\n]*)\n?") do
|
||||
while #line > xRes do
|
||||
gpu.set(1,lineNumber,line:sub(1,xRes))
|
||||
gpu.set(termlib.nextPosX, termlib.nextPosY, line:sub(1,xRes))
|
||||
line = line:sub(xRes+1)
|
||||
lineNumber = lineNumber + 1
|
||||
termlib.nextPosY = termlib.nextPosY + 1
|
||||
termlib.nextPosX = 1
|
||||
end
|
||||
gpu.set(1,lineNumber,line)
|
||||
lineNumber = lineNumber + 1
|
||||
gpu.set(termlib.nextPosX, termlib.nextPosY, line)
|
||||
termlib.nextPosY = termlib.nextPosY + 1
|
||||
end
|
||||
end
|
||||
|
||||
function _G.clear()
|
||||
local xRes, yRes = gpu.getResolution()
|
||||
gpu.fill(1,1,xRes,yRes," ")
|
||||
lineNumber = 1
|
||||
termlib.nextPosX, termlib.nextPosY = 1, 1
|
||||
end
|
||||
|
||||
function _G.read()
|
||||
ocelot.log("reading")
|
||||
local curtext = ""
|
||||
local nextPosX, nextPosY = termlib.nextPosX, termlib.nextPosY
|
||||
while true do
|
||||
local args = {event.pull("key_down", 0.5)}
|
||||
ocelot.log(tostring(args[1]))
|
||||
if args[4] then
|
||||
local keycode = args[4]
|
||||
local key = keyboard.keys[keycode]
|
||||
if key == "back" then
|
||||
curtext = curtext:sub(1, #curtext-1)
|
||||
elseif key == "enter" then
|
||||
return curtext
|
||||
else
|
||||
curtext = curtext .. (unicode.char(args[3]) or "")
|
||||
end
|
||||
termlib.nextPosX, termlib.nextPosY = nextPosX, nextPosY
|
||||
print(curtext)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user