sxyazi / yazi

💥 Blazing fast terminal file manager written in Rust, based on async I/O.
https://yazi-rs.github.io
MIT License
17.08k stars 399 forks source link

Enable FriBiDi Support for RTL Languages #1679

Closed amraymanaly closed 2 months ago

amraymanaly commented 2 months ago

yazi --debug output

Yazi
    Version: 0.3.3 (VERGEN_IDEMPOTENT_OUTPUT 2024-09-23)
    Debug  : false
    OS     : linux-x86_64 (unix)

Ya
    Version: 0.3.3 (VERGEN_IDEMPOTENT_OUTPUT 2024-09-23)

Emulator
    Emulator.via_env: ("st-256color", "")
    Emulator.via_csi: Ok(Unknown([]))
    Emulator.detect : Unknown([])

Adapter
    Adapter.matches: X11

Desktop
    XDG_SESSION_TYPE           : None
    WAYLAND_DISPLAY            : None
    DISPLAY                    : Some(":0")
    SWAYSOCK                   : None
    HYPRLAND_INSTANCE_SIGNATURE: None
    WAYFIRE_SOCKET             : None

SSH
    shared.in_ssh_connection: false

WSL
    WSL: false

Variables
    SHELL              : Some("/usr/local/bin/fishlogin")
    EDITOR             : None
    VISUAL             : None
    YAZI_FILE_ONE      : None
    YAZI_CONFIG_HOME   : None

Text Opener
    default: Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
    block  : Some(Opener { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })

Multiplexers
    TMUX               : false
    tmux version       : No such file or directory (os error 2)
    ZELLIJ_SESSION_NAME: None
    Zellij version     : No such file or directory (os error 2)

Dependencies
    file             : 5.45
    ueberzugpp       : No such file or directory (os error 2)
    ffmpegthumbnailer: 2.2.2
    magick           : 7.1.1-36
    fzf              : 0.54.3
    fd               : 10.2.0
    rg               : 14.1.0
    chafa            : No such file or directory (os error 2)
    zoxide           : 0.9.4
    7z               : 24.08
    7zz              : 24.08
    jq               : 1.7.1

--------------------------------------------------
When reporting a bug, please also upload the `yazi.log` log file - only upload the most recent content by time.
You can find it in the "/home/amr/.local/state/yazi" directory.

Please describe the problem you're trying to solve

For simple programs, I can generally pipe their output to fribidi, which does the rendering of Arabic text correctly. However, I can't just do that with a complex program like yazi. There doesn't seem to be a way to extend it with lua to achieve this.

Would you be willing to contribute this feature?

Describe the solution you'd like

Either use FriBiDi headers directly in code, perhaps through c, or a simple pipe to the fribidi executable before rendering text, which is a lot less efficient.

Additional context

No response

Validations

sxyazi commented 2 months ago

I don't know FriBiDi, it would help if you could explain what it is and what Yazi can do here

amraymanaly commented 2 months ago

FriBiDi is GNU's implementation of the standard bidirectional text algorithm. It takes unicode RTL text and renders it properly. If the characters are in the simple Latin range, or the slightly wider LTR characters range, it does nothing. Hence it's a harmless and useful addition to pipe all text through the algorithm before rendering.

This is important to me because I have Arabic files/directories and Arabic content, so it messes with my directory listings and the content preview.

sxyazi commented 2 months ago

I think this is a bit beyond the scope of Yazi, as it involves text layout. Yazi being a TUI app, doesn't handle that directly and relies on the UI library Ratatui.

If you just want to deal with the filename part, you could try rewriting the Entity:highlights() method, where you can access the file name through self._file.name and perform any processing or conversion. Here's a simple example:

-- ~/.config/yazi/init.lua
function Entity:highlights()
  return ui.Line("You can return anything you want here")
end

screenshot-002024

However, content preview is still tricky because it's not just a Line like the filename but a Paragraph, which requires the appropriate API from Ratatui. Fortunately, I found an issue discussing this: https://github.com/ratatui/ratatui/issues/756.

Implementing this on the Yazi side would be quite complex; we might need to iterate over each Paragraph and calculate their content size before Ratatui renders them, which would turn the original single render into two renders. Since Yazi doesn't have complete info on each Paragraph, it would need to render them again. So, I'll close this issue as it's beyond Yazi's scope.

github-actions[bot] commented 1 month ago

I'm going to lock this issue because it has been closed for 30 days. ⏳ This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please file a new issue and complete the issue template so we can capture all the details necessary to investigate further.