mapscii icon indicating copy to clipboard operation
mapscii copied to clipboard

Arabic Words are reversed

Open amirping opened this issue 7 years ago • 5 comments

the name of city in arabic are reversed screenshot from 2017-05-15 08-47-44

amirping avatar May 15 '17 07:05 amirping

!@amirping شكرا

Wasn't aware of them not already being stored as left-to-right strings, most likely will use string-direction to fix it. Thanks!

rastapasta avatar May 15 '17 14:05 rastapasta

Shouldn't this be fixed up-stream?

derhuerst avatar May 15 '17 15:05 derhuerst

Same for Hebrew words.

VRDate avatar Feb 05 '18 10:02 VRDate

This could be fixed with a proper "bidi" and "reshaper" implementations. From my quick search, I found few implementations out there for node but to be honest I did not like any...

One option is to rely on fribidi, but this won't be pure javascript. Maybe check if the system has it, use it, otherwise skip this?

But anyway, I don't think this is really a huge deal. For me, as an Arabic speaker that lives on the terminal, with time, you'll get used to read in reversed order... But if you really need that to be solved and right now, go for bicon.

Naheel-Azawy avatar Aug 03 '19 00:08 Naheel-Azawy

The intrinsic problem, to begin with, is that terminals have (or well, up to recently had) absolutely no idea what to do on RTL text: whether to automatically reverse it or not.

Some don't reverse (e.g. gnome-terminal, as of the time the above screenshot was posted; xterm; and plenty of others). Some do reverse by default (e.g. newest gnome-terminal; konsole; mlterm; putty). Some make it configurable (e.g. gnome-terminal via an escape sequence, konsole via a preference).

Obviously there's no way you can make it work in both of these kinds of terminals at once.

In my BiDi in Terminal Emulators specification I argue that the behavior of the terminal automatically "reversing" the strings (that is, displaying them from right to left) is the desired behavior for simple command-line utilities, and thus should be the default; however is outright broken (literally impossible to use as a canvas to arbitrarily arrange the letters, cropping of long words etc.) for apps that control the entire UI, such as mapscii.me, so there needs to be an escape sequence to turn it off.

The only reasonable thing for you to do is to print these words in "reverse", i.e. "left-to-right visual" order, by reversing(*) them on the server. If cropping is required (the word crosses the edge of the terminal), this cropping needs to happen on the already reversed ("LTR visual") string. This will be broken in terminals like konsole using their default settings, but you can ask users to disable BiDi in the terminal.

In order to support GNOME Terminal 3.34 (and all other terminals based on VTE 0.58), MinTTY, and any other future terminal implementing this new spec, you have to switch to Explicit LTR mode at startup using \e[8l\e[1 k, followed by a clear screen (or similar) operation when the cursor stands in the upper left corner; and upon exiting restore the default state using \e[8h\e[ k.

(*) In addition to reversing, you also need to mirror mirrorable characters (e.g. parentheses), and cleverly handle if a string is a mixture of LTR and RTL. Probably the simplest is to run it through some existing BiDi algorithm implementation to convert the logical string to a visual LTR one.

egmontkob avatar Nov 19 '19 11:11 egmontkob