here i made a textbox type thing:
usage: textbox(label)
returns string or nil if you press ctrl to close it out
local function textbox(bartext)
term.setCursorBlink( true )
local sLine = ""
local nPos = 0
local oW, oH = term.getSize()
local w,h=oW-4,math.floor(oH/2)
local sx,sy=4,math.floor(oH/2)
local function redraw()
local nScroll = 0
if sx + nPos >= w then
nScroll = (sx + nPos) - w
end
term.setCursorPos(3,math.floor(oH/2)-1)
write(string.rep("-",oW-5))
term.setCursorPos(3,math.floor(oH/2)+1)
write(string.rep("-",oW-5))
term.setCursorPos(math.floor(oW/2)-math.floor(#bartext/2),math.floor(oH/2)-1)
write(bartext)
term.setCursorPos( sx, sy )
term.write(term.write( string.rep(" ", w - sx + 1) ))
term.setCursorPos( sx, sy )
term.write(term.write( string.sub( sLine, nScroll + 1 ) ))
term.setCursorPos(3,math.floor(oH/2))
write("|")
term.setCursorPos(oW-3,math.floor(oH/2))
write("|")
term.setCursorPos( sx + nPos - nScroll, sy )
end
redraw()
while true do
local sEvent, param = os.pullEvent()
if sEvent == "char" then
sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
nPos = nPos + 1
redraw()
elseif sEvent == "key" then
if param == 28 then
break
elseif param == 203 then
if nPos > 0 then
nPos = nPos - 1
redraw()
end
elseif param == 205 then
if nPos < string.len(sLine) then
nPos = nPos + 1
redraw()
end
elseif param == 200 or param == 208 then
if _tHistory then
if param == 200 then
if nHistoryPos == nil then
if #_tHistory > 0 then
nHistoryPos = #_tHistory
end
elseif nHistoryPos > 1 then
nHistoryPos = nHistoryPos - 1
end
else
if nHistoryPos == #_tHistory then
nHistoryPos = nil
elseif nHistoryPos ~= nil then
nHistoryPos = nHistoryPos + 1
end
end
if nHistoryPos then
sLine = _tHistory[nHistoryPos]
nPos = string.len( sLine )
else
sLine = ""
nPos = 0
end
redraw()
end
elseif param == 14 then
if nPos > 0 then
sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
nPos = nPos - 1
redraw()
end
elseif param == 29 then
term.setCursorBlink( false )
return nil
end
end
end
term.setCursorBlink( false )
term.setCursorPos( w + 1, sy )
return sLine
end