sxyazi / yazi

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

New Line Delimited JSON cannot be opened/previewed #1183

Closed xfzv closed 1 week ago

xfzv commented 1 week ago

What system are you running Yazi on?

Linux X11

What terminal are you running Yazi in?

kitty 0.34.1

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 (505de05 2024-06-22) Debug : false OS : linux-x86_64 (unix) Ya Version: No such file or directory (os error 2) Emulator Emulator.via_env: ("xterm-kitty", "") Emulator.via_csi: Ok(Kitty) Emulator.detect : Kitty Adapter Adapter.matches: Kitty Desktop XDG_SESSION_TYPE: Some("tty") WAYLAND_DISPLAY : None DISPLAY : Some(":0") SSH shared.in_ssh_connection: false WSL /proc/sys/fs/binfmt_misc/WSLInterop: false Variables SHELL : Some("/bin/zsh") EDITOR : Some("nvim") ZELLIJ_SESSION_NAME: None YAZI_FILE_ONE : None YAZI_CONFIG_HOME : None Text Opener default: Some(Opener { run: "${EDITOR} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true }) block : Some(Opener { run: "${EDITOR} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true }) tmux TMUX : false 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-25 fzf : 0.53.0 fd : 9.0.0 rg : 14.1.0 chafa : No such file or directory (os error 2) zoxide : 0.9.4 unar : No such file or directory (os error 2) jq : 1.7.1 ```

Describe the bug

Opening/previewing regular json files works just fine. However, I have a json file which is actually a "New Line Delimited JSON text data" and this one can neither be opened (pressing "o" / "Enter" does nothing) or previewed (see screenshot). Works fine with Lf.

{
  "test": 1,
  "test2": 2
}{
  "test": "test",
  "test2": {
    "test": 1
  }
}
% file test-1.json
test-1.json: New Line Delimited JSON text data

% mimetype -bL test-1.json
application/json

Manually editing the formatting to turn the file into a regular json file solves the issue:

[
  {
    "test": 1,
    "test2": 2
  },
  {
    "test": "test",
    "test2": {
      "test": 1
    }
  }
]
% file test-2.json
test-2.json: JSON text data

% mimetype -bL test-2.json
application/json

Expected Behavior

"New Line Delimited JSON text data" files are opened/previewed just fine like regular JSON files.

To Reproduce

  1. Create a file.json with the following content:
    {
    "test": 1,
    "test2": 2
    }{
    "test": "test",
    "test2": {
    "test": 1
    }
    }
  2. Open yazi and highlight file.json: no preview
  3. Press either "o" or "" to open the file: nothing happens

Configuration

can reproduce without ~/.config/yazi directory (stock config)

Anything else?

yazi-preview

~/.local/state/yazi/yazi.log is empty

sxyazi commented 1 week ago

% mimetype -bL test-1.json

What is the mimetype program? Is it an alias for file(1) (which is used by Yazi)? What does file -bL test-2.json output?

xfzv commented 1 week ago

% mimetype -bL test-1.json

What is the mimetype program? Is it an alias for file(1) (which is used by Yazi)?

I'm using Gentoo:

% qfile mimetype
dev-perl/File-MimeInfo: /usr/bin/mimetype

% qlist -Iv dev-perl/File-MimeInfo                                                                                           
dev-perl/File-MimeInfo-0.330.0

% mimetype --version                                                                                                
mimetype 0.33

What does file -bL test-2.json output?

% file -bL test-2.json
JSON text data

% file -bL test-1.json                                                                                      
New Line Delimited JSON text data
sxyazi commented 1 week ago

Now what's the output of file -bL --mime-type test-1.json and file -bL --mime-type test-2.json?

xfzv commented 1 week ago
% file -bL --mime-type test-1.json
application/x-ndjson

% file -bL --mime-type test-2.json
application/json
xfzv commented 1 week ago

The following allows me to open the file with either <o> or <Enter>:

# ~/.config/yazi/yazi.toml

[open]
rules = [
# ..
{ mime = "application/{json,x-ndjson}", use = [
    "edit",
    "reveal",
  ] },
# ..
]

but preview is still not working with:

# ~/.config/yazi/yazi.toml

previewers = [
  # ..
  # JSON
  { mime = "application/{json,x-ndjson}", run = "json" },
  # ..
]
sxyazi commented 1 week ago

Thanks for the reporting, should be fixed in https://github.com/sxyazi/yazi/pull/1190, please give it a try (make sure you're using the default Yazi config)

xfzv commented 1 week ago

Thank you! Can confirm it works fine now with https://github.com/sxyazi/yazi/commit/696dcf2668770b09839424a825b06d2ff7556b1f

% yazi --version
Yazi 0.2.5 (696dcf2 2024-06-23)