mfontanini / presenterm

A markdown terminal slideshow tool
https://mfontanini.github.io/presenterm/
BSD 2-Clause "Simplified" License
1.37k stars 34 forks source link

Allow code execution #4

Closed baduhai closed 1 year ago

baduhai commented 1 year ago

It would be great if presenterm had code execution the way slides does. You'd have a code block, and by pressing ctrl+e the code block would be executed.

mfontanini commented 1 year ago

I've seen this feature in slides and I'm curious what exactly is the use case. IMO this goes against what I'd want in a presentation: you now turn it into a live demo where a typo or the state of your system may cause the command being run to fail. I'm also curious how many times per presentation you'd put a block of executable code that it would be worth it to have this vs running the command and pasting the output yourself.

I'm not saying I don't want to implement this (I've considered whether it's worth it a couple of times actually), I'd like to understand what people use it for before doing so.

baduhai commented 1 year ago

Fair enough, then here's what I would like to use it for specifically. I'm currently giving some lectures on networking, and one of the lessons is on packet tracing. I want to be able to show a command and execute the command within the presentation. In the slide I would have something like:

\```bash
#!/usr/bin/env bash

traceroute google.com
\```

And ctrl+e would give me the output of the script within the presentation, this is just a simple example, but it gets the point across. Since I've switched from slides to presenterm due to image support, I've been missing this feature. Right now I pop out of the presentation and run any script I need to myself, which isn't a big deal, but it would just look tidier if the presentation was self-contained.

mfontanini commented 1 year ago

Okay that's a fair use case. Do you ever use more than one executable block within a single slide? Would ctrl+e execute them one by one every time you press, top to bottom? Or would you expect them all to be executed at once?

baduhai commented 1 year ago

I pretty much only ever have one code block per slide. I don't think it makes much sense to have more than one code block per slide, since you need space to show the output of what you execute.

But I guess if I were to put more than one executable code block in the same slide, I could see myself executing one by one top to bottom, and maybe the output of the second overwrites the output of the first.

mfontanini commented 1 year ago

Great, thanks! I'll think about it a bit and implement that next. I'll ping you for feedback once it's getting in shape.

mfontanini commented 1 year ago

Hey! I still need to polish a few things but it's shaping up. I went with a syntax like

```bash +exec
echo hi

So that it's explicit that you want that code to be executable. This is a demo of how it currently looks like; it streams the output as it gets spit out:

asciicast

Any thoughts on style or anything you'd like different? I'll probably at least add a configurable background/foreground color and extend the background all the way to the right so it looks like a code block.

baduhai commented 1 year ago

Brilliant! The only thing I would add would be a different background colour to the output, but it looks like you already have that in mind :)

Btw, I'm going to submit a package for presenterm to nixpkgs, would you like to be added as a maintainer?