qo / term

emulate terminal screenshots in typst
16 stars 1 forks source link

can output be extracted from a file? #1

Open alperyilmaz opened 5 months ago

alperyilmaz commented 5 months ago

Hi, Thanks for the template. I was wondering, is it possible to get the output from an existing file in the folder?

A hypothetical example would be:

#term(
  ps1: [`$`],
  input: [`ls -la`],
  output: [filename:"ls-output.txt"],
)
qo commented 5 months ago

Hi, Thanks for the template. I was wondering, is it possible to get the output from an existing file in the folder?

A hypothetical example would be:

#term(
  ps1: [`$`],
  input: [`ls -la`],
  output: [filename:"ls-output.txt"],
)

Hi! You can read the file using data loading in Typst, and then put the loaded data to the output parameter.

Here I compile the following document:

#import "term.typ": term

#let my_file_content = raw(read("my_file"))

#figure(
  term(
    ps1: [`$`],
    input: [`cat my_file`],
    output: my_file_content,
  ),
  caption: [Content of my_file],
)

Beforehand I ran the following command:

echo "Here is the content" > my_file

So the result is the following:

image

alperyilmaz commented 5 months ago

thanks for the detailed answer.. I'm new to typst and I keep forgetting that typst is actually a language. If you don't mind can I ask file and terminal related questions?

  1. Is it possible to have the command ls -alh for example as input, but the output is actually generated by running it in terminal? If that's easy, then I won't need to keep output of each command I have to demonstrate, I can run them during compile.
  2. I am writing a book about data analysis in terminal, hence I have lots of code examples in files. But my files have the code and output in the file. So, I need to leave input empty in term. But then I think there's a space left. Is it possible to skip input without leaving a space? Below, I left ps1 and input empty because the command and its output is coming from the file. But then there's blank line on top.

image

qo commented 5 months ago

thanks for the detailed answer.. I'm new to typst and I keep forgetting that typst is actually a language. If you don't mind can I ask file and terminal related questions?

  1. Is it possible to have the command ls -alh for example as input, but the output is actually generated by running it in terminal? If that's easy, then I won't need to keep output of each command I have to demonstrate, I can run them during compile.
  2. I am writing a book about data analysis in terminal, hence I have lots of code examples in files. But my files have the code and output in the file. So, I need to leave input empty in term. But then I think there's a space left. Is it possible to skip input without leaving a space? Below, I left ps1 and input empty because the command and its output is coming from the file. But then there's blank line on top.

image

Sorry for the wait.

Answer 1

As far as I know, Typst can't run commands via shell at compile time. You might wanna ask on Typst Github though.

Answer 2

My use case is storing input and output files separately, just like I showed in the previous example.

However what you're saying makes sense. I'd like this template to be more universal and work like carbon. So I'll get rid of three arguments and make it a one.

I just pushed the changes. See examples. Thanks for helping me out!