thx for ur awesome replies
I think I created a cRead function with backspace, arrowkeys and home/end support:
local function clearLine(y)
term.setCursorPos(1,y)
for i=1,51 do
term.write(" ")
end
end
local function cRead()
term.setCursorBlink(true)
local w,h = term.getSize()
local _,y = term.getCursorPos()
local s = ""
local p = 0 -- position of cursor
while true do
term.setCursorPos(w/2-math.floor(#s/2)+p,y)
local e,key = os.pullEvent()
if e == "char" then
s = table.concat({s:sub(1,p),key,s:sub(p+1,#s)})
p=p+1
end
if e == "key" and key == 14 and p > 0 then --backspace
s = table.concat({s:sub(1,p-1),s:sub(p+1,#s)})
p = p -1
end
if e == "key" and key == 28 then --enter
break
end
if e == "key" and key == 203 and p > 0 then --left arrow k.
p = p-1
end
if e == "key" and key == 205 and p < #s then --right arrow key
p = p+1
end
if e == "key" and key == 199 then --home
p = 0
end
if e == "key" and key == 207 then -- end
p = #s
end
if p > #s then --I had some issues, this is a fix for that
p = #s
end
clearLine(y)
term.setCursorPos(w/2-math.floor(#s/2),y)
term.write(s)
end
term.setCursorBlink(false)
return s
end
EDIT: I JUST QUICKLY ADDED KEYS IN COMMENTS
Edited by Konlab, 30 March 2015 - 06:13 PM.