39 lines
852 B
Lua
39 lines
852 B
Lua
local buffer = ""
|
|
local completion_index = nil
|
|
local completion_fn = nil
|
|
local hide_input = false
|
|
|
|
KEY_BACKSPACE = 259
|
|
KEY_ENTER = 257
|
|
|
|
function do_event(etype, edata)
|
|
if etype == "char" then
|
|
buffer = buffer .. edata
|
|
if hide_input then
|
|
write("*")
|
|
else
|
|
write(edata)
|
|
end
|
|
elseif etype == "key" then
|
|
if edata == KEY_BACKSPACE and #buffer > 0 then
|
|
x, y = term.getCursorPos()
|
|
x = x - 1
|
|
term.setCursorPos(x, y)
|
|
write(" ")
|
|
term.setCursorPos(x, y)
|
|
buffer = string.sub(buffer, 1, string.len(buffer) - 1)
|
|
elseif edata == KEY_ENTER then
|
|
local b = buffer
|
|
buffer = ""
|
|
return b
|
|
end
|
|
end
|
|
end
|
|
|
|
return {
|
|
do_event = do_event,
|
|
get_buffer = function() return buffer end,
|
|
reset_buffer = function() buffer = "" end,
|
|
set_completion = function(f) completion_fn = f end,
|
|
hide_input = function(hide) hide_input = hide end,
|
|
}
|