-- cmd (string): the cmd will be sent to pkuxkx
-- regex (table): a collection of regex, when any line matches any regex, return
-- timeout (number): timeout
function PkuxkxWaitForNextMatchingLine(cmd, regex, timeout)
timeout = timeout or 3
world.Note("WaitForNextMatchingLine - never comment this line out, we need an output to eliminate previous partial line")
local startLineCount = world.GetLineCount()
local deadline = os.time() + timeout
Info("Executing "..cmd)
world.Send(cmd)
repeat
local endIndex = world.GetLinesInBufferCount()
local lineCount = world.GetLineCount() - startLineCount
local startIndex = endIndex - lineCount
for i = startIndex, endIndex do
local line = world.GetLineInfo(i, 1)
for k, v in ipairs(regex) do
if string.match(line, v) then
return startIndex, i, k
end
end
end
wait.time(0.1)
until os.time() > deadline
end