rtl_reshaper_rs
is a CLI tool that uses rust libraries arabic_reshaper
and unic-bidi
to reshape and reorder bi-directional, Arabic/Persian text for display in apps that do not support them natively.
cargo install --git https://github.com/NightMachinary/rtl_reshaper_rs --force
Or (not recommended):
cargo install rtl_reshaper_rs
echo 'من غذا خوردم.' $'\n' 'خانه خالی و hollow است ... :)' | rtl_reshaper_rs
echo $'\n'
.ﻡﺩﺭﻮﺧ ﺍﺬﻏ ﻦﻣ ): ... ﺖﺳﺍ hollow ﻭ ﯽﻟﺎﺧ ﻪﻧﺎﺧ
Python version (less buggy but much slower)
cd ~/code/data/sharif_course_list || return $?
hyperfine --warmup=6 'ls -l | rtl_reshaper_rs' 'ls -l | rtl_reshaper.py'
Benchmark #1: ls -l | rtl_reshaper_rs Time (mean ± σ): 24.2 ms ± 12.9 ms [User: 14.8 ms, System: 8.3 ms] Range (min … max): 13.9 ms … 91.3 ms 91 runs Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet PC without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options. Benchmark #2: ls -l | rtl_reshaper.py Time (mean ± σ): 1.310 s ± 0.137 s [User: 751.1 ms, System: 317.7 ms] Range (min … max): 1.051 s … 1.489 s 10 runs Summary 'ls -l | rtl_reshaper_rs' ran 54.07 ± 29.28 times faster than 'ls -l | rtl_reshaper.py'
echo A$'\n'B | rtl_reshaper_rs | cat -n
1 A 2 B
echo ب$'\n'ن | rtl_reshaper_rs | cat -n
1 2 ﺏ 3 ﻥ
echo ب$'\n'ن | rtl_reshaper.py | cat -n
1 ﺏ 2 ﻥ
echo "بد :)" | rtl_reshaper_rs
): ﺪﺑ
echo "بد :)" | rtl_reshaper.py
(: ﺪﺑ
MIT