sxyazi / yazi

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

Plugins are not able to access local preferences #1237

Closed imsi32 closed 2 months ago

imsi32 commented 2 months ago

What system are you running Yazi on?

Linux X11

What terminal are you running Yazi in?

alacritty 0.13.2

Did you try the latest code to see if this problem got fixed?

Tried, but the problem still

yazi --debug output

```sh Yazi Version: 0.2.5 (VERGEN_IDEMPOTENT_OUTPUT 2024-06-26) OS: linux-x86_64 (unix) Debug: false Emulator Emulator.via_env: ("xterm-256color", "") Emulator.via_csi: Ok(Unknown([])) Emulator.detect: Unknown([]) Adaptor Adaptor.matches: X11 Desktop XDG_SESSION_TYPE: Some("x11") WAYLAND_DISPLAY: None DISPLAY: Some(":0.0") SSH shared.in_ssh_connection: false WSL /proc/sys/fs/binfmt_misc/WSLInterop: false Variables SHELL: Some("/bin/bash") EDITOR: None ZELLIJ_SESSION_NAME: None YAZI_FILE_ONE: None YAZI_CONFIG_HOME: None file(1) Version: Ok(Output { status: ExitStatus(unix_wait_status(0)), stdout: "file-5.41\nmagic file from /etc/magic:/usr/share/misc/magic\n", stderr: "" }) Text Opener default: Some(Opener { run: "nvim \"$@\"", block: true, orphan: false, desc: "nvim", for_: None, spread: true }) block: Some(Opener { run: "nvim \"$@\"", block: true, orphan: false, desc: "nvim", for_: None, spread: true }) tmux TMUX: false Ueberzug++ Version: Ok(Output { status: ExitStatus(unix_wait_status(0)), stdout: "ueberzugpp 2.9.6\n", stderr: "" }) ```

yazi.log

Describe the bug

While I developing my plugin, I encounter two issues which I believe it is because local system preferences like language, time - date form, fonts etc. cannot accessed by plugins. The issues:

  1. Even though, I set my Styles with probability bold = true in init.lua file. My texts are not applied with this property. However, if I use theme.toml, or used bold font in other application like neovim, its works.
  2. I added a time and date component using os.date() function. However, it gives me only English text, which is not my local. These does not happen when I use this function in neovim which gives my local values.

Expected Behavior

According to my issues:

  1. Text with bold fonts appear
  2. os:date'() function returns texts with my language (local preferences)

To Reproduce

For the 1st issue:

  1. Put a style with a bold = true property in init.lua of a plugin
  2. Style a component using this style
  3. It should not have bold font

For the 2nd issue:

  1. Create a component which shows text from os:date() function
  2. If your local preferences is not same with English, it can be seen that it is in English but not in your local preferences.

Configuration

These sections are from yatline.yazi plugin's init.lua file.

function CreateDate()

    set_mode_style(cx.active.mode)
    set_separator_style(1, 1, 2, 1)

    local date = ui.Span(" " .. os.date("%A, %d %B %Y", os.time()) .. " ")
    set_component_style(date, 1)
    local date_line = connect_separator(date, 1, 1)

    set_separator_style(1, 1, 3, 2)

    local time = ui.Span(" " .. os.date("%X", os.time()) .. " ")
    set_component_style(time, 2)
    local time_line = connect_separator(time, 1, 1)

    return ui.Line( {time_line, date_line} )
end
local separator_style = { bg = "#282828", fg = "#282828", bold = true }

local style_a = { bg = "#282828", fg = "#282828", bold = true }
local style_b = { bg = "#665c54", fg = "#ebdbb2", bold = true}
local style_c = { bg = "#3c3836", fg = "#a89984", bold = true}

Anything else?

In Yazi: yatline_os_date

In Neovim: lualine_os_date

sxyazi commented 2 months ago

I set my Styles with probability bold = true in init.lua file

You should use ui.Style() to create a Style, e.g.:

ui.Style():fg("red"):bg("blue"):bold()

Doc of ui.Style: https://yazi-rs.github.io/docs/plugins/layout#style

I added a time and date component using os.date() function. However, it gives me only English text, which is not my local.

Could you please try calling os.setlocale("") or os.setlocale("C") before os.date() and see which one works, we can add it to the setup.lua if either of them worked.

Doc of os.setlocale: https://www.lua.org/manual/5.4/manual.html#pdf-os.setlocale

imsi32 commented 2 months ago

First of all, I am sorry to put two different issue into one issue. For the bold font issue, I just added :bold() after I styled components like the following and it worked.

component:style(style_a):bold()

For the local text issue I tried os.setlocale(), os.setlocale("") and os.setlocale("C"). The only one working is os.setlocale("").

sxyazi commented 2 months ago

The only one working is os.setlocale("").

I've added it to the setup.lua in https://github.com/sxyazi/yazi/pull/1241/files#diff-1efb3f807841b778a047aae5032cf99bf0b4294e7036f8f09c5cc1b994906ffa, you should no longer need to set it up before calling os.date() as now Yazi will initialize it automatically.

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 open a new issue and complete the issue template so we can capture all the details necessary to investigate further.