Skip to content

Instantly share code, notes, and snippets.

@kuanyui
Last active March 11, 2022 08:49
Show Gist options
  • Save kuanyui/55c73182943dd464f2edf2d8c0926b71 to your computer and use it in GitHub Desktop.
Save kuanyui/55c73182943dd464f2edf2d8c0926b71 to your computer and use it in GitHub Desktop.
Colors in console (NodeJS, Makefile)
const C = {
Reset: "\x1b[0m",
Bright: "\x1b[1m",
Dim: "\x1b[2m",
Underscore: "\x1b[4m",
Blink: "\x1b[5m",
Reverse: "\x1b[7m",
Hidden: "\x1b[8m",
FgBlack: "\x1b[30m",
FgRed: "\x1b[31m",
FgGreen: "\x1b[32m",
FgYellow: "\x1b[33m",
FgBlue: "\x1b[34m",
FgMagenta: "\x1b[35m",
FgCyan: "\x1b[36m",
FgWhite: "\x1b[37m",
BgBlack: "\x1b[40m",
BgRed: "\x1b[41m",
BgGreen: "\x1b[42m",
BgYellow: "\x1b[43m",
BgBlue: "\x1b[44m",
BgMagenta: "\x1b[45m",
BgCyan: "\x1b[46m",
BgWhite: "\x1b[47m",
} as const
ifneq (,$(findstring xterm,${TERM}))
DARK_BLACK := $(shell tput setaf 0)
DARK_RED := $(shell tput setaf 1)
DARK_GREEN := $(shell tput setaf 2)
DARK_YELLOW := $(shell tput setaf 3)
DARK_BLUE := $(shell tput setaf 4)
DARK_MAGENTA := $(shell tput setaf 5)
DARK_CYAN := $(shell tput setaf 6)
DARK_WHITE := $(shell tput setaf 7)
BLACK := $(shell tput setaf 8)
RED := $(shell tput setaf 9)
GREEN := $(shell tput setaf 10)
YELLOW := $(shell tput setaf 11)
BLUE := $(shell tput setaf 12)
MAGENTA := $(shell tput setaf 13)
CYAN := $(shell tput setaf 14)
WHITE := $(shell tput setaf 15)
RESET := $(shell tput -Txterm sgr0)
else
DARK_BLACK := ''
DARK_RED := ''
DARK_GREEN := ''
DARK_YELLOW := ''
DARK_BLUE := ''
DARK_MAGENTA := ''
DARK_CYAN := ''
DARK_WHITE := ''
BLACK := ''
RED := ''
GREEN := ''
YELLOW := ''
BLUE := ''
MAGENTA := ''
CYAN := ''
WHITE := ''
RESET := ''
endif
@kuanyui
Copy link
Author

kuanyui commented Mar 11, 2022

Quoted from https://blog.gtwang.org/linux/how-to-make-a-fancy-and-useful-bash-prompt-in-linux-2/ :

tput setb [1-7]:設定背景顏色。
tput setab [1-7]:使用 ANSI escape code 設定背景顏色。
tput setf [1-7]:設定前景顏色。
tput setaf [1-7]:使用 ANSI escape code 設定前景顏色。

tput bold:進入粗體模式。
tput dim:進入低亮度(half-bright)模式。
tput smul:進入下底線模式。
tput rmul:結束下底線模式。
tput rev:開始反相模式。
tput smso:進入 standout 模式。
tput rmso:結束 standout 模式。
tput sgr0:結束所有的模式。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment