|
15 | 15 | # You should have received a copy of the GNU General Public License
|
16 | 16 | # along with this program. If not, see http://www.gnu.org/licenses/ .
|
17 | 17 |
|
18 |
| -# Keep the original TERM for say_color |
19 |
| -ORIGINAL_TERM=$TERM |
20 |
| - |
21 | 18 | # Test the binaries we have just built. The tests are kept in
|
22 | 19 | # t/ subdirectory and are run in 'trash directory' subdirectory.
|
23 | 20 | if test -z "$TEST_DIRECTORY"
|
@@ -68,12 +65,12 @@ done,*)
|
68 | 65 | esac
|
69 | 66 |
|
70 | 67 | # For repeatability, reset the environment to known value.
|
| 68 | +# TERM is sanitized below, after saving color control sequences. |
71 | 69 | LANG=C
|
72 | 70 | LC_ALL=C
|
73 | 71 | PAGER=cat
|
74 | 72 | TZ=UTC
|
75 |
| -TERM=dumb |
76 |
| -export LANG LC_ALL PAGER TERM TZ |
| 73 | +export LANG LC_ALL PAGER TZ |
77 | 74 | EDITOR=:
|
78 | 75 | # A call to "unset" with no arguments causes at least Solaris 10
|
79 | 76 | # /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets
|
@@ -181,8 +178,14 @@ export _x05 _x40 _z40 LF u200c
|
181 | 178 | # This test checks if command xyzzy does the right thing...
|
182 | 179 | # '
|
183 | 180 | # . ./test-lib.sh
|
| 181 | +test "x$TERM" != "xdumb" && ( |
| 182 | + test -t 1 && |
| 183 | + tput bold >/dev/null 2>&1 && |
| 184 | + tput setaf 1 >/dev/null 2>&1 && |
| 185 | + tput sgr0 >/dev/null 2>&1 |
| 186 | + ) && |
| 187 | + color=t |
184 | 188 |
|
185 |
| -unset color |
186 | 189 | while test "$#" -ne 0
|
187 | 190 | do
|
188 | 191 | case "$1" in
|
@@ -253,6 +256,44 @@ then
|
253 | 256 | verbose=t
|
254 | 257 | fi
|
255 | 258 |
|
| 259 | +if test -n "$color" |
| 260 | +then |
| 261 | + # Save the color control sequences now rather than run tput |
| 262 | + # each time say_color() is called. This is done for two |
| 263 | + # reasons: |
| 264 | + # * TERM will be changed to dumb |
| 265 | + # * HOME will be changed to a temporary directory and tput |
| 266 | + # might need to read ~/.terminfo from the original HOME |
| 267 | + # directory to get the control sequences |
| 268 | + # Note: This approach assumes the control sequences don't end |
| 269 | + # in a newline for any terminal of interest (command |
| 270 | + # substitutions strip trailing newlines). Given that most |
| 271 | + # (all?) terminals in common use are related to ECMA-48, this |
| 272 | + # shouldn't be a problem. |
| 273 | + say_color_error=$(tput bold; tput setaf 1) # bold red |
| 274 | + say_color_skip=$(tput setaf 4) # blue |
| 275 | + say_color_warn=$(tput setaf 3) # brown/yellow |
| 276 | + say_color_pass=$(tput setaf 2) # green |
| 277 | + say_color_info=$(tput setaf 6) # cyan |
| 278 | + say_color_reset=$(tput sgr0) |
| 279 | + say_color_="" # no formatting for normal text |
| 280 | + say_color () { |
| 281 | + test -z "$1" && test -n "$quiet" && return |
| 282 | + eval "say_color_color=\$say_color_$1" |
| 283 | + shift |
| 284 | + printf "%s\\n" "$say_color_color$*$say_color_reset" |
| 285 | + } |
| 286 | +else |
| 287 | + say_color() { |
| 288 | + test -z "$1" && test -n "$quiet" && return |
| 289 | + shift |
| 290 | + printf "%s\n" "$*" |
| 291 | + } |
| 292 | +fi |
| 293 | + |
| 294 | +TERM=dumb |
| 295 | +export TERM |
| 296 | + |
256 | 297 | error () {
|
257 | 298 | say_color error "error: $*"
|
258 | 299 | GIT_EXIT_OK=t
|
@@ -829,52 +870,6 @@ HOME="$TRASH_DIRECTORY"
|
829 | 870 | GNUPGHOME="$HOME/gnupg-home-not-used"
|
830 | 871 | export HOME GNUPGHOME
|
831 | 872 |
|
832 |
| -# run the tput tests *after* changing HOME (in case ncurses needs |
833 |
| -# ~/.terminfo for $TERM) |
834 |
| -test -n "${color+set}" || test "x$ORIGINAL_TERM" != "xdumb" && ( |
835 |
| - TERM=$ORIGINAL_TERM && |
836 |
| - export TERM && |
837 |
| - test -t 1 && |
838 |
| - tput bold >/dev/null 2>&1 && |
839 |
| - tput setaf 1 >/dev/null 2>&1 && |
840 |
| - tput sgr0 >/dev/null 2>&1 |
841 |
| - ) && |
842 |
| - color=t |
843 |
| - |
844 |
| -if test -n "$color" |
845 |
| -then |
846 |
| - say_color () { |
847 |
| - ( |
848 |
| - TERM=$ORIGINAL_TERM |
849 |
| - export TERM |
850 |
| - case "$1" in |
851 |
| - error) |
852 |
| - tput bold; tput setaf 1;; # bold red |
853 |
| - skip) |
854 |
| - tput setaf 4;; # blue |
855 |
| - warn) |
856 |
| - tput setaf 3;; # brown/yellow |
857 |
| - pass) |
858 |
| - tput setaf 2;; # green |
859 |
| - info) |
860 |
| - tput setaf 6;; # cyan |
861 |
| - *) |
862 |
| - test -n "$quiet" && return;; |
863 |
| - esac |
864 |
| - shift |
865 |
| - printf "%s" "$*" |
866 |
| - tput sgr0 |
867 |
| - echo |
868 |
| - ) |
869 |
| - } |
870 |
| -else |
871 |
| - say_color() { |
872 |
| - test -z "$1" && test -n "$quiet" && return |
873 |
| - shift |
874 |
| - printf "%s\n" "$*" |
875 |
| - } |
876 |
| -fi |
877 |
| - |
878 | 873 | if test -z "$TEST_NO_CREATE_REPO"
|
879 | 874 | then
|
880 | 875 | test_create_repo "$TRASH_DIRECTORY"
|
|
0 commit comments