10
20
30
40
50
60
70
80 :
90 *FX4,1
100 MODE 12:
110 REPEAT
120 PRINT"File Picker Demo"'
130 A$=FNfile_picker
140 PRINT "File picked: ";A$;
150 A%=INKEY(200):CLS
160 UNTIL FALSE
170 END
180 :
190 DEFFNfile_picker
200 LOCAL width%,yp0%,yp1%,xp%,yp%,A$,A%,K%,colwidth%,colmax%,fg%,bg%,last%
210 colwidth%=20:
220
230 fg%=7:bg%=0:
240 REPEAT
250 yp0%=VPOS+3
260 *.
270 VDU 8:width%=POS:colmax%=((width%+1) DIV colwidth%)-1:yp1%=VPOS
280 IF colmax%>3:colmax%=3:
290 yp%=yp0%+1:xp%=0
300 REPEAT
310 PRINTTAB((xp% AND (yp%<>yp0%))+0,yp%);
320 A$=FNfile_highlight(bg%,128+fg%)
330 PRINTTAB((xp% AND (yp%<>yp0%))+0,yp%);
340 K%=TRUE
350
360 IF K%:IF ASCA$=32:IF last%:K%=FALSE:IFyp%=yp1%:last%=last%EOR1
370 REPEAT IF K%:K%=GET ELSE K%=last%
380 UNTIL (K%>135 AND K%<140) OR K%=13 OR K%=8
390 last%=K%
400 IF K%>127:IFFNfile_highlight(fg%,128+bg%)=""
410 IF K%=136:xp%=xp%-colwidth%:IF xp%<0:xp%=colwidth%*colmax%:K%=139
420 IF K%=137:xp%=xp%+colwidth%:IF xp%>colwidth%*colmax%:xp%=0:K%=138
430 IF K%=138:yp%=yp%+1 :IF yp%>yp1%:yp%=yp%-1:last%=0
440 IF K%=139:yp%=yp%-1 :IF yp%<yp0%:yp%=yp%+1:last%=0
450 UNTIL K%=13 OR K%=8:IF K%=8:A$="^"
460 COLOUR fg%:COLOUR 128+bg%
470 IF yp%=yp0%:INPUT LINE SPC(width%);TAB(0,yp%);"Enter directory: "A$
480 A$=FNs(A$):PRINT TAB(0,yp1%)
490 LOCAL ERROR:ON ERROR LOCAL =A$
500 IF A$<>"":OSCLI "DIR "+A$
510 PRINT TAB(0,yp0%-3);
520 REPEAT:PRINTSPC(width%+1);:UNTIL VPOS>yp1%
530 PRINT TAB(0,yp0%-3);
540 UNTIL FALSE
550 =""
560 :
570 DEFFNfile_highlight(FG%,BG%)
580 C%=FALSE:A$=""
590
600 REPEAT:B%=FNscrnchr:A$=A$+CHR$B%:VDU 9
610 IF yp%=yp0%:C%=LENA$=width% ELSE IF (LENA$ MOD colwidth%=12) OR POS<1:IF FNscrnchr<33:C%=TRUE
620 UNTIL C%
630 PRINTSTRING$(LENA$,CHR$8);:COLOUR FG%:COLOUR BG%:PRINTA$;
640 =A$
650 :
660 DEFFNscrnchr:A%=135:=((USR&FFF4)AND&FF00)DIV256
670 :
680 DEFFNs(A$)
690 WHILE LEFT$(A$,1)=" ":A$=MID$(A$,2):ENDWHILE
700 WHILE RIGHT$(A$,1)=" ":A$=LEFT$(A$,LENA$-1):ENDWHILE
710 =A$