JacobCrabill / zigdown

Markdown parser in Zig
MIT License
16 stars 2 forks source link

fzf error: SystemCallFailed #2

Closed VarLad closed 1 day ago

VarLad commented 2 months ago

When I'm trying to use zigdown with fzf, I get: error: SystemCallFailed I'm observing it in some other places as well. Running zigdown with zigdown -c {-1} in this case.

JacobCrabill commented 2 months ago

What do you mean by "using it with fzf"? Could you give a complete example? And are you on Linux or something else?

VarLad commented 2 months ago

Apologies for lack of information. Yes I tried this in Linux, on foot and wezterm terminal. cd to a folder where you have markdown files, and preview them using:

ls *.md | fzf --preview 'zigdown {-1}'

Assumes that you got zigdown and fzf on PATH.

This works for other viewers, for example, if you replace zigdown with mdcat there, it should work as intended.

My primary usecase for this tool, is usage with https://github.com/zk-org/zk where its used the same way as above.

JacobCrabill commented 2 months ago

Ah, I suspect that the {-1} option results in a list of files rather than a single file at a time, which isn't something I had considered. You could try a BASH for loop over the results one at a time instead. Changing the behavior to take a list of files shouldn't be hard.

If you're trying to preview a bunch of Markdown files, though, take a look at my Slidey project - that's exactly the purpose I built that for (although it "presents" them using the alternate terminal rather than using the main terminal).

VarLad commented 2 months ago

@JacobCrabill I wonder if thats the issue I was using helix editor and ran !sh zigdown README.sh inside it. Expected it to -print inside a window in Helix Got the above error instead. It would look horrible but I expected it to print something. mdcat works here too.

JacobCrabill commented 2 months ago

Try creating an executable .sh script like so:

#!/usr/bin/env bash
for f in "$@"; do
  zigdown "$f"
done
VarLad commented 2 months ago

Same error. Also the first thing I tried :) More specifically, I was trying to run zigdown, store its output in a variable, then print that variable, and even that doesn't work.

JacobCrabill commented 2 months ago

Ah, with the ANSI escape characters, I don't think there's any way (or at least no good way) to store the contents in a variable and then re-print them in a way the terminal will properly interpret them. Your best bet is to dump the output to a file then cat it (that's how I make the Neovim plugin work).

VarLad commented 4 days ago

@JacobCrabill Apologies for delay, but I get the same issue with store to file too... Its like zigdown somehow knows that I'm running it inside fzf and just errors out without writing to output file. Command: ls *.md | fzf --preview 'zigdown --output ~/something.txt {-1}'

Even without {-1}, if I write FILE.md instead, same error zigdown --output ~/something.txt FILE.md works though :/

JacobCrabill commented 1 day ago

Huh, ok, I just installed fzf to see if I could replicate the issue, and I see what you're talking about now (btw, I'd never heard of that preview tool before, but I guess that's how Telescope is implemented! Pretty neat).

Off the top of my head, I have no clue what fzf might be doing to cause Zigdown to fail - I'm not doing anything special... JK - I just found the issue! I use a terminal ioctl to get the terminal size, so that the rendered output will conform to the terminal size (try running zigdown in a super narrow terminal and you'll see what I mean).

This is actually an easy fix - I'll add a command-line arg to specify the render width, so when you're using fzf, you can just specify it there.

Pushed to main :)

JacobCrabill commented 1 day ago

There's still a minor rendering bug where newlines at the end of code blocks aren't quite correct; I may look into that at some point but it's super low priority for me.