Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make install colors not always shown #2179

Merged
merged 3 commits into from
May 24, 2024
Merged

Conversation

grepsuzette
Copy link
Contributor

@grepsuzette grepsuzette commented May 24, 2024

In my terminals (konsole, kmscon, kmscon+tmux), colors won't show without -e in
echo -e "\033[0;32m blabla \033[0m".

The -e option enables interpretation of backslash escapes in the string, which
allows the color code \033[0;32m to work. With -e it should be more widely
supported across different platforms and shell environments.

$ help echo
echo: echo [-neE] [arg ...]
    Write arguments to the standard output.

    Display the ARGs, separated by a single space character and followed by a
    newline, on the standard output.

    Options:
      -n        do not append a newline
      -e        enable interpretation of the following backslash escapes
      -E        explicitly suppress interpretation of backslash escapes

    `echo' interprets the following backslash-escaped characters:
      \a        alert (bell)
      \b        backspace
      \c        suppress further output
      \e        escape character
      \E        escape character
      \f        form feed
      \n        new line
      \r        carriage return
      \t        horizontal tab
      \v        vertical tab
      \\        backslash
      \0nnn     the character whose ASCII code is NNN (octal).  NNN can be
                0 to 3 octal digits

An alternative is to directly input the escape character, or to use printf: printf "\033[0;32mHello\033[0m\n".

@leohhhh does it still work on your machine with echo -e? (what terminal are you using btw?)

In my terminals (konsole, kmscon, kmscon+tmux), colors won't show without -e in
echo -e "\033[0;32m blabla \033[0m".

The -e option enables interpretation of backslash escapes in the string, which
 allows the color code \033[0;32m to work. With -e it should be more widely
 supported across different platforms and shell environments.

```
$ help echo
echo: echo [-neE] [arg ...]
    Write arguments to the standard output.

    Display the ARGs, separated by a single space character and followed by a
    newline, on the standard output.

    Options:
      -n        do not append a newline
      -e        enable interpretation of the following backslash escapes
      -E        explicitly suppress interpretation of backslash escapes

    `echo' interprets the following backslash-escaped characters:
      \a        alert (bell)
      \b        backspace
      \c        suppress further output
      \e        escape character
      \E        escape character
      \f        form feed
      \n        new line
      \r        carriage return
      \t        horizontal tab
      \v        vertical tab
      \\        backslash
      \0nnn     the character whose ASCII code is NNN (octal).  NNN can be
                0 to 3 octal digits
```
@grepsuzette grepsuzette requested a review from a team as a code owner May 24, 2024 01:23
@grepsuzette grepsuzette requested review from jaekwon and harry-hov and removed request for a team May 24, 2024 01:23
@grepsuzette grepsuzette changed the title fix: make install (ansi colors not always shown) fix: make install colors not always shown May 24, 2024
Copy link
Member

@thehowl thehowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get this problem, but doing a few tests I think it's because my shell is zsh and automatically converts it. The PR is sensible, merging.

Makefile Outdated Show resolved Hide resolved
@thehowl
Copy link
Member

thehowl commented May 24, 2024

Actually, my shell prints the literal -e:

image

I looked this up, see UNIX stackexchange:

UNIX compliant implementations of echo are required to output -e<space>hello<newline>world<newline> there.

Those that don't are not compliant. Many aren't which means it's almost impossible to use echo portably, printf should be used instead. bash's echo, in some (most) builds of it, is only compliant when you enable both the posix and xpg_echo options. That might be the echo behaviour you were expecting.

I changed the implementation to use printf instead.

@thehowl thehowl merged commit c6cde63 into gnolang:master May 24, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants