Skip to content

A CLI tool to reshape and reorder bi-directional, Arabic/Persian text for display in apps that do not support them natively

License

Notifications You must be signed in to change notification settings

NightMachinery/rtl_reshaper_rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rtl_reshaper_rs

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.

Installation

cargo install --git https://github.com/NightMachinary/rtl_reshaper_rs --force

Or (not recommended):

cargo install rtl_reshaper_rs

Usage

echo 'من غذا خوردم.' $'\n' 'خانه خالی و hollow است ... :)' | rtl_reshaper_rs
echo $'\n'
 .ﻡﺩﺭﻮﺧ ﺍﺬﻏ ﻦﻣ
): ... ﺖﺳﺍ hollow ﻭ ﯽﻟﺎﺧ ﻪﻧﺎﺧ

readme.org_imgs/20210316_211212_rq0bk5.png

Alternatives

Python version (less buggy but much slower)

Benchmarks

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'

Known issues

Upstream

Newlines are ordered weirdly:

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	ﻥ

Punctuation marks are ordered wrongly:

echo "بد :)" | rtl_reshaper_rs
): ﺪﺑ
echo "بد :)" | rtl_reshaper.py
(: ﺪﺑ

License

MIT

Releases

No releases published

Packages

No packages published

Languages