Posted 05 February 2013 - 05:37 AM
Hello folks, here's a simple function I made. It's a scrolling textbox with configurable width.
Warning: has not been fully tested (yet)! Tested, should work as expected.
Code:
or
eJGVpdFv
Code:
Spoiler
local function maxRead(nWidth)
nWidth = nWidth and nWidth-1 or 10
term.setCursorBlink(true)
local X_,Y_ = term.getCursorPos() --get original cursor X,Y
local String = ""
while true do --main loop
local event,p1 = os.pullEvent() --pull event
if event == "char" then --character was pressed
String = String..p1
elseif event == "key" then --key was pressed
if p1 == 28 then --return/enter
break
elseif p1 == 14 then --backspace
String = String:sub(1,#String-1)
end
end
term.setCursorPos(X_,Y_)
term.write(string.rep(" ",nWidth+1))
term.setCursorPos(X_,Y_)
term.write(String:sub(((#String - nWidth) >= 1 and #String - nWidth) or 1,#String))
end
term.setCursorBlink(false)
term.setCursorPos(X_,Y_+1) --return cursor to original X, original Y + 1
return String --return the string
end
or
eJGVpdFv
Edited on 02 January 2014 - 03:12 AM