# [PATCH/RFC] test-lib: add support for colors without tput

17 messages from 2012-09-14 to 2012-09-17. Participants: Erik Faye-Lund, Elia Pinto, Johannes Sixt, Junio C Hamano, Jeff King.
Thread: https://gitlist.dev/t/31532

## Erik Faye-Lund, 2012-09-14 16:41

Subject: [PATCH/RFC] test-lib: add support for colors without tput
Message-ID: <1347640905-1400-1-git-send-email-kusmabite@gmail.com>
URL: https://gitlist.dev/e/1347640905-1400-1-git-send-email-kusmabite%40gmail.com

```
For platforms that does not have tput we can still perform coloring
by manually emitting the ANSI control codes. If tput is missing from
$PATH, install a replacement function.

The exact strings has been dumped from a machine that has tput, by
piping the output of tput through 'od -c -An'.

Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
---

I got slightly annoyed that we didn't get colored output from the
tests on Windows, so I decided to fix it.

Hopefully other platforms can benefit from this as well.

I'm not super happy with the condition to enable it. I considered
an environment variable as well, but decided against it because
"make -C t" from the root does not seem to pick up environment
variables configured in the main Makefile.

Thoughts?

 t/test-lib.sh | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/t/test-lib.sh b/t/test-lib.sh
index 78c4286..7d1b34b 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -129,6 +129,20 @@ export _x05 _x40 _z40 LF
 # This test checks if command xyzzy does the right thing...
 # '
 # . ./test-lib.sh
+
+if ! which tput > /dev/null ; then
+	tput () {
+		case "$1" in
+		bold)
+			echo -ne "\033[1m" ;;
+		setaf)
+			echo -ne "\033[0;3$2m" ;;
+		sgr0)
+			echo -ne "\033(\033[m" ;;
+		esac
+	}
+fi
+
 [ "x$ORIGINAL_TERM" != "xdumb" ] && (
 		TERM=$ORIGINAL_TERM &&
 		export TERM &&
-- 
1.7.11.msysgit.0.5.g0225efe.dirty

-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

```

## Erik Faye-Lund, 2012-09-14 16:54

Subject: Re: [PATCH/RFC] test-lib: add support for colors without tput
Message-ID: <CABPQNSa1hEG_rB9hd8izW+iL1TQVAKu5W1=GbG20ROv-+DMgVg@mail.gmail.com>
URL: https://gitlist.dev/e/CABPQNSa1hEG_rB9hd8izW%2BiL1TQVAKu5W1%3DGbG20ROv-%2BDMgVg%40mail.gmail.com
In-Reply-To: <1347640905-1400-1-git-send-email-kusmabite@gmail.com>

```
On Fri, Sep 14, 2012 at 6:41 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 78c4286..7d1b34b 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -129,6 +129,20 @@ export _x05 _x40 _z40 LF
>  # This test checks if command xyzzy does the right thing...
>  # '
>  # . ./test-lib.sh
> +
> +if ! which tput > /dev/null ; then
> +       tput () {
> +               case "$1" in
> +               bold)
> +                       echo -ne "\033[1m" ;;
> +               setaf)
> +                       echo -ne "\033[0;3$2m" ;;
> +               sgr0)
> +                       echo -ne "\033(\033[m" ;;

I should of course have checked this earlier, but I find now that
"echo -ne" isn't portable. So perhaps this on top?

diff --git a/t/test-lib.sh b/t/test-lib.sh
index 7d1b34b..91a1d7b 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -134,11 +134,11 @@ if ! which tput > /dev/null ; then
 	tput () {
 		case "$1" in
 		bold)
-			echo -ne "\033[1m" ;;
+			printf "%b" "\033[1m" ;;
 		setaf)
-			echo -ne "\033[0;3$2m" ;;
+			printf "%b" "\033[0;3$2m" ;;
 		sgr0)
-			echo -ne "\033(\033[m" ;;
+			printf "%b" "\033(\033[m" ;;
 		esac
 	}
 fi

-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

```

## Erik Faye-Lund, 2012-09-14 16:58

