From 483297d5ddaea930d61da1da9c3f052cbd3c3810 Mon Sep 17 00:00:00 2001
From: Ed Avis <ed@membled.com>
Date: Tue, 12 Feb 2008 12:22:35 +0100
Subject: ls --color no longer outputs unnecessary escape sequences

In --color mode, plain files do not get any color, not even white.
When no highlighting is required, ls outputs no escape sequence at all.
* src/ls.c (print_with_color):
(used_color): New global.
(indicator_no) [C_RESET]: New enum value.
(indicator_name) ["rs"]: Corresponding new string.
(color_indicator): Make the 'normal' and 'file' markers be NULL.
Use "rs" (C_RESET) to reset to ordinary colors.
(process_signals): Restore default colors only if necessary.
(main): Don't call prep_non_filename_text here.
(print_name_with_quoting): Call it here, instead.
(prep_non_filename_text): Use C_RESET, not C_NORM.
(print_color_indicator): Return bool, not void.
Print nothing, when possible.
(put_indicator): Call prep_non_filename_text the first time.
* tests/misc/ls-misc: Test for above.
* tests/ls/color-dtype-dir: Adapt: no escapes around regular file name.
* TODO: Remove item.
* NEWS: Mention this.
---
 tests/misc/ls-misc | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

(limited to 'tests/misc')

diff --git a/tests/misc/ls-misc b/tests/misc/ls-misc
index 9290eb4d7..4182fa1f9 100755
--- a/tests/misc/ls-misc
+++ b/tests/misc/ls-misc
@@ -1,7 +1,7 @@
 #!/bin/sh
 # -*- perl -*-
 
-# Copyright (C) 1998, 2000-2007 Free Software Foundation, Inc.
+# Copyright (C) 1998, 2000-2008 Free Software Foundation, Inc.
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -55,8 +55,14 @@ system (qq(touch setuid && chmod u+s setuid && $test -u setuid &&
   or (warn "$program_name: cannot create setuid/setgid/sticky files,"
       . "so can't run this test\n"), exit 77;
 
-my $mkdir = {PRE => sub {mkdir 'd',0755 or die "d: $!\n"}};
-my $rmdir = {POST => sub {rmdir 'd' or die "d: $!\n"}};
+sub mkdir_d {mkdir 'd',0755 or die "d: $!\n"}
+sub rmdir_d {rmdir 'd'      or die "d: $!\n"}
+my $mkdir = {PRE => sub {mkdir_d}};
+my $rmdir = {POST => sub {rmdir_d}};
+my $mkdir_reg = {PRE => sub {mkdir_d; open (FH, '>d/f') && close FH
+			       or die "d/f: $!\n" }};
+my $rmdir_reg = {POST => sub {unlink 'd/f' or die "d/f: $!\n";
+			      rmdir 'd' or die "d: $!\n"}};
 
 my $mkdir2 = {PRE => sub {mkdir 'd',0755 or die "d: $!\n";
 			  mkdir 'd/e',0755 or die "d/e: $!\n" }};
@@ -132,6 +138,11 @@ my @Tests =
 				 {OUT => "\e[0m\e[01;36md\e[0m\@\n\e[m"},
 				  $slink_d, $unlink_d],
 
+     # A listing with no output should have no color sequences at all.
+     ['no-c-empty', '--color=always d', {OUT => ""}, $mkdir, $rmdir],
+     # A listing with only regular files should have no color sequences at all.
+     ['no-c-reg', '--color=always d', {OUT => "f\n"}, $mkdir_reg, $rmdir_reg],
+
      # Test for a bug fixed after coreutils-6.9.
      ['sl-target', '--color=always d',
       {OUT => "\e[0m\e[01;34mX\e[0m\n\e[m"}, $target, $target2],
-- 
cgit v1.2.3-70-g09d2