When I run this script:
fn main() {
// \033[0;31m <- Red
// \033[0m <- No Color
println!("\033[0;31mSO\033[0m")
}
I expect to get
SO #in red letters
However, I get:
33[0;31mSO33[0m
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?
I am using:
$ 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 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")
}
Updated: This answer was intended that "you cannot use octal character such as \033
, use hexadecimal character \x1b
instead",
but If you want to know about ANSI Escape code, maybe this gist is useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With