summaryrefslogtreecommitdiffstats
path: root/src/render
diff options
context:
space:
mode:
Diffstat (limited to 'src/render')
-rw-r--r--src/render/markdown.rs4
-rw-r--r--src/render/repl.rs9
2 files changed, 11 insertions, 2 deletions
diff --git a/src/render/markdown.rs b/src/render/markdown.rs
index f491fc1..f300854 100644
--- a/src/render/markdown.rs
+++ b/src/render/markdown.rs
@@ -205,7 +205,9 @@ impl MarkdownRender {
fn wrap(text: &str, width: usize) -> String {
let indent: usize = text.chars().take_while(|c| *c == ' ').count();
- let wrap_options = textwrap::Options::new(width).initial_indent(&text[0..indent]);
+ let wrap_options = textwrap::Options::new(width)
+ .wrap_algorithm(textwrap::WrapAlgorithm::FirstFit)
+ .initial_indent(&text[0..indent]);
textwrap::wrap(&text[indent..], wrap_options).join("\n")
}
diff --git a/src/render/repl.rs b/src/render/repl.rs
index 31c597e..34212c3 100644
--- a/src/render/repl.rs
+++ b/src/render/repl.rs
@@ -70,7 +70,9 @@ fn repl_render_stream_inner(
cursor::MoveTo(0, 0),
)?;
}
- queue!(writer, terminal::Clear(terminal::ClearType::UntilNewLine))?;
+
+ // No guarantee that text returned by render will not be re-layouted, so it is better to clear it.
+ queue!(writer, terminal::Clear(terminal::ClearType::FromCursorDown))?;
if text.contains('\n') {
let text = format!("{buffer}{text}");
@@ -79,6 +81,9 @@ fn repl_render_stream_inner(
let output = render.render(head);
print_block(writer, &output, columns)?;
queue!(writer, style::Print(&buffer),)?;
+
+ // No guarantee the buffer width of the buffer will not exceed the number of columns.
+ // So we calcuate the number of rows needed, rather than setting it directly to 1.
buffer_rows = need_rows(&buffer, columns);
} else {
buffer = format!("{buffer}{text}");
@@ -87,6 +92,8 @@ fn repl_render_stream_inner(
let (head, tail) = split_line_tail(&output);
buffer_rows = print_block(writer, head, columns)?;
queue!(writer, style::Print(&tail),)?;
+
+ // Same as above.
buffer_rows += need_rows(tail, columns);
} else {
queue!(writer, style::Print(&output))?;