Re: enhancing prompt() functions
- Posted by euphoric (admin) Sep 15, 2011
- 1038 views
This seems to work OK:
public function prompt_string(sequence prompt, sequence default = "") object answer puts(1, prompt) if length(default) > 0 then puts(1," [" & default & "] ") end if answer = gets(0) puts(1, '\n') if sequence(answer) and length(answer) > 0 then answer = answer[1..$-1] -- trim the \n end if if length(answer) > 0 then return answer else return default end if end function
To test:
sequence s = prompt_string( "Enter username:", "Billy Ray Jones") puts(1,"\n'" & s & "'\n\n")