Subject: Re: [PATCH/RFC] test-lib: add support for colors without tput
Message-ID: <CABPQNSaArMz8hTiNZyD__K8bjntUuFUvk7Ojpu6NeXWLkJSUiA@mail.gmail.com>
URL: https://gitlist.dev/e/CABPQNSaArMz8hTiNZyD__K8bjntUuFUvk7Ojpu6NeXWLkJSUiA%40mail.gmail.com
In-Reply-To: <CABPQNSa1hEG_rB9hd8izW+iL1TQVAKu5W1=GbG20ROv-+DMgVg@mail.gmail.com>

```
On Fri, Sep 14, 2012 at 6:54 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:
> On Fri, Sep 14, 2012 at 6:41 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:
>> diff --git a/t/test-lib.sh b/t/test-lib.sh
>> index 78c4286..7d1b34b 100644
>> --- a/t/test-lib.sh
>> +++ b/t/test-lib.sh
>> @@ -129,6 +129,20 @@ export _x05 _x40 _z40 LF
>>  # This test checks if command xyzzy does the right thing...
>>  # '
>>  # . ./test-lib.sh
>> +
>> +if ! which tput > /dev/null ; then
>> +       tput () {
>> +               case "$1" in
>> +               bold)
>> +                       echo -ne "\033[1m" ;;
>> +               setaf)
>> +                       echo -ne "\033[0;3$2m" ;;
>> +               sgr0)
>> +                       echo -ne "\033(\033[m" ;;
>
> I should of course have checked this earlier, but I find now that
> "echo -ne" isn't portable. So perhaps this on top?
>
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 7d1b34b..91a1d7b 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -134,11 +134,11 @@ if ! which tput > /dev/null ; then
>         tput () {
>                 case "$1" in
>                 bold)
> -                       echo -ne "\033[1m" ;;
> +                       printf "%b" "\033[1m" ;;
>                 setaf)
> -                       echo -ne "\033[0;3$2m" ;;
> +                       printf "%b" "\033[0;3$2m" ;;
>                 sgr0)
> -                       echo -ne "\033(\033[m" ;;
> +                       printf "%b" "\033(\033[m" ;;
>                 esac
>         }
>  fi

And again, I'm stupid for not reading documentation properly; octal
escaped strings in the format string should work (and does on my
systems), so this is sufficient:

diff --git a/t/test-lib.sh b/t/test-lib.sh
index 7d1b34b..2a6149e 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -134,11 +134,11 @@ if ! which tput > /dev/null ; then
 	tput () {
 		case "$1" in
 		bold)
-			echo -ne "\033[1m" ;;
+			printf "\033[1m" ;;
 		setaf)
-			echo -ne "\033[0;3$2m" ;;
+			printf "\033[0;3$2m" ;;
 		sgr0)
-			echo -ne "\033(\033[m" ;;
+			printf "\033(\033[m" ;;
 		esac
 	}
 fi

-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

```

## Elia Pinto, 2012-09-14 17:08

Subject: Re: [PATCH/RFC] test-lib: add support for colors without tput
Message-ID: <CA+EOSBm4cSu8cxPc-3Eqm0J7deeht6FMMUGBKP6vx8VDcVrGPQ@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BEOSBm4cSu8cxPc-3Eqm0J7deeht6FMMUGBKP6vx8VDcVrGPQ%40mail.gmail.com
In-Reply-To: <CABPQNSaArMz8hTiNZyD__K8bjntUuFUvk7Ojpu6NeXWLkJSUiA@mail.gmail.com>

```
2012/9/14 Erik Faye-Lund <kusmabite@gmail.com>:
> On Fri, Sep 14, 2012 at 6:54 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:
>> On Fri, Sep 14, 2012 at 6:41 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:
>>> diff --git a/t/test-lib.sh b/t/test-lib.sh
>>> index 78c4286..7d1b34b 100644
>>> --- a/t/test-lib.sh
>>> +++ b/t/test-lib.sh
>>> @@ -129,6 +129,20 @@ export _x05 _x40 _z40 LF
>>>  # This test checks if command xyzzy does the right thing...
>>>  # '
>>>  # . ./test-lib.sh
>>> +
Nice. But this setting should be check that we have a terminal first isn't ?
Some test like this before

test "X$$TERM" != Xdumb \
&&  test -t 1 2>/dev/null  \
&& ....

or the inverse logic. This is what automake  and popt autogen.sh does.

Best Regards

```

