1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-06 09:17:25 +00:00

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
This commit is contained in:
Josef Karthauser 2000-08-12 22:40:14 +00:00
parent 88c75941e6
commit 3d2ddc9e1a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=64568
2 changed files with 54 additions and 44 deletions

View File

@ -43,7 +43,7 @@
.Nd list directory contents
.Sh SYNOPSIS
.Nm ls
.Op Fl ABCFGHLPRTWabcdfgiklnoqrstu1
.Op Fl ABCFHLPRTWabcdfgiklnoqrstu1
.Op Ar file ...
.Sh DESCRIPTION
For each operand that names a
@ -91,29 +91,8 @@ a percent sign (%) after each whiteout,
and a vertical bar (|) after each that is a
.Tn FIFO .
.It Fl G
Use
.Tn ANSI
color sequences to distinguish file types.
See
.Ev LSCOLORS
below.
In addition to those mentioned above in
.Fl F ,
some extra attributes (setuid bit set, etc.) are also displayed.
The colorization is dependent on a terminal type with the proper
.Xr termcap 5
capabilities.
The default
.Dq cons25
console has the proper capabilities,
however if you want to display the colors in an
.Xr xterm 1
for example,
you need to set your
.Ev TERM
variable to
.Dq xterm-color .
Other terminal types may require similar adjustments.
This flag has been depricated. Please use the
.Ev CLICOLOR environment variable instead.
.It Fl H
Symbolic links on the command line are followed. This option is assumed if
none of the
@ -393,6 +372,33 @@ is set, the block counts
(see
.Fl s )
will be displayed in units of that size block.
.It Ev CLICOLOR
Use
.Tn ANSI
color sequences to distinguish file types.
See
.Ev LSCOLORS
below.
In addition to the file types mentioned in the
.Fl F
option some extra attributes (setuid bit set, etc.) are also displayed.
The colorization is dependent on a terminal type with the proper
.Xr termcap 5
capabilities.
The default
.Dq cons25
console has the proper capabilities,
however if you want to display the colors in an
.Xr xterm 1
for example,
you need to set your
.Ev TERM
variable to
.Dq xterm-color .
Other terminal types may require similar adjustments.
.It Ev CLICOLOR_FORCE
Color sequences are normally disabled if the output isn't directed to
a color capable terminal. This can be overridden by setting this flag.
.It Ev COLUMNS
If this variable contains a string representing a
decimal integer, it is used as the
@ -414,9 +420,8 @@ See
for more information.
.It Ev LSCOLORS
The value of this variable describes what color to use for which
attribute when the color output
.Pq Fl G
is specified.
attribute when colors are enabled with
.Ev CLICOLOR.
This string is a concatenation of pairs of the format
.Sy fb ,
where
@ -494,8 +499,8 @@ in order: inode, block count, number of links, user name,
group name, flags, file size, file name.
.It Ev TERM
The
.Fl G
option depends on a terminal type with color capabilities.
.Ev CLICOLOR
functionality depends on a terminal type with color capabilities.
.It Ev TZ
The timezone to use when displaying dates.
See

View File

@ -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: