475 posts
Posted 20 October 2012 - 12:07 AM
Hi! I'm trying to get a text field (read()) to have something already there before the user inputs any text. Does anyone know how to do this?
2217 posts
Location
3232235883
Posted 20 October 2012 - 12:10 AM
modify the sLine variable at the top of the read function
231 posts
Posted 20 October 2012 - 12:12 AM
You can do
os.queueEvent("char", "Starting text")
input = read()
This has the side effect of the starting cursor in read still being after the first characterEDIT: It doesn't if you put os.queueEvent("key", keys["end"]) between where you queue the message and read()
715 posts
Posted 20 October 2012 - 12:23 AM
You could first write something infront of it like so:
write("Enter Password: ")
local input = read()
And for convenience sake you can put it into a function:
local function textRead( text )
write( text )
return read()
end
This way you can comfortably use textRead() whenever you want to write something before an input:
local pwd = textRead("Please Enter your Password: ")
295 posts
Location
In the TARDIS at an unknown place in time.
Posted 20 October 2012 - 03:56 AM
Well, here's what you might do:
prevtext = "What's your name? | Answer: "
write(prevtext)
aftertext = read()
aftertext = (prevtext..aftertext)
I think the last line will work..
475 posts
Posted 20 October 2012 - 04:33 AM
Well I wanted the text there that you can edit the existing text too.
231 posts
Posted 20 October 2012 - 05:46 AM
My suggestion will do that. It makes it so that read will pull the starting text queued as a char event and put it there before you start writing.
475 posts
Posted 20 October 2012 - 06:29 PM
My suggestion will do that. It makes it so that read will pull the starting text queued as a char event and put it there before you start writing.
I tried your solution it works but were right, the cursor starts at the second character
231 posts
Posted 20 October 2012 - 06:30 PM
Use os.queueEvent("key", keys["end"]) after queueing the message but before calling read()
2447 posts
Posted 20 October 2012 - 06:47 PM
Why don't you just copy read and make your own function? It is open source in bios.lua. Should be trivial to prefill the character buffer.
Edit: as was suggested by pixeltoast.
8543 posts
Posted 21 October 2012 - 12:22 AM
read() can be passed a history table. Passing a table containing the string and queuing an up-arrow key event may do what you wish. Copying read() and adding this (very simple) feature is certainly the best way to do this, though.