## Erik Faye-Lund, 2012-09-14 17:11

Subject: Re: [PATCH/RFC] test-lib: add support for colors without tput
Message-ID: <CABPQNSZSQCvoD=n-iQPSHbUQ2S4c0P1VTZfiHkRcwpm=7dk5Vg@mail.gmail.com>
URL: https://gitlist.dev/e/CABPQNSZSQCvoD%3Dn-iQPSHbUQ2S4c0P1VTZfiHkRcwpm%3D7dk5Vg%40mail.gmail.com
In-Reply-To: <CA+EOSBm4cSu8cxPc-3Eqm0J7deeht6FMMUGBKP6vx8VDcVrGPQ@mail.gmail.com>

```
On Fri, Sep 14, 2012 at 7:08 PM, Elia Pinto <gitter.spiros@gmail.com> wrote:
> 2012/9/14 Erik Faye-Lund <kusmabite@gmail.com>:
>> On Fri, Sep 14, 2012 at 6:54 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:
>>> On Fri, Sep 14, 2012 at 6:41 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:
>>>> diff --git a/t/test-lib.sh b/t/test-lib.sh
>>>> index 78c4286..7d1b34b 100644
>>>> --- a/t/test-lib.sh
>>>> +++ b/t/test-lib.sh
>>>> @@ -129,6 +129,20 @@ export _x05 _x40 _z40 LF
>>>>  # This test checks if command xyzzy does the right thing...
>>>>  # '
>>>>  # . ./test-lib.sh
>>>> +
> Nice. But this setting should be check that we have a terminal first isn't ?
> Some test like this before
>
> test "X$$TERM" != Xdumb \
> &&  test -t 1 2>/dev/null  \
> && ....
>
> or the inverse logic. This is what automake  and popt autogen.sh does.

There's already such a check a few lines further down, and tput isn't
used in such cases.

-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

```

## Elia Pinto, 2012-09-14 17:12

Subject: Re: [PATCH/RFC] test-lib: add support for colors without tput
Message-ID: <CA+EOSBki2syrwdfzFXzBPuJAhH2jfgAbL=W+yP7bx8WXMkYiMQ@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BEOSBki2syrwdfzFXzBPuJAhH2jfgAbL%3DW%2ByP7bx8WXMkYiMQ%40mail.gmail.com
In-Reply-To: <CA+EOSBm4cSu8cxPc-3Eqm0J7deeht6FMMUGBKP6vx8VDcVrGPQ@mail.gmail.com>

```
2012/9/14 Elia Pinto <gitter.spiros@gmail.com>:
> 2012/9/14 Erik Faye-Lund <kusmabite@gmail.com>:
>> On Fri, Sep 14, 2012 at 6:54 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:
>>> On Fri, Sep 14, 2012 at 6:41 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:
>>>> diff --git a/t/test-lib.sh b/t/test-lib.sh
>>>> index 78c4286..7d1b34b 100644
>>>> --- a/t/test-lib.sh
>>>> +++ b/t/test-lib.sh
>>>> @@ -129,6 +129,20 @@ export _x05 _x40 _z40 LF
>>>>  # This test checks if command xyzzy does the right thing...
>>>>  # '
>>>>  # . ./test-lib.sh
>>>> +
> Nice. But this setting should be check that we have a terminal first isn't ?
> Some test like this before
>
> test "X$$TERM" != Xdumb \
> &&  test -t 1 2>/dev/null  \
> && ....
and in reality this echo use is not portable.
http://ftp.gnu.org/old-gnu/Manuals/autoconf-2.53/html_node/Limitations-of-Builtins.html

In popt 1_17 autogen.sh does

red=; grn=; lgn=; blu=; std=;
test "X$$TERM" != Xdumb \
&&  test -t 1 2>/dev/null  \
&& { \
  red='^[[0;31m'; \
  grn='^[[0;32m'; \
  lgn='^[[1;32m'; \
  blu='^[[1;34m'; \
  std='^[[m'; \
}

and

Die()    {
        color="$red"
        echo "${color}${_PROGNAME}: Error: $@${std}" >&2
        exit 1
}

Die "message here"


>
> or the inverse logic. This is what automake  and popt autogen.sh does.
>
> Best Regards

-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

```

