Skip to content

Instantly share code, notes, and snippets.

@XVilka
Last active August 9, 2024 06:36
Show Gist options
  • Save XVilka/a0e49e1c65370ba11c17 to your computer and use it in GitHub Desktop.
Save XVilka/a0e49e1c65370ba11c17 to your computer and use it in GitHub Desktop.
BiDirectional Text

This gist will show the support of BiDirectional text in the terminal emulators and console programs. You can read more about the standardization efforts at the dedicated page of FreeDesktop Terminal BiDi working group.

How to test

Logical Order ◀ ◀ ◀ RTL LTR ▶ ▶ ▶
WHAT IS UNICODE؟ in arabic in arabic ؟EDOCINU SI TAHW ؟EDOCINU SI TAHW in arabic
ما هو الترميز الموحد يونيكود؟ in Arabic ما هو الترميز الموحد يونيكود؟ in Arabic

Supporting BiDirectional text

According to a new standard

Please note, that specification is preliminary yet, and VTE implementation is still work in progress:

Incompatible and incomplete implementations

Supporting BiDirectional text programs, but incompatible

Not supporting BiDirectional text

Terminal multiplexers

Not supporting BiDirectional text programs

@wolandark
Copy link

wolandark commented Jul 24, 2024

Konsole is actually doing a great job at bidi, in fact it is the only terminal that renders the RTL text from the right edge of the terminal window.

See this screenshot from Konsole displaying English and Persian bible text in one window.

I'm not sure if others can render LTR and RTL text in such fashion.

The settings window

@mintty
Copy link

mintty commented Jul 24, 2024

I'd say all terminals I've seen to do bidi do it that way - how else? To check, however, please upload your test file.

The konsole feature "Table characters BiDi mode override" might be interesting but unfortunately it is not really specified (which characters? examples?); maybe I'll submit them an issue.

@MoSal
Copy link

MoSal commented Jul 24, 2024

@wolandark

In any VTE-based terminal, echo '\e[?2501h' to enable auto-direction, and you should get the same behavior.

This comes from terminal-wg's BiDI draft proposal.

@wolandark
Copy link

@MoSal Neat! I didn't know that. After running the escape sequence, XFCE terminal also behaves the same as Konsole does.

@wolandark
Copy link

@mintty here is a sample of the text (though what I shared in the screenshot was being fetched from an API).

As mentioned above, doing as MoSal suggested, makes XFCE terminal (which is VTE) behave the same way as Konsole, so I guess my defense of Konsole is relevant, though in my defense there is no need to run any escape sequence in Konsole to get this behavior.

@MoSal
Copy link

MoSal commented Jul 24, 2024

though in my defense there is no need to run any escape sequence in Konsole to get this behavior.

FWIW, LTR instead of AUTO as a default paragraph direction was a design choice which I, as a native speaker of an RTL language, tend to agree with.

@mintty
Copy link

mintty commented Jul 26, 2024

The konsole feature "Table characters BiDi mode override" might be interesting

It appears that mintty already has a mode that seems to render table layout like konsole: echo -e "\e[?2501l".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment