Skip to content

Instantly share code, notes, and snippets.

@huzemin
Last active January 30, 2024 17:51
Show Gist options
  • Save huzemin/8395a28bf9a95bf6a9e8585e9ec77e18 to your computer and use it in GitHub Desktop.
Save huzemin/8395a28bf9a95bf6a9e8585e9ec77e18 to your computer and use it in GitHub Desktop.

终端颜色和控制码

ANSI颜色和样式编码

1.字背景颜色范围:40~49

40:黑, 41:深红, 42:绿, 43:黄色, 44:蓝色, 45:紫色, 46:深绿, 47:白色

字颜色:30~39

30:黑, 31:红, 32:绿, 33:黄, 34:蓝色, 35:紫色, 36:深绿, 37:白色
echo -e "\x1b[31;1m color red underline \x1b[0m"

1m 亮的颜色,默认不给是暗淡的颜色

ANSI ANSI ANSI Aixterm Aixterm
  Color FG Code BG Code   Bright Color   FG Code BG Code
Black 30 40 Bright Black 90 100
Red 31 41 Bright Red 91 101
Green 32 42 Bright Green 92 102
Yellow 33 43 Bright Yellow 93 103
Blue 34 44 Bright Blue 94 104
Magenta 35 45 Bright Magenta 95 105
Cyan 36 46 Bright Cyan 96 106
White 37 47 Bright White 97 107
TYPE CODE
Shell \e
ASCII Hex \0x1B
ASCII Oct \033

终端使用256颜色

  1. 字体颜色: \x1b[38;5
  2. 背景颜色: \x1b[48;5

ANSI控制码的说明

  • 33[0m 关闭所有属性
  • 33[1m 设置高亮度
  • 33[4m 下划线
  • 33[5m 闪烁
  • 33[7m 反显
  • 33[8m 消隐
  • 33[30m -- 33[37m 设置前景色
  • 33[40m -- 33[47m 设置背景色
  • 33[nA 光标上移n行
  • 33[nB 光标下移n行
  • 33[nC 光标右移n行
  • 33[nD 光标左移n行
  • 33[y;xH设置光标位置
  • 33[2J 清屏
  • 33[K 清除从光标到行尾的内容
  • 33[s 保存光标位置
  • 33[u 恢复光标位置
  • 33[?25l 隐藏光标
  • 33[?25h 显示光标

其他资料

Colors In Terminal

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