p = Pty.open("adventure")

input = {
    "no",
    "go building",
    "get water",
    "get keys",
    "get food",
    "get lantern",
    "go out",
    "go stream",
    "s",
    "quit",
    "yes",
    "ok"
}
i = 1

delay = 100
local read_until_done = function(p)
	local g, acc = true, ""

	while g and g ~= "" do
		g = p:read(delay)
		if not g then
			return nil
		end
		acc = acc .. g
	end

	return acc
end

g = read_until_done(p)
while g and input[i] do
	io.stdout:write(g)
	p:write(input[i] .. "\n")
	i = i + 1
	g = read_until_done(p)
end

p:close()
