Check if terminal supports unicode in rust

Viewed 520

I would like some way of doing essentially the following:

if supports_unicode {
    print!("some unicode");
} else {
    print!("ascii");
}

Is there any way in rust to check if the output supports unicode?

Update

I found a way to check if the device supports unicode, but it doesn't check if the current output is set to the correct encoding, nor does it check if the font supports the full range of unicode characters. If you're curious, it uses the crate locale-codes 0.3.0, and the code is

locale_codes::codeset::all_names().contains(&String::from("UTF-8"))

But, as I said, this doesn't solve my problem

Also, if you want, here is a more specific example of the problem I've been having. In the VSCode intergrated terminal (Windows 10 x64, VSCode 1.47), if I run a rust program that prints the character (U+1D465), I get a variety of results, such as:

  • It actually printing the correct character
  • It prints �
  • It prints nothing at all
  • It prints (U+1D435)

I hope this example helps.

0 Answers
Related