## Erik Faye-Lund, 2012-09-14 17:16

Subject: Re: [PATCH/RFC] test-lib: add support for colors without tput
Message-ID: <CABPQNSYu1mAxn_ZKqgM6xcsgJfegu=upv0QQpFryMVrEH+KAsw@mail.gmail.com>
URL: https://gitlist.dev/e/CABPQNSYu1mAxn_ZKqgM6xcsgJfegu%3Dupv0QQpFryMVrEH%2BKAsw%40mail.gmail.com
In-Reply-To: <CA+EOSBki2syrwdfzFXzBPuJAhH2jfgAbL=W+yP7bx8WXMkYiMQ@mail.gmail.com>

```
On Fri, Sep 14, 2012 at 7:12 PM, Elia Pinto <gitter.spiros@gmail.com> wrote:
> 2012/9/14 Elia Pinto <gitter.spiros@gmail.com>:
>> 2012/9/14 Erik Faye-Lund <kusmabite@gmail.com>:
>>> On Fri, Sep 14, 2012 at 6:54 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:
>>>> On Fri, Sep 14, 2012 at 6:41 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:
>>>>> diff --git a/t/test-lib.sh b/t/test-lib.sh
>>>>> index 78c4286..7d1b34b 100644
>>>>> --- a/t/test-lib.sh
>>>>> +++ b/t/test-lib.sh
>>>>> @@ -129,6 +129,20 @@ export _x05 _x40 _z40 LF
>>>>>  # This test checks if command xyzzy does the right thing...
>>>>>  # '
>>>>>  # . ./test-lib.sh
>>>>> +
>> Nice. But this setting should be check that we have a terminal first isn't ?
>> Some test like this before
>>
>> test "X$$TERM" != Xdumb \
>> &&  test -t 1 2>/dev/null  \
>> && ....
> and in reality this echo use is not portable.

Yeah; I posted a couple of follow-up mails earlier where I had noticed
it and changed to printf instead. It seems the testsuite is already
using it, so it's probably portable.

Thanks a lot for the extra set of eyes :)

-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

```

## Johannes Sixt, 2012-09-14 17:28

Subject: Re: Re: [PATCH/RFC] test-lib: add support for colors without tput
Message-ID: <50536943.4030300@kdbg.org>
URL: https://gitlist.dev/e/50536943.4030300%40kdbg.org
In-Reply-To: <CABPQNSaArMz8hTiNZyD__K8bjntUuFUvk7Ojpu6NeXWLkJSUiA@mail.gmail.com>

```
Am 14.09.2012 18:58, schrieb Erik Faye-Lund:
>  	tput () {
>  		case "$1" in
>  		bold)
> -			echo -ne "\033[1m" ;;
> +			printf "\033[1m" ;;
>  		setaf)
> -			echo -ne "\033[0;3$2m" ;;
> +			printf "\033[0;3$2m" ;;

This should be
			printf '\033[0;3%sm' "$2" ;;

>  		sgr0)
> -			echo -ne "\033(\033[m" ;;
> +			printf "\033(\033[m" ;;
>  		esac
>  	}
>  fi

Did you test this only in rxvt or in CMD as well? (I hadn't time to
test, yet, so I'm asking :-)

-- Hannes

-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

```

## Junio C Hamano, 2012-09-14 17:30

Subject: Re: [PATCH/RFC] test-lib: add support for colors without tput
Message-ID: <7va9ws5x6w.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7va9ws5x6w.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CABPQNSa1hEG_rB9hd8izW+iL1TQVAKu5W1=GbG20ROv-+DMgVg@mail.gmail.com>

