Comments (6)
+1. I also wonder how this can be implemented. My current idea to work around this is to print raw strings and store these chunks, then once the completion is finished, clear the previous output and render the full content in md using termimad.
from termimad.
A word of caution: termimad isn't a universal renderer (there's not even any support for images). Its main use cases are for building terminal applications and it may not be suited to render what chatgpt outputs (no idea here).
from termimad.
OK, I'm looking into it and will try to make a PR to add a simpler example.
from termimad.
Why wait for the end ? If you receive those chunks in an application, you can render them like in this example: https://github.com/Canop/termimad/tree/main/examples/render-input-markdown
from termimad.
OK
from termimad.
I think this is the minimum code to do this
use std::io::{stdout, Write};
use std::thread::sleep;
use termimad::crossterm::{cursor, ExecutableCommand};
use termimad::{FmtText, MadSkin};
use termimad::crossterm::terminal::Clear;
use termimad::crossterm::terminal::ClearType::FromCursorDown;
const MARKDOWN_TEXT: &str = r#"
# Hello
This is inline code `print("hello")`.
// wrap the below line in a code block
print("hello")
Here ends it.
"#;
fn main() {
let skin = MadSkin::default();
stdout().execute(cursor::Hide).unwrap();
let mut string_buffer = String::new();
for (i, chunk) in MARKDOWN_TEXT.chars().enumerate() {
stdout()
.execute(cursor::SavePosition).unwrap()
.execute(Clear(FromCursorDown)).unwrap();
string_buffer.push(chunk);
let formatted_text = FmtText::from(&skin, &string_buffer, None); // can have Some(width) to enable hard wrapping
print!("{}", formatted_text);
stdout().flush().unwrap();
let is_last_one = i == MARKDOWN_TEXT.len() - 1;
if !is_last_one {
stdout().execute(cursor::RestorePosition).unwrap();
}
sleep(std::time::Duration::from_millis(100));
}
stdout().execute(cursor::Show).unwrap();
sleep(std::time::Duration::from_millis(500));
}
I got the idea from
and
These two lines essentially do the same, which is rendering over and over again rather than incrementally rendering texts.
from termimad.
Related Issues (20)
- Cannot escape markdown characters HOT 5
- board creation returns 500 HOT 2
- Update to crossterm 0.20.0 HOT 5
- provide simple render as a binary HOT 5
- Termimad Parses some random text when used with TUI HOT 2
- Pass InputField into a MadSkin HOT 5
- example compile error on M1 mac
- Crossterm 0.25.0 breaking changes HOT 4
- Cannot compile inputs or render-input-markdown examples HOT 6
- Rendering inline code with newlines HOT 4
- Feature request: please add custom style syntax HOT 1
- Indented list rendering HOT 5
- How to render a code block that has new lines in it in one block. HOT 2
- Display fenced code block issue HOT 3
- Hyperlinks are not rendered correctly HOT 10
- Code blocks are 100 columns even if `Some(< 100)` is passed to `text` HOT 2
- "coloor" dependency introduces LGPL-3.0 HOT 4
- Lone newlines not interpreted as space HOT 1
- Incorrect handling of list entry text
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from termimad.