Skip to content

Commit

Permalink
Added implemention selection (Python or Rust) to pybidi cli
Browse files Browse the repository at this point in the history
  • Loading branch information
MeirKriheli committed Jul 30, 2024
1 parent 381e2e4 commit 754029e
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions bidi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ def main():
help="Text encoding (default: utf-8)",
)

parser.add_argument(
"-u",
"--upper-is-rtl",
dest="upper_is_rtl",
default=False,
action="store_true",
help="Treat upper case chars as strong 'R' "
"for debugging (default: False), Ignored in Rust algo",
)

parser.add_argument(
"-d",
"--debug",
Expand All @@ -61,17 +71,37 @@ def main():
help="Override base direction [L|R]",
)

parser.add_argument(
"-r",
"--rust",
dest="use_rust",
action="store_true",
help="Use the Rust unicode-bidi implemention instead of the Python one",
)

parser.add_argument(
"-v", "--version", action="version", version=f"pybidi {VERSION}"
)

options, rest = parser.parse_known_args()

lines = rest or sys.stdin

params = {
"encoding": options.encoding,
"base_dir": options.base_dir,
"debug": options.debug,
}

if options.use_rust:
display_func = get_display
else:
from .algorithm import get_display as get_display_python
display_func = get_display_python
params["upper_is_rtl"] = options.upper_is_rtl

for line in lines:
display = get_display(
line,
options.encoding,
options.base_dir,
options.debug,
)
display = display_func(line, **params)
# adjust the encoding as unicode, to match the output encoding
if not isinstance(display, str):
display = bytes(display).decode(options.encoding)
Expand Down

0 comments on commit 754029e

Please sign in to comment.