diff options
author | joe <joe@FreeBSD.org> | 2000-08-12 22:40:14 +0000 |
---|---|---|
committer | joe <joe@FreeBSD.org> | 2000-08-12 22:40:14 +0000 |
commit | 4ab486798ec3907ec0d18962dcd76f75dcca2112 (patch) | |
tree | 6f6471340a04c3cc7448bd7aa00985d4382b73b8 /bin/ls/ls.c | |
parent | 002ef51d6eb85e40acd7d5111adaccddc33e3880 (diff) | |
download | FreeBSD-src-4ab486798ec3907ec0d18962dcd76f75dcca2112.zip FreeBSD-src-4ab486798ec3907ec0d18962dcd76f75dcca2112.tar.gz |
A change to the way that colours are switched on in ls. The -G
flag has been depricated, although it still works with a warning
message, and replaced with an environment variable CLICOLOR (command
line interface colour). This could be used by other tools that
want to be able to control colour output.
In addition if the environment variable CLICOLOR_FORCE is defined
colour sequences are output irrespective of whether the output is
directed to a terminal (as long as TERM references a colour capable
terminal of course ;)
PR: bin/20291 and bin/20483
Diffstat (limited to 'bin/ls/ls.c')
-rw-r--r-- | bin/ls/ls.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/bin/ls/ls.c b/bin/ls/ls.c index 4b48ef9..87cea23 100644 --- a/bin/ls/ls.c +++ b/bin/ls/ls.c @@ -202,23 +202,11 @@ main(argc, argv) fts_options |= FTS_COMFOLLOW; break; case 'G': - if (isatty(STDOUT_FILENO)) #ifdef COLORLS - 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; - } + (void)fprintf(stderr, "The -G flag is depricated, please define CLICOLOR instead.\n"); + setenv("CLICOLOR", "", 1); #else - (void)fprintf(stderr, "Color support not compiled in.\n"); + (void)fprintf(stderr, "Color support not compiled in.\n"); #endif break; case 'L': @@ -295,6 +283,23 @@ main(argc, argv) argv += optind; #ifdef COLORLS + /* Enabling of colours is conditional on the environment. */ + if (getenv("CLICOLOR") && + (isatty(STDOUT_FILENO) || getenv("CLICOLOR_FORCE"))) + 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; + } + if (f_color) { /* * We can't put tabs and color sequences together: |