File:  [Coherent Logic Development] / freem / contrib / %MEN.m
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Sun Jan 19 02:04:04 2025 UTC (6 months, 1 week ago) by snw
Branches: MAIN, CoherentLogicDevelopment
CVS tags: v0-63-1-rc1, v0-63-0-rc1, v0-63-0, v0-62-3, v0-62-2, v0-62-1, v0-62-0, start, HEAD
FreeM

    1: %MEN(y) ; A.Trocha ; Menu (up/down/choice) [1999/01/31-21:25:56]
    2: 	; $Source: /home/cvsroot/freem/contrib/%MEN.m,v $
    3: 	; $Revision: 1.1.1.1 $ $Date: 2025/01/19 02:04:04 $
    4: 	; <y> row where to position menue
    5: 	; inp> ^%UTILITY(%J,0..n) = choice
    6: 	; inp> ^%UTILITY(%J)   = default choice'headline
    7: 	; out> as function result chosen <i>
    8: 	;	-1 if esc was pressed
    9: 	;
   10: 	D ^%SYSDEV
   11: 	;
   12: 	N i,max,df,len,len,cnt,dflt,key,pos,max,head
   13: 	S i=""
   14: 	;
   15: 	;---  get the largest choice
   16: 	F  S i=$O(^%UTILITY($J,i)) Q:i=""  D
   17: 	. S len=$L(^%UTILITY($J,i)),max=i
   18: 	. I len>+$G(maxlen) S maxlen=len
   19: 	S head=$P($G(^%UTILITY($J)),"'",2)
   20: 	I $L(head)>maxlen S maxlen=$L(head)
   21: 	;
   22: 	;--- get params to center
   23: 	S x=(80-maxlen+2)\2
   24: 	;
   25: 	;--- get default choice - if none is given use the first entry
   26: 	S dflt=+$G(^%UTILITY($J))
   27: 	;
   28: 	;--- output initial menu
   29: 	S i=""
   30: 	F  S i=$O(^%UTILITY($J,i)) Q:i=""  D ref(i,dflt)
   31: 	D c(x,y+1,$$z(head,maxlen+2))
   32: 	;
   33: 	;--- draw window
   34: 	X %GO
   35: 	D c(x-1,y,"l"_$TR($J("",maxlen+2)," ","q")_"k")
   36: 	D c(x-1,y+1,"x"),c(x+maxlen+2,y+1,"x")
   37: 	F i=0:1:max+1 D c(x-1,y+i+2,"x"),c(x+maxlen+2,y+i+2,"x")
   38: 	D c(x-1,y+2,"t"_$TR($J("",maxlen+2)," ","q")_"u")
   39: 	D c(x-1,y+max+4,"m"_$TR($J("",maxlen+2)," ","q")_"j")
   40: 	X %GF
   41: 	;
   42: 	;---
   43: 	S pos=dflt
   44: 	W $C(27,91,63,50,53,108) ; turn off cursor
   45: loop	S key=$$^%KEY("",1)
   46: 	I key="UP" I pos>0 D ref(pos,-1) S pos=pos-1 D ref(pos,pos) G loop
   47: 	I key="DOWN" I pos<max D ref(pos,-1) S pos=pos+1 D ref(pos,pos) G loop
   48: 	I key="CR",$TR($G(^%UTILITY($J,pos))," ")'="" G end
   49: 	I key="ESC" S pos=-1 G end
   50: 	G loop
   51: 	;
   52: ref(rel,akt)	;
   53: 	N df
   54: 	S df=$S(akt=rel:">",1:" ")
   55: 	D c(x,y+rel+3,df_$$z(^%UTILITY($J,rel),maxlen)_$TR(df,">","<"))
   56: 	Q
   57: 	;
   58: end	;
   59: 	W $C(27,91,63,50,53,104) ; turn  cursor back on
   60: 	Q pos
   61: 	
   62: c(x,y,t) W *27,*91,y,";",x,"H"_$G(t) Q
   63: z(txt,len) ;
   64: 	N l,add
   65: 	S l=(len-$L($E(txt,1,len)))\2
   66: 	S add=len-(l*2+$L($E(txt,1,len)))
   67: 	Q $J("",l+add)_$E(txt,1,len)_$J("",l)

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>