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
[Feature] Provide a Way to Escape Blocks of Content #8
Comments
You might be interested by that:
I hope to publish it this weekend (testing it in broot). In short: |
That looks great. 👍 One note: I would want to be able to do keyword arguments in the template. So something like |
Right now placeholders are Are named placeholders really necessary ? |
I have my docs in separate files like this that I include using Still it wouldn't be a problem for me to have |
That wouldn't work with the mad_ macros, as the templace is of type But:
|
It probably wouldn't be bad to use the Template type if we had to. It is a more involved setup to use a separate file for the doc anyway. |
Templating with names and sub-templates is coming soon. static TEMPLATE: &str = r#"
# ${app-name} v${app-version}
**${app-name}** is *fantastic*!
## Modules
In a table:
|:-:|:-:|:-:|
|**name**|**path**|**description**|
|-:|:-:|:-|
${module-rows
|**${module-name}**|`${app-version}/${module-key}`|${module-description}|
}
|-|-|-|
and the same data in another form:
${module-rows
### ${module-name} (${module-key})
${module-description}
}
## Items
${formatted-items
* **${item-name}:** `${item-code}`
}
"#;
fn main() -> Result<()> {
let skin = make_skin();
let text_template = TextTemplate::from(TEMPLATE);
let mut expander = text_template.expander();
expander
.set("app-name", "MyApp")
.set("app-version", "42");
expander.sub("module-rows")
.set("module-name", "lazy-regex")
.set("module-key", "lrex")
.set("module-description", "eases regexes");
expander.sub("module-rows")
.set("module-name", "termimad")
.set("module-key", "tmd")
.set("module-description", "do things on terminal");
expander.sub("formatted-items")
.set("item-name", "3*5")
.set("item-code", "187/12");
expander.sub("formatted-items")
.set("item-name", "π")
.set("item-code", "22/7");
let text = expander.expand();
let (width, _) = terminal_size();
let fmt_text = FmtText::from_text(&skin, text, Some(width as usize));
println!("{}", &fmt_text);
Ok(())
} |
Ooh, that looks pretty neat. Nice work. That will be more than I need. :) |
@zicklag I've published a new version with a description : https://github.com/Canop/termimad#templates It should close this issue. Please tell me how it works for you, though. |
Awesome, I can't wait to try it out. I'll let you know how it goes. |
It seems like there is no |
@zicklag I should make that clearer in the documentation: The TextTemplate is part of the Minimad library which is developed for Termimad and contains the Markdown making parts. You should have a look at how templates are used in broot: https://github.com/Canop/broot/blob/master/src/help_content.rs You'll need this in your dependencies:
|
Oh, perfect thanks. |
Oh that's pretty. I'll use it for a gallery if I can get a few other ones. I'd be interested by suggestions regarding the documentation. |
I'll take some more pictures when I get some more documentation written. 😉. The biggest problem I had API-wise was that I couldn't use the |
The current lifetime design of Minimad and Termimad minimizes memory and string copies but make a few things more complicated. Side note: rebuilding everything at each render is reasonable: it's fast enough (normally less than a ms). |
Yeah, the current design isn't bad or anything, it just isn't immediately apparent as a newbie. Also I'm new to terminal rendering so I had some confusion of when to flush the writer, etc.
That would be cool.
OK, thanks for the assurance of that. :) Also, I had some issue where, while scrolling, some of the text would get left over from previous lines in the command help. It only seems to happen in the command output. Anyway, I just ended up clearing the whole screen at every update. Is that a decent solution? It caused more flickering, but I'm on a slow SSH connection at the moment, so I think it probably won't be a problem in general. |
No, you should not clean the whole screen at every render, the flickering isn't acceptable in my opinion. There's a case of leftovers which happens when you resize the screen. That's why I usually do a screen cleaning at resize. If your screenshot isn't related to terminal resizing, then an investigation is in order (and I can help if you build a minimal reproducible example). And if it's confirmed, this should be another issue. |
OK, cool. I'll try to get a minimal example for you soonish. |
Here is a minimal demonstration: https://github.com/katharostech/termimad/tree/termimad-test/examples/colored-template-scroll. Maybe not completely minimal, but it is simple ( tell me if you need me to trim it down furthur ). The problem only happens when the text has to wrap a lot, and it only happens when color is enabled: Edit: Also, I'm pretty sure this was happening without the template, too, when I was just using |
I just published Termimad 0.8.1 which should solve the problem. Side note: crossterm has a function to get the size of the terminal, you don't need to import another crate for that. |
That worked! Thanks for the fix. 😃 Thanks for the crossterm tip. 👍 I'm really liking crossterm. Very nice API. |
I am trying to create manpage-like help pages using Termimad and I want to be able to inline the Clap commandline argument help into the document, but the styling for the help message gets a little confused because Termimad is interpreting the indentation in the help message as code blocks.
Could there be a way to make a whole block of the document so that it is taken literally instead of interpreted as Markdown syntax?
Maybe something like this:
The text was updated successfully, but these errors were encountered: