makefiles/utils/ansi: Refactor ansi codes into their own file.

The escape codes and special chars now live in their own module. The
color module is only concerned with detecting whether to use colors or
not.

Additional variables are defined with hard a coded ESC char, a tab and a
newline. This removes the need for echo or printf.
This commit is contained in:
Juan Carrano 2019-08-30 15:02:16 +02:00 committed by Francisco Molina
parent 3ed96312af
commit 1036115f2d
No known key found for this signature in database
GPG Key ID: 3E94EAC3DBDEEDA8
4 changed files with 33 additions and 6 deletions

View File

@ -171,6 +171,7 @@ include $(RIOTMAKE)/utils/checks.mk
include $(RIOTMAKE)/docker.inc.mk
# include color echo macros
include $(RIOTMAKE)/utils/ansi.mk
include $(RIOTMAKE)/color.inc.mk
# include concurrency helpers

View File

@ -14,12 +14,11 @@ ifneq ($(CC_NOCOLOR),1)
IS_TERMINAL = $(if $(MAKE_TERMOUT),$(MAKE_TERMERR),)
# Check if terminal support colored output
ifneq ($(IS_TERMINAL),)
_ANSI_ESC := $(shell printf "\033")
COLOR_GREEN := $(_ANSI_ESC)[1;32m
COLOR_RED := $(_ANSI_ESC)[1;31m
COLOR_YELLOW := $(_ANSI_ESC)[1;33m
COLOR_PURPLE := $(_ANSI_ESC)[1;35m
COLOR_RESET := $(_ANSI_ESC)[0m
COLOR_GREEN := $(ANSI_GREEN)
COLOR_RED := $(ANSI_RED)
COLOR_YELLOW := $(ANSI_YELLOW)
COLOR_PURPLE := $(ANSI_PURPLE)
COLOR_RESET := $(ANSI_RESET)
ifeq ($(OS),Darwin)
COLOR_ECHO := echo -e
SHELL=bash

11
makefiles/utils/ansi.mk Normal file
View File

@ -0,0 +1,11 @@
# ANSI Terminal codes and other escape sequences.
# The objective of this definitions is to be able to write special characters
# without resorting to shell commands like echo.
include $(RIOTMAKE)/utils/ansi_special.mk
ANSI_GREEN := $(ANSI_ESC)[1;32m
ANSI_RED := $(ANSI_ESC)[1;31m
ANSI_YELLOW := $(ANSI_ESC)[1;33m
ANSI_PURPLE := $(ANSI_ESC)[1;35m
ANSI_RESET := $(ANSI_ESC)[0m

View File

@ -0,0 +1,16 @@
# Make does not recognize escaped characters (e.g. \t, \033, etc).
# The following variables contain the characters themselves.
# This file is inherently fragile (i.e. your editor could destroy the tab
# without you realizing, to be careful when editing this.
# To generate this: $ printf "ANSI_ESC := \033# comment"
ANSI_ESC := # you may or may not be able to see that character in your editor
# The third parameter to the subst is a tab - be careful not to replace it with
# spaces!
TAB := $(subst ,, )
define NEWLINE
endef