如何更改文本颜色&背景在mac终端? [英] How to change text color & background in mac terminal?

查看:127
本文介绍了如何更改文本颜色&背景在mac终端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个程序,需要用不同的颜色写文本。
我有转义码RED \e [31m。但是,如果我在红色背景上做红色,那将无法工作。所以我也想改变背景颜色。
我试过使用这个\e [31m \e [94m 或甚至 \e [4Xm 在不同的背景做文本,但是,这不工作。任何想法得到红色文本在白色背景上?

I'm writing a program that needs to write text in different colors. I have the escape code RED "\e[31m". However, if I make red on a red background, that won't work. So I also want to change the background color. I've tried using this "\e[31m\e[94m" or even \e[4Xm to do text on a different background, however, this isn't working. Any ideas to get red text on a white background?

这是格式std :: cout<< COLORNAME....

This is in the format std::cout << "COLORNAME" ....

谢谢!

推荐答案

SGR选项可以链接在一起,实际上比你一直在尝试更紧凑。 SGR语法采用以下一般形式:

Multiple SGR options can be chained together, and in fact more compactly than you've been trying. The SGR syntax takes the general form of:


\e [ options m

kbd>可以包含由分号分隔的一个*或多个数字,其中可以包括多个事件,但特别是:

where options can consist of one* or more numbers separated by semicolons, which can include a number of things, but especially:


  • 1:bold

  • 30 - 37:设置前景颜色0-7(黑色,红色,绿色,黄色,蓝色,洋红色,青色,白色)

  • 40 - 47:设置背景颜色0-7(同上)

  • 90 - 97:设置前景色8 - 15(亮度版本为0 - 7;亮黑色

  • 100 - 107:设定背景颜色8 - 15(同上)

  • 1: bold
  • 30 – 37: set foreground color 0 – 7 (black, red, green, yellow, blue, magenta, cyan, white)
  • 40 – 47: set background color 0 – 7 (ditto)
  • 90 – 97: set foreground color 8 – 15 (bright versions of 0 – 7; "bright black" is a dark gray)
  • 100 – 107: set background color 8 – 15 (ditto)

,白色背景上的红色文本将是 \e [31; 47m

In your case, red text on a white background would be \e[31;47m.

(*:或根本没有数字,在这种情况下,它会重置所有图形选项。)

(*: Or no numbers at all, in which case it resets all graphical options.)

这篇关于如何更改文本颜色&amp;背景在mac终端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