44 lines
779 B
Lua
44 lines
779 B
Lua
|
return function(con)
|
||
|
|
||
|
function con.getch(tout)
|
||
|
local t, ch = os.time(), nil
|
||
|
con.usebs = false
|
||
|
con:once('type', function(text)
|
||
|
ch = text:sub(1, 1)
|
||
|
end)
|
||
|
await(function() return
|
||
|
ch ~= nil
|
||
|
or (tout and os.time() - t >= tout)
|
||
|
end)
|
||
|
con.usebs = true
|
||
|
return ch
|
||
|
end
|
||
|
|
||
|
function con.getln()
|
||
|
local ln, du = '', true
|
||
|
local function _ln(text)
|
||
|
ln = ln .. text
|
||
|
end
|
||
|
local function _dwn(k)
|
||
|
if k == 'backspace' then
|
||
|
if #ln == 0 then con.usebs = false
|
||
|
else
|
||
|
con.usebs = true
|
||
|
ln = con.bs(ln)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
con:on('type', _ln)
|
||
|
con:on('down', _dwn)
|
||
|
con:once('return', function()
|
||
|
con:off(_ln)
|
||
|
con:off(_dwn)
|
||
|
con.usebs = true
|
||
|
du = false
|
||
|
end)
|
||
|
await(function() return not du end)
|
||
|
return ln
|
||
|
end
|
||
|
|
||
|
end
|