68 lines
1.1 KiB
Lua
68 lines
1.1 KiB
Lua
|
return function(con)
|
||
|
|
||
|
function con.curln(of)
|
||
|
return con.text[#con.text - (of or 0)]
|
||
|
end
|
||
|
|
||
|
function con.setln(v, of)
|
||
|
con.text[#con.text - (of or 0)] = tostring(v)
|
||
|
return v
|
||
|
end
|
||
|
|
||
|
function con.bs(oth)
|
||
|
if not con.usebs then return end
|
||
|
local s = oth or con.curln()
|
||
|
local off = utf8.offset(s, -1)
|
||
|
if off then
|
||
|
s = s:sub(1, off - 1)
|
||
|
end
|
||
|
if not oth then con.setln(s) end
|
||
|
return s
|
||
|
end
|
||
|
|
||
|
function con.cls()
|
||
|
con.text = {''}
|
||
|
con.oy = 0
|
||
|
end
|
||
|
|
||
|
function con.print(text)
|
||
|
for i, v in utf8.codes(tostring(text)) do
|
||
|
v = utf8.char(v)
|
||
|
if v == '\n' then con.ret()
|
||
|
elseif v == '\b' then con.bs()
|
||
|
-- \r\t\v is in loop
|
||
|
else con.puts(v)
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function con.puts(text)
|
||
|
con.setln(con.curln().. text)
|
||
|
con:emit('resT')
|
||
|
end
|
||
|
|
||
|
function con.println(text)
|
||
|
con.print(tostring(text).. '\n')
|
||
|
end
|
||
|
|
||
|
function con.ret()
|
||
|
table.insert(con.text, '')
|
||
|
end
|
||
|
|
||
|
function con.type(text)
|
||
|
con.puts(text)
|
||
|
con:emit('type', text)
|
||
|
end
|
||
|
|
||
|
function con.keydown(k)
|
||
|
con:emit('down', k)
|
||
|
if k == 'backspace' then con.bs()
|
||
|
elseif k == 'return' then
|
||
|
con.ret()
|
||
|
con.down()
|
||
|
con:emit('return')
|
||
|
end
|
||
|
end
|
||
|
|
||
|
end
|