1

i am making a CLI app in rust, and the app includes multiple languages. one of those languages is hebrew, which is a RTL language. when writing in hebrew, for example:

println!("קוד לדוגמא");

it comes out as

אמגודל דוק

which is the original message in reverse.

i know i can just write the text and reverse, and then it works, but i have a lot of text to write, and i don't want to have any side effects from this. is there any library or configuration in rust in order to write RTL text?

6
  • It seems to work just fine on the playground. What do you use as an output device (terminal...)? You may try \u{202E}קוד לדוגמא just for laughs, which includes the RIGHT-TO-LEFT-OVERRIDE unicode character. Commented Sep 17, 2023 at 10:16
  • i'm using debian, and i am using rustrover and vscode for the code, and both of them wrote this in reverse, even with the RTL override Commented Sep 17, 2023 at 10:36
  • 2
    It depends on your output device. Try running your program in gnome terminal or whatever comes with your OS. Some terminals support RTL/BIDI text, some don't (so sometimes you must reverse and sometimes you cannot reverse). You cannot tell which is the case with your terminal from within a program, there is no API. Note (1) there is a lot more to BIDI text than simple reversal and (2) you think that's hard? wait until you need to display Arabic on one of those non-supporting devices. Commented Sep 17, 2023 at 10:47
  • @throwawayaccount, can confirm this behavior in VSCode on GitHub Codespaces and on MacOS. However, the same terminal output (same tmux session) is rendered correctly (RTL) in MacOS-Terminal compared to VSCode (LTR). So it's definitely a output device issue, not Rust specific Commented Sep 17, 2023 at 10:54
  • 1
    @throwawayaccount if it's acceptable, try piping into fribidi. Haven't been doing that in a while but it used to solve this in a local manner Commented Sep 17, 2023 at 11:02

1 Answer 1

1

it seems that anything that emulates a terminal does this bug. This depends on the editor, but you should have to option to just display the result instead of emulate a commandline. on rustrover just go into your "run/debug configurations" and turn off "emulate terminal in output console". this also worked on other jetbrains products, but i haven't tested on all of them.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.