我无法在终端上打印颜色转义码 [英] I cannot print color escape codes to the terminal

查看:62
本文介绍了我无法在终端上打印颜色转义码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行此脚本时:

fn main() {
    // \033[0;31m <- Red
    // \033[0m <- No Color
    println!("\033[0;31mSO\033[0m")
}

我希望得到

SO #in red letters

但是,我得到了:

33[0;31mSO33[0m

当我在Go或Python中运行类似的脚本时,我得到了预期的输出.到底是怎么回事?我想念什么?该如何解决?

When I ran similar script in Go or Python, I get the expected output. What is going on? What am I missing? How do fix this?

我正在使用:

$ rustc --version
rustc 1.3.0 (9a92aaf19 2015-09-15)
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.3 LTS
Release:    14.04
Codename:   trusty

推荐答案

Rust 1.3.0似乎不支持八进制转义字符串,例如 \ 033 .相反,您可以使用十六进制转义字符串,例如 \ x1b .

Rust 1.3.0 does not seem to support octal escape strings such as \033. Instead, you can use hexadecimal escape strings like \x1b.

fn main(){
  println!("\x1b[0;31mSO\x1b[0m")
}

这篇关于我无法在终端上打印颜色转义码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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