diff options
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/ls/extern.h | 4 | ||||
| -rw-r--r-- | bin/ls/ls.c | 25 | ||||
| -rw-r--r-- | bin/ls/print.c | 13 |
3 files changed, 31 insertions, 11 deletions
diff --git a/bin/ls/extern.h b/bin/ls/extern.h index 82e020776556..9707ea7805ed 100644 --- a/bin/ls/extern.h +++ b/bin/ls/extern.h @@ -55,4 +55,8 @@ int prn_octal __P((char *)); void parsecolors __P((char *cs)); int colortype __P((mode_t mode)); void endcolor __P((void)); + +char *ansi_fgcol; +char *ansi_bgcol; +char *ansi_coloff; #endif diff --git a/bin/ls/ls.c b/bin/ls/ls.c index 7f278b383581..ee9da2cb0f9d 100644 --- a/bin/ls/ls.c +++ b/bin/ls/ls.c @@ -119,6 +119,10 @@ int f_type; /* add type character for non-regular files */ int f_whiteout; /* show whiteout entries */ #ifdef COLORLS int f_color; /* add type in color for non-regular files */ + +char *ansi_bgcol; /* ANSI sequence to set background colour */ +char *ansi_fgcol; /* ANSI sequence to set foreground colour */ +char *ansi_coloff; /* ANSI sequence to reset colours */ #endif int rval; @@ -133,6 +137,12 @@ main(argc, argv) int ch, fts_options, notused; char *p; +#ifdef COLORLS + char termcapbuf[1024]; /* termcap definition buffer */ + char tcapbuf[512]; /* capability buffer */ + char *bp = tcapbuf; +#endif + (void) setlocale(LC_ALL, ""); /* Terminal defaults to -Cq, non-terminal defaults to -1. */ @@ -198,8 +208,19 @@ main(argc, argv) case 'G': if (isatty(STDOUT_FILENO)) #ifdef COLORLS - if (tgetent(NULL, getenv("TERM")) == 1) - f_color = 1; + if (tgetent(termcapbuf, getenv("TERM")) == 1) { + ansi_fgcol = tgetstr("AF", &bp); + ansi_bgcol = tgetstr("AB", &bp); + + /* To switch colours off use 'op' if + * available, otherwise use 'oc', or + * don't do colours at all. */ + ansi_coloff = tgetstr("op", &bp); + if (!ansi_coloff) + ansi_coloff = tgetstr("oc", &bp); + if (ansi_fgcol && ansi_bgcol && ansi_coloff) + f_color = 1; + } #else (void)fprintf(stderr, "Color support not compiled in.\n"); #endif diff --git a/bin/ls/print.c b/bin/ls/print.c index e1925caf1929..34744087621d 100644 --- a/bin/ls/print.c +++ b/bin/ls/print.c @@ -352,22 +352,20 @@ printtype(mode) } #ifdef COLORLS -static char tcapbuf[512]; void printcolor(c) Colors c; { - char *bp = tcapbuf; char *ansiseq; if (colors[c][0] != -1) { - ansiseq = tparm(tgetstr("AF", &bp), colors[c][0]); + ansiseq = tparm(ansi_fgcol, colors[c][0]); if (ansiseq) putp(ansiseq); } if (colors[c][1] != -1) { - ansiseq = tparm(tgetstr("AB", &bp), colors[c][1]); + ansiseq = tparm(ansi_bgcol, colors[c][1]); if (ansiseq) putp(ansiseq); } @@ -376,11 +374,8 @@ printcolor(c) void endcolor() { - char *bp = tcapbuf; - char *ansiseq; - ansiseq = tgetstr("se", &bp); - if (ansiseq) - putp(ansiseq); + if (ansi_coloff) + putp(ansi_coloff); } int |