```
Erik Faye-Lund <kusmabite@gmail.com> writes:

> On Fri, Sep 14, 2012 at 6:41 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:
>> diff --git a/t/test-lib.sh b/t/test-lib.sh
>> index 78c4286..7d1b34b 100644
>> --- a/t/test-lib.sh
>> +++ b/t/test-lib.sh
>> @@ -129,6 +129,20 @@ export _x05 _x40 _z40 LF
>>  # This test checks if command xyzzy does the right thing...
>>  # '
>>  # . ./test-lib.sh
>> +
>> +if ! which tput > /dev/null ; then
>> +       tput () {
>> +               case "$1" in
>> +               bold)
>> +                       echo -ne "\033[1m" ;;
>> +               setaf)
>> +                       echo -ne "\033[0;3$2m" ;;
>> +               sgr0)
>> +                       echo -ne "\033(\033[m" ;;
>
> I should of course have checked this earlier, but I find now that
> "echo -ne" isn't portable.

Neither is which, no?

-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

```

## Erik Faye-Lund, 2012-09-14 17:31

Subject: Re: Re: [PATCH/RFC] test-lib: add support for colors without tput
Message-ID: <CABPQNSbKWb-tWqFBtBCenJNDE6oVLyCbspoK+vLYj9yD6ZraWQ@mail.gmail.com>
URL: https://gitlist.dev/e/CABPQNSbKWb-tWqFBtBCenJNDE6oVLyCbspoK%2BvLYj9yD6ZraWQ%40mail.gmail.com
In-Reply-To: <50536943.4030300@kdbg.org>

```
On Fri, Sep 14, 2012 at 7:28 PM, Johannes Sixt <j6t@kdbg.org> wrote:
> Am 14.09.2012 18:58, schrieb Erik Faye-Lund:
>>       tput () {
>>               case "$1" in
>>               bold)
>> -                     echo -ne "\033[1m" ;;
>> +                     printf "\033[1m" ;;
>>               setaf)
>> -                     echo -ne "\033[0;3$2m" ;;
>> +                     printf "\033[0;3$2m" ;;
>
> This should be
>                         printf '\033[0;3%sm' "$2" ;;
>

That's probably a good idea, yeah.

>>               sgr0)
>> -                     echo -ne "\033(\033[m" ;;
>> +                     printf "\033(\033[m" ;;
>>               esac
>>       }
>>  fi
>
> Did you test this only in rxvt or in CMD as well? (I hadn't time to
> test, yet, so I'm asking :-)

I don't have rxvt installed, but it works for me in CMD also.

-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

```

## Erik Faye-Lund, 2012-09-14 17:42

Subject: Re: [PATCH/RFC] test-lib: add support for colors without tput
Message-ID: <CABPQNSb=j=TtZVm4tzR6HE+Fhh=Aa6GSnmaysLNBQTbtSie4Mg@mail.gmail.com>
URL: https://gitlist.dev/e/CABPQNSb%3Dj%3DTtZVm4tzR6HE%2BFhh%3DAa6GSnmaysLNBQTbtSie4Mg%40mail.gmail.com
In-Reply-To: <7va9ws5x6w.fsf@alter.siamese.dyndns.org>

