Re: enhancing prompt() functions
- Posted by jimcbrown (admin) Sep 15, 2011
- 1071 views
euphoric said...
I would like to enhance the prompt_string() function to allow the user to supply a default or initial string to be used.
For example:
uname = "Steve Jones" -- could be retrieved from a database, prefs file, or whatever uname = prompt_string( "Enter username: ", uname )
Or is there another/a better way to go about this?
This approach is quite difficult, because we just use gets(0). Even if we fall back to C code, to handle fgets() we'd have to use ungetc() to push back the characters in the initial string - and ungetc() only guarantees one push back (thus one character).
So, we have to drop gets() and use wait_key() and puts() and handle the edit processing ourselves. This is a lot more complicated than the existing prompt_string() function. OTOH, ed.ex already does this.