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

Use printf instead of echo in colors.sh #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lethosor
Copy link
Contributor

echo (both the built-in command and /bin/echo) doesn't recognize the "\e" escape sequence on OS X. (This may not be an issue, since $TERM is typically only unset in non-interactive environments, so these could theoretically also be replaced with an empty echo or printf.)

`echo \e[0;30m` (using both the built-in command and /bin/echo) doesn't recognize
the "\e" escape sequence on OS X.
@davidsnyder
Copy link

This fixed my prompt on OS X. Before it was printing "(master)\e[0m$" from the txtrst escape sequence.

@lethosor
Copy link
Contributor Author

Was master printing in color?

@davidsnyder
Copy link

davidsnyder commented Nov 30, 2018

Yes: https://imgur.com/a/99n9jkG (using echo)

Here it is with this patch: https://imgur.com/a/PEhL91H

@lethosor
Copy link
Contributor Author

Weird, I'm guessing your tput doesn't recognize sgr 0 somehow. What version of OS X are you using?

Changing sgr 0 to sgr0 might also work.

@davidsnyder
Copy link

Darwin Kernel Version 17.7.0

Like I said, switching to printf fixes the issue.

@lethosor
Copy link
Contributor Author

Right, but the only reason echo or printf are called is because tput fails. So in this case, it's because "tput sgr 0" fails. That's weird, though, because I'm using Darwin 17.6.0 (aka macOS 10.13.5) and it appears to work fine for me. Maybe it has something to do with your terminal, then.

At any rate, this patch would be good to merge for portability reasons in cases like yours.

@davidsnyder
Copy link

davidsnyder commented Dec 1, 2018

Ah you're right. I wasn't thinking about the logic. Are you sure that your tput sgr 0 2 isn't exiting 1? You might be hitting the echo/printf as I did.

davidsnyder@loki tictactoe-react (master)*$ tput sgr 0 2
davidsnyder@loki tictactoe-react (master)*$ echo $?
1

tput sgr0 seems to be the correct command? I read that sgr 0 0 is equivalent to sgr0 but sgr 0 0 exits 1 for some reason.

txtrst="$(tput sgr0 2>/dev/null || printf '\e[0m')" # Text Reset works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants