Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI help could be clearer about interaction of watching and stdin input #3996

Open
1 task done
oligo opened this issue Apr 24, 2024 · 5 comments
Open
1 task done

CLI help could be clearer about interaction of watching and stdin input #3996

oligo opened this issue Apr 24, 2024 · 5 comments
Labels
cli About Typst's command line interface. docs Improvements or additions to documentation

Comments

@oligo
Copy link

oligo commented Apr 24, 2024

Description

Typst version: 0.11.0.

Issue: I use the following command to read from stdin but watch does not compile.

typst watch - ./test.pdf

I see this feature was added in #3339, but seems not working for me. Please confirm if is is broken. Thank you!

Reproduction URL

No response

Operating system

macOS

Typst version

  • I am using the latest version of Typst
@oligo oligo added the bug Something isn't working label Apr 24, 2024
@alerque
Copy link
Contributor

alerque commented Apr 24, 2024

This is not expected to work, and it has nothing to do with typst. STDIN is a stream not a regular file, and the device node that powers it cannot be watched for write events the same way that a file can. There would be no way to tell when a file was complete vs. when more content was coming in appended to the current file vs. when the contents was starting over with changes.

If you need this functionality you'll need to manually implement it yourself using a loop that notices some kind of EOF in the content stream itself and them ships it off to Typst in a discrete invocation.

Or did you just mean typst compile - ./test.pdf?

@oligo
Copy link
Author

oligo commented Apr 26, 2024

Hi @alerque,
I know the difference between a regular file and a stream, what confused me is that the command line help has this option under the watch sub command. So if this does not work, maybe it should be removed from the doc? Below is part of the current help doc for typst watch:

Watches an input file and recompiles on changes

Usage: typst watch [OPTIONS] [OUTPUT]

Arguments:

Path to input Typst file, use - to read input from stdin

[OUTPUT]
Path to output file (PDF, PNG, or SVG)

I am using the below command to read from STDIN and it works. Thank you!

Or did you just mean typst compile - ./test.pdf?

@alerque
Copy link
Contributor

alerque commented Apr 26, 2024

I am not able to make sense of your situation.

For starters:

Issue: I use the following command to read from stdin but watch does not compile.

This is not accurate, it does in fact compile, what it doesn't do is recompile since there is no way to send a new batch of content to the same stream. echo foo | typst watch - foo.pdf will in fact render the PDF, but since the input stream ended and there isn't any way to renew it the "watch" functionality is endlessly sitting there waiting for changes to a node that does not exist any more and never will.

The help docs perhaps could use updating, but I'm confused there too because the output I get from typst watch --help or man typst watch are both different than what you have quoted. I'm using the tagged v0.11.0 release, which you claim as well. Is it possible you're actually using a development version that is newer than than (Typst doesn't identify exact revisions internally for Git HEAD builds).

The docs for watch probably just re-use the help info for compile which is not completely correct and could possibly be fixed, but first ... what help docs are you actually looking at?

@oligo
Copy link
Author

oligo commented Apr 26, 2024

Please see the screenshot attached.
image

The help docs should be the same and I can confirm that I am using a stable version.

This is not accurate, it does in fact compile, what it doesn't do is recompile since there is no way to send a new batch of content to the same stream.

This is what confused me most. As per my understanding the name suggests watch should recompile but STDIN can not be updated so there is no way to recompile, and typst is just waiting there doing nothing. Anyway I think the doc might better be updated to explain this kind of situation. Or it should just tell the users to use compile command directly.

@laurmaedje
Copy link
Member

laurmaedje commented Apr 29, 2024

Not sure whether we can easily adjust the comments there as it's reused on the code level.

@laurmaedje laurmaedje added docs Improvements or additions to documentation and removed bug Something isn't working labels Apr 29, 2024
@laurmaedje laurmaedje changed the title Watch from stdin not work CLI help could be clearer about interaction of watching and stdin input Apr 29, 2024
@laurmaedje laurmaedje added the cli About Typst's command line interface. label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli About Typst's command line interface. docs Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants