erdos/src/term/get.lua

32 lines
492 B
Lua
Raw Normal View History

2022-02-16 18:53:37 +00:00
return function(con)
2022-02-21 18:29:51 +00:00
-- KostylLand
--- Special for (almost) terminal
--- (c) Er2 2022 <er2@dismail.de>
local function updK()
__run(true)
end
2022-02-16 18:53:37 +00:00
function con.getch(tout)
local t, ch = os.time(), nil
2022-02-21 18:29:51 +00:00
while ch == nil and ACTIVE do
updK()
ch = con.popbuf(false)
if tout and os.time() - t >= tout
then break end
end
return ch or ''
2022-02-16 18:53:37 +00:00
end
function con.getln()
2022-02-21 18:29:51 +00:00
local ln
while ln == nil and ACTIVE do
updK()
ln = con.popbuf(true)
2022-02-16 18:53:37 +00:00
end
2022-02-21 18:29:51 +00:00
return ln or ''
2022-02-16 18:53:37 +00:00
end
end