mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-05 09:14:03 +00:00
Don't use curses includes, include termcap.h instead
Don't use curses functions, use tputs instead Add ^C reaction - reset colors Optimization - don't turn off colors after EACH file printed. Fix wrong ctype macro arg type in LSCOLORS parsing
This commit is contained in:
parent
b6a1416d3a
commit
cf0feaeee9
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=61291
@ -48,7 +48,8 @@ static const char rcsid[] =
|
||||
|
||||
#ifdef COLORLS
|
||||
#include <ctype.h>
|
||||
#include <curses.h>
|
||||
#include <termcap.h>
|
||||
#include <term.h> /* for tparm */
|
||||
#endif
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
@ -58,9 +59,6 @@ static const char rcsid[] =
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifdef COLORLS
|
||||
#include <term.h>
|
||||
#endif
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
@ -94,6 +92,7 @@ typedef enum Colors {
|
||||
char *defcolors = "4x5x2x3x1x464301060203";
|
||||
|
||||
static int colors[C_NUMCOLORS][2];
|
||||
static int color_printed = 0;
|
||||
#endif
|
||||
|
||||
void
|
||||
@ -159,12 +158,12 @@ printlong(dp)
|
||||
printtime(sp->st_mtime);
|
||||
#ifdef COLORLS
|
||||
if (f_color)
|
||||
(void)colortype(sp->st_mode);
|
||||
color_printed = colortype(sp->st_mode);
|
||||
#endif
|
||||
if (f_octal || f_octal_escape) (void)prn_octal(p->fts_name);
|
||||
else (void)printf("%s", p->fts_name);
|
||||
#ifdef COLORLS
|
||||
if (f_color)
|
||||
if (f_color && color_printed)
|
||||
endcolor();
|
||||
#endif
|
||||
if (f_type)
|
||||
@ -280,12 +279,12 @@ printaname(p, inodefield, sizefield)
|
||||
(int)sizefield, howmany(sp->st_blocks, blocksize));
|
||||
#ifdef COLORLS
|
||||
if (f_color)
|
||||
(void)colortype(sp->st_mode);
|
||||
color_printed = colortype(sp->st_mode);
|
||||
#endif
|
||||
chcnt += (f_octal || f_octal_escape) ? prn_octal(p->fts_name)
|
||||
: printf("%s", p->fts_name);
|
||||
#ifdef COLORLS
|
||||
if (f_color)
|
||||
if (f_color && color_printed)
|
||||
endcolor();
|
||||
#endif
|
||||
if (f_type)
|
||||
@ -352,6 +351,13 @@ printtype(mode)
|
||||
}
|
||||
|
||||
#ifdef COLORLS
|
||||
int putch(c)
|
||||
int c;
|
||||
{
|
||||
return putc(c, stdout);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
printcolor(c)
|
||||
Colors c;
|
||||
@ -361,21 +367,20 @@ printcolor(c)
|
||||
if (colors[c][0] != -1) {
|
||||
ansiseq = tparm(ansi_fgcol, colors[c][0]);
|
||||
if (ansiseq)
|
||||
putp(ansiseq);
|
||||
tputs(ansiseq, 1, putch);
|
||||
}
|
||||
|
||||
if (colors[c][1] != -1) {
|
||||
ansiseq = tparm(ansi_bgcol, colors[c][1]);
|
||||
if (ansiseq)
|
||||
putp(ansiseq);
|
||||
tputs(ansiseq, 1, putch);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
endcolor()
|
||||
{
|
||||
if (ansi_coloff)
|
||||
putp(ansi_coloff);
|
||||
tputs(ansi_coloff, 1, putch);
|
||||
}
|
||||
|
||||
int
|
||||
@ -439,7 +444,7 @@ char *cs;
|
||||
}
|
||||
for (j = 0 ; j < 2 ; j++) {
|
||||
if ((c[j] < '0' || c[j] > '7') &&
|
||||
tolower(c[j]) != 'x') {
|
||||
tolower((unsigned char)c[j]) != 'x') {
|
||||
fprintf(stderr,
|
||||
"error: invalid character '%c' in LSCOLORS env var\n",
|
||||
c[j]);
|
||||
@ -452,6 +457,14 @@ char *cs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
void colorquit(sig)
|
||||
int sig;
|
||||
{
|
||||
endcolor();
|
||||
exit(1);
|
||||
}
|
||||
#endif /*COLORLS*/
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user