Re: enhancing prompt() functions

new topic     » goto parent     » topic index » view thread      » older message » newer message

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") 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu