Page 1 of 1

Controlling DIR scrolling

Posted: Tue Jun 11, 2019 9:01 pm
by Chr$
Hello, I'm just writing a little SuperBasic prog on an original QL with TK2, to help me manage and unzip the tons of zip files downloaded from Dilwyn's site.

The program can (if you want it to) display a Dir listing of a directory but the directory in question is quite full, so it expects you to press a key to scroll the listing. Fine, but annoyingly the keys pressed to scroll during the program are also 'remembered' and they end up on screen, which sort of ruins the next input request (of a file name) as I first have to delete the entered rubbish keys that I had to press to scroll the dir!

So is there a way to do a Dir and scroll the results without the actual keys pressed being registered/recorded in any way? Like a silent stealth mode for scrolling!

Thanks.

Re: Controlling DIR scrolling

Posted: Tue Jun 11, 2019 10:01 pm
by Andrew
dummy = KEYROW(0)

When KEYROW is used any characters in the type-ahead buffer are cleared.

Re: Controlling DIR scrolling

Posted: Tue Jun 11, 2019 10:13 pm
by Derek_Stewart
Hi,

Two ways to do this:

1) Open a channel to a file and do a DIR to the channel to open file, then read the files back:

OPEN_NEW #3,dir_list: DIR #3,win1_: CLOSE #3

or with Toolkit 2

ch=FOP_NEW ('dir_list'): DIR #ch: CLOSE #ch

Both give a listing of the default directory.

The file dir_list holds the files of the DIRectory.

2) A more stuble way, is to open the directory and read each file in the directory.

See the online superbasic manual:

https://superbasic-manual.readthedocs.i ... n-dir.html

This gives complicated exa,ple of opening disc dirctories, the Toolkit 2 version use a fuction called FOP_DIR.

I will post an equivalent DIR cammand later, as I am not at my computer.

You need to read the Toolkit 2 manual as well, which allows yoy to use file functions like FTEST, FTYP, which allows selection of files based on the file type, FTEST can tell you if thet exist.

Re: Controlling DIR scrolling

Posted: Tue Jun 11, 2019 10:44 pm
by EmmBee
Hi chr$,

I've had this problem myself. The extraneous keys are coming from TK2, and they get stored in #0's input buffer. dummy = KEYROW(0) should work a treat.

If you would like to give us your listing, that would be interesting, and we could then perhaps make some further comments.

Re: Controlling DIR scrolling

Posted: Tue Jun 11, 2019 11:01 pm
by Chr$
Thanks everyone.

I'll have a play. I did include a dummy = KEYROW(0), but I suspect in the wrong place! It's my first attempt at a SuperBasic program and I'm really not good at these things, but I will share it when it's done. It certainly helps me to manage zip files and saves a lot of time.

Re: Controlling DIR scrolling

Posted: Wed Jun 12, 2019 8:13 am
by EmmBee
It would appear that the use of KEYROW doesn't actually work. I tried the following ...

Code: Select all

100 DIR win1_
110 dummy = KEYROW(0)
120 PRINT #0,"All clear"
The typed in characters are appearing after the All clear message.
It's beginning to look like the only way would be to avoid using TK2 and do as Derek is suggesting.

Re: Controlling DIR scrolling

Posted: Wed Jun 12, 2019 8:42 am
by EmmBee
Instead of using KEYROW, an INKEY$ loop could be used to suck these unwanted characters out ...

Code: Select all

DIR win1_
REPeat exhaust : IF INKEY$ = "" : EXIT exhaust
PRINT #0,"All clear"

Re: Controlling DIR scrolling

Posted: Wed Jun 12, 2019 9:33 am
by Derek_Stewart
Hi,

Here is a S*Basic implementation of the DIR comand, with no screen pause:

Code: Select all

100 dir$="win1_"
110 ch=3
120 OPEN_DIR#ch,(dir$)
130 no_files=0
140 REPeat loop
150   IF EOF(#ch):EXIT loop
160   GET #ch\no_files*64+14,a$
170   IF a$<>'': PRINT a$
180   BGET #ch\no_files*64+64
190   no_files=no_files+1
200 END REPeat loop
210 CLOSE#ch
Change the variable dir$ for the required drive or directory, also you have make sure that channel 3 is not open.

An enhanced version using Toolkit 2 Functions:

Code: Select all

100 REMark Toolkit 2 style dir routine
120 REMark created 11/3/2000, D.Stewart
130 :
140 REMark File types : 0 = basic files
150 REMark File types : 1 = Exeutable files
160 REMark File types : 255 = Directory
170 :
172 REMark $$external
175 DEFine PROCedure CAT
180 dir$=DATAD$
190 dev$=dir$(1 TO 5)
195 tree$=dir$(6 TO )
200 ch=FOP_DIR(dir$)
210 COUNTA=0
220 STAT dir$
230 REPeat loop
240   IF EOF(#ch):EXIT loop
250   GET #ch\COUNTA*64+14,a$
260   IF a$<>'' THEN
270     file$=a$(LEN(tree$)+1 TO )
280     SELect ON FTYP(\dev$&tree$&file$)
290       =0   : file$ = file$
300       =1   : file$ = file$
310       =255 : file$ = file$ & " ->"
320     END SELect
325     PRINT file$
330   END IF
340   BGET #ch\COUNTA*64+64
350   COUNTA=COUNTA+1
360 END REPeat loop
370 CLOSE#ch
380 END DEFine CAT
The above procedure could be compiled with Qliberator as an external function and add the CAT keyword to SBASIC.

Re: Controlling DIR scrolling

Posted: Wed Jun 12, 2019 9:37 am
by Chr$
EmmBee wrote:It would appear that the use of KEYROW doesn't actually work. I tried the following ...

Code: Select all

100 DIR win1_
110 dummy = KEYROW(0)
120 PRINT #0,"All clear"
The typed in characters are appearing after the All clear message.
It's beginning to look like the only way would be to avoid using TK2 and do as Derek is suggesting.
dummy = KEYROW(0) works for me on my real QL! And your little program above was also fine and didn't show the keys-entered-to-scroll either.

That seems to be the simplest way of getting it to do what I want it to do. Which is good, because using channels, loops and such like just confuses me, a lot (but thanks Derek).

Re: Controlling DIR scrolling

Posted: Wed Jun 12, 2019 12:22 pm
by Cristian
I usually press the right arrow key