Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: pws-20: Blatant falsehood should not be tolerated



LINES <S>
     The number of lines for this terminal session.  Used for printing
     select lists and for the line editor.

Bah!  Printing select lists has never paid any attention to the number of
lines (though I have often wished that it did).

Consequently, the patch below makes it pay attention to $LINES.  Every time
you hit return at the PS3 prompt without typing anything, another screenful
of possible selections is printed.  When you've seen them all, it starts
over at the top.  If you don't like this patch, let's fix the doc.

The selection list is still split into columns and numbered down them as if
the screen had enough lines to display the whole thing.  This makes it very
obvious that some of the choices are not shown when there are at least two
columns; anybody have a good suggestion for, say, altering the PS3 prompt,
so one can tell the list is incomplete when there is only one column?

For example, in the 3.1.5 dist tree, try (with a 24-line display):

zagzig% foo=(**/*(.:t))
zagzig% typeset -U foo
zagzig% select foo in $foo; do echo $REPLY\) $foo; done
1) BUGS                                175) hist.c                            
2) CONTRIBUTORS                        176) index.yo                          
3) ChangeLog                           177) init.c                            
4) ChangeLog.3.0                       178) input.c                           
5) FAQ.yo                              179) install-sh                        
6) FEATURES                            180) intro.ms                          
7) FTP-README                          181) intro.yo                          
8) INSTALL                             182) invoke.yo                         
9) MACHINES                            183) iwidgets.list                     
10) META-FAQ                           184) jobs.c                            
11) META-FAQ.yo                        185) jobs.yo                           
12) Makefile.in                        186) lete2ctl                          
13) Makemod.in.in                      187) lex.c                             
14) NEWS                               188) linklist.c                        
15) README                             189) loop.c                            
16) _a2ps                              190) main.c                            
17) _aliases                           191) makepro.awk                       
18) _approximate                       192) mapfile.c                         
19) _arrays                            193) mapfile.mdd                       
20) _autoload                          194) math.c                            
21) _bg_jobs                           195) mem.c                             
22) _bindkey                           196) mere                              
?# 

You can keep hitting return until eventually you see:

155) deltochar.mdd                     329) zshcompwid.yo                     
156) example.c                         330) zshenv                            
157) example.mdd                       331) zshexpn.1                         
158) exec.c                            332) zshexpn.yo                        
159) exec.yo                           333) zshmisc.1                         
160) expn.yo                           334) zshmisc.yo                        
161) filelist.yo                       335) zshmodules.1                      
162) files.c                           336) zshmodules.yo                     
163) files.mdd                         337) zshoptions.1                      
164) files.yo                          338) zshoptions.yo                     
165) func.yo                           339) zshparam.1                        
166) glob.c                            340) zshparam.yo                       
167) globtests                         341) zshrc                             
168) globtests.ksh                     342) zshzftpsys.1                      
169) grammar.yo                        343) zshzftpsys.yo                     
170) guide.yo                          344) zshzle.1                          
171) harden                            345) zshzle.yo                         
172) hashtable.c                       346) ztexi.yo                          
173) hashtable.h                       347) ztype.h                           
174) helpfiles                         
?# 

at which point it starts back at 1 (and 175) again.

In the patch, `more' will be zero whenever the last entry in the list has
been printed, nonzero otherwise.

Index: Src/loop.c
===================================================================
@@ -138,6 +138,7 @@
     LinkNode n;
     int i;
     FILE *inp;
+    size_t more;
 
     node = cmd->u.forcmd;
     args = cmd->args;
@@ -154,7 +155,7 @@
     lastval = 0;
     pushheap();
     inp = fdopen(dup((SHTTY == -1) ? 0 : SHTTY), "r");
-    selectlist(args);
+    more = selectlist(args, 0);
     for (;;) {
 	for (;;) {
 	    if (empty(bufstack)) {
@@ -181,7 +182,7 @@
 		*s = '\0';
 	    if (*str)
 	      break;
-	    selectlist(args);
+	    more = selectlist(args, more);
 	}
 	setsparam("REPLY", ztrdup(str));
 	i = atoi(str);
@@ -217,8 +218,8 @@
 /* And this is used to print select lists. */
 
 /**/
-static void
-selectlist(LinkList l)
+size_t
+selectlist(LinkList l, size_t start)
 {
     size_t longest = 1, fct, fw = 0, colsz, t0, t1, ct;
     LinkNode n;
@@ -245,7 +246,7 @@
     else
 	fw = (columns - 1) / fct;
     colsz = (ct + fct - 1) / fct;
-    for (t1 = 0; t1 != colsz; t1++) {
+    for (t1 = start; t1 != colsz && t1 - start < lines - 2; t1++) {
 	ap = arr + t1;
 	do {
 	    int t2 = strlen(*ap) + 2, t3;
@@ -271,6 +272,8 @@
        }
        while (*ap);*/
     fflush(stderr);
+
+    return t1 < colsz ? t1 : 0;
 }
 
 /**/

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



Messages sorted by: Reverse Date, Date, Thread, Author