```
On Fri, Sep 14, 2012 at 7:30 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Erik Faye-Lund <kusmabite@gmail.com> writes:
>
>> On Fri, Sep 14, 2012 at 6:41 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:
>>> diff --git a/t/test-lib.sh b/t/test-lib.sh
>>> index 78c4286..7d1b34b 100644
>>> --- a/t/test-lib.sh
>>> +++ b/t/test-lib.sh
>>> @@ -129,6 +129,20 @@ export _x05 _x40 _z40 LF
>>>  # This test checks if command xyzzy does the right thing...
>>>  # '
>>>  # . ./test-lib.sh
>>> +
>>> +if ! which tput > /dev/null ; then
>>> +       tput () {
>>> +               case "$1" in
>>> +               bold)
>>> +                       echo -ne "\033[1m" ;;
>>> +               setaf)
>>> +                       echo -ne "\033[0;3$2m" ;;
>>> +               sgr0)
>>> +                       echo -ne "\033(\033[m" ;;
>>
>> I should of course have checked this earlier, but I find now that
>> "echo -ne" isn't portable.
>
> Neither is which, no?

Oooh, right. Thanks for noticing. So I guess I should try to run it
instead. From the POSIX spec, I can't find a way of running it that
guarantees a return-code of 0 without clobbering the console somehow.

Perhaps the best thing is pass no operands, and check for $? == 127 instead?

Something like this?

diff --git a/t/test-lib.sh b/t/test-lib.sh
index a939e19..1433cb3 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -130,7 +130,8 @@ export _x05 _x40 _z40 LF
 # '
 # . ./test-lib.sh

-if ! which tput > /dev/null ; then
+tput > /dev/null
+if test $? -eq 127 ; then
 	tput () {
 		case "$1" in
 		bold)

-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

```

## Jeff King, 2012-09-14 17:44

Subject: Re: [PATCH/RFC] test-lib: add support for colors without tput
Message-ID: <20120914174439.GA16657@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20120914174439.GA16657%40sigill.intra.peff.net
In-Reply-To: <1347640905-1400-1-git-send-email-kusmabite@gmail.com>

```
On Fri, Sep 14, 2012 at 06:41:45PM +0200, Erik Faye-Lund wrote:

> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 78c4286..7d1b34b 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -129,6 +129,20 @@ export _x05 _x40 _z40 LF
>  # This test checks if command xyzzy does the right thing...
>  # '
>  # . ./test-lib.sh
> +
> +if ! which tput > /dev/null ; then

Testing the return value of "which" is not portable (I know, it's
insane; SunOS is the common offender). Use "type" instead.

-Peff

-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

```

## Erik Faye-Lund, 2012-09-14 17:52

Subject: Re: [PATCH/RFC] test-lib: add support for colors without tput
Message-ID: <CABPQNSYzSzMrmY4Jto+xig2BRL-P0xJDcUiBV8TtV3Ehd1DD_w@mail.gmail.com>
URL: https://gitlist.dev/e/CABPQNSYzSzMrmY4Jto%2Bxig2BRL-P0xJDcUiBV8TtV3Ehd1DD_w%40mail.gmail.com
In-Reply-To: <20120914174439.GA16657@sigill.intra.peff.net>

```
On Fri, Sep 14, 2012 at 7:44 PM, Jeff King <peff@peff.net> wrote:
> On Fri, Sep 14, 2012 at 06:41:45PM +0200, Erik Faye-Lund wrote:
>
>> diff --git a/t/test-lib.sh b/t/test-lib.sh
>> index 78c4286..7d1b34b 100644
>> --- a/t/test-lib.sh
>> +++ b/t/test-lib.sh
>> @@ -129,6 +129,20 @@ export _x05 _x40 _z40 LF
>>  # This test checks if command xyzzy does the right thing...
>>  # '
>>  # . ./test-lib.sh
>> +
>> +if ! which tput > /dev/null ; then
>
> Testing the return value of "which" is not portable (I know, it's
> insane; SunOS is the common offender). Use "type" instead.

Junio already noticed it, and I suggested a fix that involved running
it. However, I like your fix much better, thanks :)

-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

```

## Junio C Hamano, 2012-09-14 18:03

Subject: Re: [PATCH/RFC] test-lib: add support for colors without tput
Message-ID: <7vpq5o4h30.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vpq5o4h30.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CABPQNSb=j=TtZVm4tzR6HE+Fhh=Aa6GSnmaysLNBQTbtSie4Mg@mail.gmail.com>

```
Erik Faye-Lund <kusmabite@gmail.com> writes:

>> Neither is which, no?
>
> Oooh, right. Thanks for noticing. So I guess I should try to run it
> instead. From the  POSIX spec,...

If you assume POSIX.1, there is "type".

    $ type frotz ; echo $?
    frotz is /usr/games/frotz
    0
    $ type frobnitz ; echo $?
    bash: type: frobnitz: not found
    1

-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

```

