Color termcaps Konsole?

久未见 提交于 2019-12-13 04:54:19

问题


I've got a problem with ANSI escape codes in my terminal on OpenSuse 13.2. My Makefile use to display pretty colors on OSX at work but at home when I use it I get the litteral termcaps such as \033[1;30m ... \033[0m

I know close to nothing about termcaps, I just found these escape characters that seemed to be working fine ! The strangest is that both my OSX and Linux terminal are configured with TERM=xterm-256color so I really don't know where to look for the correct setting I'm currently missing on Linux.

TL;DR: How to get escape codes such as \033[1;30m working in Konsole with xterm-256color ?

Edit: Here's a snippet of the Makefile I am talking about: \Here's a snippet of the Makefile I am talking about:

# Display settings
RED_L = \033[1;31m
GREEN_L = \033[1;32m
GREEN = \033[0;32m
BLUE = \033[0;34m
RED = \033[0;31m

all: $(OBJ_DIR) $(NAME)

$(OBJ_DIR):
        @mkdir -p $(OBJ_DIR)

$(NAME): $(OBJ)
        @echo "$(BLUE)Linking binary $(RED)$(NAME)$(BLUE).\n"
        @$(CC) -o $@ $^ $(LFLAGS)
        @echo "\t✻ $(GRAY)$(CC) -o $(RED)$(NAME)$(GRAY) object files:$(GREEN) OK! √\n$(NC)

回答1:


The example which you gave does not rely upon the setting of TERM (unless it is going someplace other than the terminal, e.g., via some program which interprets it such as the ls program, which has its own notion about colors). It would help if you quoted the section of the makefile which uses the escape sequences. Without that, we can offer only generic advice, e.g,. by assuming you have an echo command in the makefile.

The place to start looking is at the shell which your makefile uses. One would expect bash to be the default shell on OpenSUSE. But suppose you are actually using some other shell which happens to not recognize the syntax you are using, and trying to do something like

echo '\033[1;34mhello\033[m'

To help ensure that you are using the expected shell, you can put an assignment in your makefile, e.g.,

SHELL = /bin/sh

This assumes that /bin/sh itself is going to work as intended. However, that is commonly a symbolic link (for Linux) to the real shell. If so, one possible solution would be to change the real shell using OpenSUSE's update-alternatives feature to change the shell to bash (or zsh).

For additional information, see the discussion of SHELL in the GNU make manual.

Reflecting comments on the version of make -- GNU make 4.0 is known to have incompatible changes versus 3.81, as noted in the thread GNU Make 4.0 released on LWN.net. In particular, there are several comments relating to your problem, starting here.

However, checking a recent Fedora, it seems that the problem really is that the default behavior for echo has changed. As noted in other discussions (such as Why doesn't echo support “\e” (escape) when using the -e argument in MacOSX), this was done to improve POSIX compatibility. You can get your colors back by adding a -e option to the echo commands.




回答2:


I finally found the solution:

the problem was I used echo instead of echo -e which seems to be the default behaivour on Mac OSX.

Thanks for your help though, it lead me to good lectures :)



来源:https://stackoverflow.com/questions/29181720/color-termcaps-konsole

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!