Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: zsh-3.1.5-pws-24: complist colour listing optimisation
- X-seq: zsh-workers 6871
- From: Geoff Wing <gcw@xxxxxxx>
- To: Zsh Hackers <zsh-workers@xxxxxxxxxxxxxx>
- Subject: PATCH: zsh-3.1.5-pws-24: complist colour listing optimisation
- Date: Sun, 27 Jun 1999 17:51:32 +1000
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
- Organization: PrimeNet Computer Consultancy
Heyla,
optimisations for output during colour lists. Duplicate sequences should
not achieve anything different from single sequences so don't output them.
Warning: unified diff follows :-)
--- Src/Zle/complist.c.orig Thu Jun 24 19:46:37 1999
+++ Src/Zle/complist.c Sun Jun 27 17:42:56 1999
@@ -230,48 +230,65 @@
if (!c->cols[COL_MI])
c->cols[COL_MI] = c->cols[COL_FI];
- if (!c->cols[COL_EC]) {
- char *e = (char *) zhalloc(strlen(c->cols[COL_LC]) +
- strlen(c->cols[COL_NO]) +
- strlen(c->cols[COL_RC]) + 1);
-
- /* If no `ec' was given, we is `<lc><no><rc>' as the default. */
- strcpy(e, c->cols[COL_LC]);
- strcat(e, c->cols[COL_NO]);
- strcat(e, c->cols[COL_RC]);
- c->cols[COL_EC] = e;
- }
return 0;
}
+static int last_col = COL_NO;
+
+static void
+zcputs(Listcols c, int colour)
+{
+ if (colour != last_col
+ && (last_col < COL_NO
+ || strcmp(c->cols[last_col], c->cols[colour]))) {
+ fputs(c->cols[COL_LC], shout);
+ fputs(c->cols[colour], shout);
+ fputs(c->cols[COL_RC], shout);
+ last_col = colour;
+ }
+ return;
+}
+
/* Get the terminal color string for the file with the given name and
* file modes. */
-static char *
-getcolstr(Listcols c, char *n, mode_t m)
+static void
+putcolstr(Listcols c, char *n, mode_t m)
{
+ int colour;
Extcol e;
for (e = c->exts; e; e = e->next)
- if (strsfx(e->ext, n))
- return e->col;
+ if (strsfx(e->ext, n)) { /* XXX: unoptimised if used */
+ if (last_col < COL_NO
+ || strcmp(c->cols[last_col], e->col)) {
+ fputs(c->cols[COL_LC], shout);
+ fputs(e->col, shout);
+ fputs(c->cols[COL_RC], shout);
+ }
+ last_col = COL_NO - 1;
+ return;
+ }
if (S_ISDIR(m))
- return c->cols[COL_DI];
+ colour = COL_DI;
else if (S_ISLNK(m))
- return c->cols[COL_LN];
+ colour = COL_LN;
else if (S_ISFIFO(m))
- return c->cols[COL_PI];
+ colour = COL_PI;
else if (S_ISSOCK(m))
- return c->cols[COL_SO];
+ colour = COL_SO;
else if (S_ISBLK(m))
- return c->cols[COL_BD];
+ colour = COL_BD;
else if (S_ISCHR(m))
- return c->cols[COL_CD];
+ colour = COL_CD;
else if (S_ISREG(m) && (m & S_IXUGO))
- return c->cols[COL_EX];
+ colour = COL_EX;
+ else
+ colour = COL_FI;
- return c->cols[COL_FI];
+ zcputs(c, colour);
+ return;
}
/* Information about the list shown. */
@@ -505,14 +522,15 @@
mc = 0;
q = p;
while (n && i--) {
- fputs(col.cols[COL_LC], shout);
if (!(m = *q)) {
- fputs(col.cols[COL_MI], shout);
- fputs(col.cols[COL_RC], shout);
+ zcputs(&col, COL_MI);
a = longest - 2;
while (a--)
putc(' ', shout);
- fputs(col.cols[COL_EC], shout);
+ if (col.cols[COL_EC])
+ fputs(col.cols[COL_EC], shout);
+ else
+ zcputs(&col, COL_NO);
break;
}
hasm = 1;
@@ -539,20 +557,18 @@
zt = ztat(pb, &buf, 1);
if (cc >= 0)
- fputs(col.cols[cc], shout);
+ zcputs(&col, cc);
else if (zt)
- fputs(col.cols[COL_NO], shout);
+ zcputs(&col, COL_NO);
else
- fputs(getcolstr(&col, pb, buf.st_mode), shout);
- fputs(col.cols[COL_RC], shout);
+ putcolstr(&col, pb, buf.st_mode);
nicezputs(m->str, shout);
if (zt)
putc(' ', shout);
else
putc(file_type(buf.st_mode), shout);
} else {
- fputs(col.cols[cc >= 0 ? cc : COL_NO], shout);
- fputs(col.cols[COL_RC], shout);
+ zcputs(&col, cc >= 0 ? cc : COL_NO);
nicezputs(m->str, shout);
if (of)
putc(' ', shout);
@@ -560,13 +576,17 @@
a = longest - niceztrlen(m->str) - 2 - of;
while (a--)
putc(' ', shout);
- fputs(col.cols[COL_EC], shout);
+ if (col.cols[COL_EC])
+ fputs(col.cols[COL_EC], shout);
+ else
+ zcputs(&col, COL_NO);
if (i) {
- fputs(col.cols[COL_LC], shout);
- fputs(col.cols[COL_NO], shout);
- fputs(col.cols[COL_RC], shout);
+ zcputs(&col, COL_NO);
fputs(" ", shout);
- fputs(col.cols[COL_EC], shout);
+ if (col.cols[COL_EC])
+ fputs(col.cols[COL_EC], shout);
+ else
+ zcputs(&col, COL_NO);
}
if (--n)
for (j = nc; j && *q; j--)
@@ -574,13 +594,14 @@
mc++;
}
if (i > 0) {
- fputs(col.cols[COL_LC], shout);
- fputs(col.cols[COL_MI], shout);
- fputs(col.cols[COL_RC], shout);
+ zcputs(&col, COL_MI);
a = longest - 2;
while (a--)
putc(' ', shout);
- fputs(col.cols[COL_EC], shout);
+ if (col.cols[COL_EC])
+ fputs(col.cols[COL_EC], shout);
+ else
+ zcputs(&col, COL_NO);
}
if (n) {
putc('\n', shout);
--
Geoff Wing : <gcw@xxxxxxxxx> Work URL: http://www.primenet.com.au/
Rxvt Stuff : <gcw@xxxxxxxx> Ego URL : http://pobox.com/~gcw/
Zsh Stuff : <gcw@xxxxxxx> Phone : (Australia) 0413 431 874
Messages sorted by:
Reverse Date,
Date,
Thread,
Author