When I type in Arabic in the print commands, for example, or any other commands in Visual Studio Code, the result appears in the terminal in reversed Arabic .for example
print ("السلام عليكم")
it’s appeared in terminal like:
م ك ي ل ع م ا ل س ل ا
2
Answers
The terminal in Visual Studio Code (and many other code editors) doesn’t fully support right-to-left text rendering.
You can try to use the following codes to make it work:
There are a few possible approaches:
python-bidi
andarabic-reshaper
packages.pyfribidi
package.As indicated in the OP, the vscode terminal has serious bidirectional text rendering issues, so the simple code will not work:
So instead, using
python-bidi
andarabic-reshaper
:python-bidi
is responsible in convert from logical to visual reordering, andarabic-reshaper
converts Arabic characters to appropriate presentational forms.Using
pyfribidi
:pyfribidi
is a wrapper around the fribidi library. If you have libraqm support enabled for bidi support in Pillow or in the mplcairo backend for matplotlib you probably already have fribidi available.Personally I prefer option 1. Options 2 and 3 are ugly hacks, but sometimes necessary.
As an example of what option 1, may look like, using the Terminal app on macOS: