Jump to content




Existing Text in read()?

lua

  • You cannot reply to this topic
10 replies to this topic

#1 lieudusty

  • Members
  • 419 posts

Posted 19 October 2012 - 11:07 PM

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?

#2 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 19 October 2012 - 11:10 PM

modify the sLine variable at the top of the read function

#3 faubiguy

  • Members
  • 213 posts

Posted 19 October 2012 - 11:12 PM

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 character
EDIT: It doesn't if you put os.queueEvent("key", keys["end"]) between where you queue the message and read()

#4 Espen

    Curious Explorer

  • Members
  • 708 posts

Posted 19 October 2012 - 11:23 PM

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: ")


#5 brett122798

  • Members
  • 300 posts
  • LocationIn the TARDIS at an unknown place in time.

Posted 20 October 2012 - 02: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..

#6 lieudusty

  • Members
  • 419 posts

Posted 20 October 2012 - 03:33 AM

Well I wanted the text there that you can edit the existing text too.

#7 faubiguy

  • Members
  • 213 posts

Posted 20 October 2012 - 04: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.

#8 lieudusty

  • Members
  • 419 posts

Posted 20 October 2012 - 05:29 PM

View Postfaubiguy, on 20 October 2012 - 04:46 AM, said:

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

#9 faubiguy

  • Members
  • 213 posts

Posted 20 October 2012 - 05:30 PM

Use os.queueEvent("key", keys["end"]) after queueing the message but before calling read()

#10 Cloudy

    Ex-Developer

  • Members
  • 2,543 posts

Posted 20 October 2012 - 05: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.

#11 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 20 October 2012 - 11:22 PM

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.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users