mfontanini / presenterm

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

Best way to display multi-line blocks? #349

Closed chris-t-jansen closed 10 hours ago

chris-t-jansen commented 3 weeks ago

I've been playing around with presenterm for a coding presentation I have coming up, and I was wondering if there's a good way to render multi-line things like ASCII art without using images or potentially code blocks?

block_example

To be more specific, I want to use things like stylized ASCII text or QR codes in my presentation, but I can't find a satisfactory way to insert those in a way that I feel looks good. Putting them in code blocks like in the photo above works in terms of getting them to render in the presentation, but then they have the colored background; I can remove the background using themes/config, but I want the background for the actual code blocks, just not these "display" blocks, and I can't find a way to conditionally format anything in the documentation.

Apologies if this is a vague/strange question, I'm happy to clarify if that would help.

I can think of some ways to potentially implement this if it doesn't exist, but I'm not sure if any of them are idiomatic for the project, or if this idea is even within the scope of the project at all.

chris-t-jansen commented 3 weeks ago

I was kind of able to achieve this using the 4-whitespaces for a line-break and   for the leading spaces, and the result isn't bad. That said, the code for it is pretty messy, and has to be adjusted by hand to achieve the desired result.

slightly_better
 ██████  ██████       ██████  ██████  ██████  ███████ ███████    
██    ██ ██   ██     ██      ██    ██ ██   ██ ██      ██          
██    ██ ██████      ██      ██    ██ ██   ██ █████   ███████     
██ ▄▄ ██ ██   ██     ██      ██    ██ ██   ██ ██           ██     
 ██████  ██   ██      ██████  ██████  ██████  ███████ ███████     
    ▀▀

I don't think the above method allows for centering the text, either; you could do three columns and use only the middle one, but the left-justified text in the middle column would still be slightly off. If there's a better way to achieve this, I'd still love to know it.

DrunkenToast commented 3 weeks ago

This is where I would use +exec_replace added in #330. However, I can see that it currently adds an execution background color and has a min width, which I would say is unexpected behaviour.

``bash +exec_replace echo "https://github.com/mfontanini/presenterm" | qrencode -t utf8i` ```

Currently results in this: image

Where ansiutf8i is: image

@mfontanini Perhaps +exec_replace should not draw a background color?

mfontanini commented 3 weeks ago

Thanks for commenting here, I was going to suggest this too. On the background color: I think maybe a new +transparent_background or +no_background option would make sense here? e.g. use +exec_replace +no_background. Otherwise maybe you do want a background sometimes? I dunno, I've never used exec_replace and have no real use cases.

chris-t-jansen commented 3 weeks ago

Personally, I'm a fan of the +no_background flag. While I'm sure it will have a small impact on the complexity of presentations that choose to use it, I think it could be useful in a couple different situations. It would most likely solve my use case.

DrunkenToast commented 3 weeks ago

Thanks for commenting here, I was going to suggest this too. On the background color: I think maybe a new +transparent_background or +no_background option would make sense here? e.g. use +exec_replace +no_background. Otherwise maybe you do want a background sometimes? I dunno, I've never used exec_replace and have no real use cases.

Sounds great! Only want to point out that there is some ambiguity with whether it'll remove the background from the codeblock or the output pane, or both :)

chris-t-jansen commented 3 weeks ago

I think transparent for both makes the most sense from an end-user perspective. Setting a +no_background flag on a code block only to have the output pane still have a background feels like it would raise eyebrows, at least personally.

Alternatively, there could be a +no_exec_background flag as well as a +no_background flag to be clearer, but I wonder if there's a real use case for that level of granularity. It seems to open the door to the idea of having override flags for every styling property, which, while I would use, I'm not sure many would.

mfontanini commented 3 days ago

Sorry it took me a bit to get to this. I created #363 to address the issue. I ended up creating +no_margin instead of +no_background because of the comments raised above. This is what you actually want: you don't want presenterm to add extra margin, you just want whatever output the program that you run generates to be displayed as-is. Running qrencode now yields something like.

image

chris-t-jansen commented 2 days ago

Apologies, I don't think I explained my original issue very clearly. The +no_margin flag is a great addition to presenterm, so I'm happy that the discussion has born fruit! However, #363 doesn't solve the particular issue I'm having.

What I'm looking for is to be able to display text in some kind of raw, unprocessed form. Markdown automatically does things like squashing whitespaces and italicizing words with asterisks (*) around them, which is great, but I want to display arbitrary multi-line text (like ASCII art/text) without the automatic formatting and processing, so that it displays exactly the text I put into it. The QR code was one example of that usage, but the ASCII text is actually more interesting to me than running the bash to generate the QR code.

The best solution I could find was to use code blocks, which display all the text put into them as written (with some exception). My problem with this approach, however, is the code blocks backgrounds, which I don't want present when putting something in a code block for "display purposes" (i.e. large ASCII text for a large header). However, as far as I have found, backgrounds on code blocks are only changeable at a theme-level (which affects every code block in the entire presentation), and not an individual block-level. Thus, there is no way that I know of to have my actual code snippets in a code block with a background, but put for-display text (like ASCII art/text) in a code block without a background.

The only other solution I found was the one I mentioned in my second comment where I did it in regular Markdown using   tags and a certain number of spaces at the end of the line. However, that process was both difficult and mired with drawbacks, so I really think it's worse than the code blocks solution.

While I think the +no_margin flag is awesome, and would probably be super useful in addition to what I'm asking about, it doesn't solve my original issue. I think the suggested +no_background flag is closer to what I'm looking for than the +no_margin flag.

Like I said previously, it's fine if this isn't within the scope of the project; I'm not contractually obligated to use presenterm or anything like that! I just think the project is awesome, and I figured I'd throw my two-cents in as to how it might potentially be improved. Again, apologies for the miscommunication on my part.

mfontanini commented 2 days ago

Sorry, I got stuck on the QR code example which I think looks alright because there's no background in between characters. But looking at some text -> ascii art example it makes sense that +no_background is what you want. I'll see if maybe I pack what I did with no_margin into a no_background that does both things (remove background and margins; this sounds the same but internally it has a different meaning).

chris-t-jansen commented 2 days ago

The QR code example is honestly awesome, and frankly cooler than my original request, so I can't say I blame you! And I think if I were generating the ASCII text from an API call or something similar, then the +no_margin flag would probably help me more than my current approach of just copy-pasting the ASCII from somewhere else.

mfontanini commented 10 hours ago

Alright this should be fixed now. This doesn't yet work well in combination with exec or exec_replace but you're not using those so you should be good. If something looks off, please let me know! See #368 for example usage.