\ defining an input box in menu style visualizing
\ hs 27.10.97

\ user interface
\	inbox	( addr n1 -- addr n2 )
\	a box is opened at the current cursor positioned with a text field
\	n1 characters wide. The user is allowed to enter up to n1 characters.
\	after pressing CR the text and it's actual length are returned.
\	name is a text info displayed above the 'enter' field

only forth also definitions
hidden also  terminals also

: edit-box	( name addr1 n1 -- addr1 n2 )
	temp-single true is menu-output?
	at-xy?  2 2 0 locals| bwidth boxx boxy oldy oldx cnt str name |
	(fg) (bg) get-cursor-status cursor-off
	cnt name c@ max is bwidth
	oldx 1- 1 max	#columns 1-  bwidth - min is boxx
	oldy 1- 3 max	#lines 2- min is boxy
	boxx 1- boxy 1- at-xy  bwidth 2+  3 save-screen-block
	black azur set-font-colours
	3 0 do boxx 1- boxy i + 1- at-xy  bwidth 2+ spaces loop
	boxx boxy 1- at-xy name ".
	multi cursor-on boxx boxy at-xy
	emacs-edit str cnt expect cursor-off single
	restore-screen-block  set-cursor-status  set-font-colours  oldx oldy at-xy
	str span @ false is menu-output? ;

: box-number	( name default len -- n )
	astring locals| str len default | push-decimal
	str 1+ len edit-box swap 1- c!
	str number? nip 0= ( n f ) str c@ 0=  or
	if drop default then pop-base ;