## Erik Faye-Lund, 2012-09-14 18:11

Subject: Re: Re: [PATCH/RFC] test-lib: add support for colors without tput
Message-ID: <CABPQNSZeuG-J8nVH15hpsX+bkM3CPcUGBNgNOUp6AtTipSdVbQ@mail.gmail.com>
URL: https://gitlist.dev/e/CABPQNSZeuG-J8nVH15hpsX%2BbkM3CPcUGBNgNOUp6AtTipSdVbQ%40mail.gmail.com
In-Reply-To: <50536943.4030300@kdbg.org>

```
On Fri, Sep 14, 2012 at 7:28 PM, Johannes Sixt <j6t@kdbg.org> wrote:
> Am 14.09.2012 18:58, schrieb Erik Faye-Lund:
>>       tput () {
>>               case "$1" in
>>               bold)
>> -                     echo -ne "\033[1m" ;;
>> +                     printf "\033[1m" ;;
>>               setaf)
>> -                     echo -ne "\033[0;3$2m" ;;
>> +                     printf "\033[0;3$2m" ;;
>
> This should be
>                         printf '\033[0;3%sm' "$2" ;;

Is there a reason for %s rather than %d? It seem it only takes
integers, and with %d at least we'd get an error message if someone
started doing something else...

-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

```

## Johannes Sixt, 2012-09-14 19:15

Subject: Re: Re: [PATCH/RFC] test-lib: add support for colors without tput
Message-ID: <50538261.8060102@kdbg.org>
URL: https://gitlist.dev/e/50538261.8060102%40kdbg.org
In-Reply-To: <CABPQNSZeuG-J8nVH15hpsX+bkM3CPcUGBNgNOUp6AtTipSdVbQ@mail.gmail.com>

```
Am 14.09.2012 20:11, schrieb Erik Faye-Lund:
> On Fri, Sep 14, 2012 at 7:28 PM, Johannes Sixt <j6t@kdbg.org> wrote:
>>                         printf '\033[0;3%sm' "$2" ;;
> 
> Is there a reason for %s rather than %d? It seem it only takes
> integers,..

No reason. I just mechanically converted your original expression. But
there is no reason for my conversion, either, if it can be more or less
guaranteed that no arbitrary strings are passed in $2.

-- Hannes

-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

```

## Johannes Sixt, 2012-09-17 17:39

Subject: Re: [PATCH/RFC] test-lib: add support for colors without tput
Message-ID: <50576058.4020508@kdbg.org>
URL: https://gitlist.dev/e/50576058.4020508%40kdbg.org
In-Reply-To: <50536943.4030300@kdbg.org>

```
Am 14.09.2012 19:28, schrieb Johannes Sixt:
> Am 14.09.2012 18:58, schrieb Erik Faye-Lund:
>>  	tput () {
>>  		case "$1" in
>>  		bold)
>> -			echo -ne "\033[1m" ;;
>> +			printf "\033[1m" ;;
>>  		setaf)
>> -			echo -ne "\033[0;3$2m" ;;
>> +			printf "\033[0;3$2m" ;;
> 
> This should be
> 			printf '\033[0;3%sm' "$2" ;;
> 
>>  		sgr0)
>> -			echo -ne "\033(\033[m" ;;
>> +			printf "\033(\033[m" ;;
>>  		esac
>>  	}
>>  fi
> 
> Did you test this only in rxvt or in CMD as well? (I hadn't time to
> test, yet, so I'm asking :-)

I tested your patch with this fixup, and it works for me (in CMD).

-- Hannes

-- 
*** Please reply-to-all at all times ***
*** (do not pretend to know who is subscribed and who is not) ***
*** Please avoid top-posting. ***
The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free.

You received this message because you are subscribed to the Google
Groups "msysGit" group.
To post to this group, send email to msysgit@googlegroups.com
To unsubscribe from this group, send email to
msysgit+unsubscribe@googlegroups.com
For more options, and view previous threads, visit this group at
http://groups.google.com/group/msysgit?hl=en_US?hl=en

```
