From eb30d90391ef73429589a98f34dfe4d3d88d0a38 Mon Sep 17 00:00:00 2001 From: sigoden Date: Wed, 8 Nov 2023 18:26:38 +0800 Subject: refactor: improve render (#235) * refactor: redesign render - if stdout is not terminal, just write reply text to stdout - rename repl_render_stream to markdown_stream - deprecate cmd_render_stream - use raw_stream to just print streaming reply text * optimize rendering error * optimize render_stream --- src/render/markdown.rs | 40 ---------------------------------------- 1 file changed, 40 deletions(-) (limited to 'src/render/markdown.rs') diff --git a/src/render/markdown.rs b/src/render/markdown.rs index f300854..44e24b3 100644 --- a/src/render/markdown.rs +++ b/src/render/markdown.rs @@ -64,17 +64,6 @@ impl MarkdownRender { }) } - pub(crate) const fn is_code(&self) -> bool { - matches!( - self.prev_line_type, - LineType::CodeBegin | LineType::CodeInner - ) - } - - pub(crate) const fn wrap_width(&self) -> Option { - self.wrap_width - } - pub fn render(&mut self, text: &str) -> String { text.split('\n') .map(|line| self.render_line_mut(line)) @@ -82,16 +71,6 @@ impl MarkdownRender { .join("\n") } - pub fn render_with_indent(&mut self, text: &str, indent: usize) -> String { - let text = format!("{}{}", " ".repeat(indent), text); - let output = self.render(&text); - if output.starts_with('\n') { - output - } else { - output.chars().skip(indent).collect() - } - } - pub fn render_line(&self, line: &str) -> String { let (_, code_syntax, is_code) = self.check_line(line); if is_code { @@ -377,23 +356,4 @@ std::error::Error>> { let output = render.render(TEXT); assert_eq!(TEXT_WRAP_ALL, output); } - - #[test] - fn wrap_with_indent() { - let options = RenderOptions::default(); - let mut render = MarkdownRender::init(options).unwrap(); - render.wrap_width = Some(80); - - let input = "To unzip a file in Rust, you can use the `zip` crate. Here's an example code"; - let output = render.render_with_indent(input, 40); - let expect = - "To unzip a file in Rust, you can use the\n`zip` crate. Here's an example code"; - assert_eq!(output, expect); - - let input = "Unzip a file"; - let output = render.render_with_indent(input, 76); - let expect = "\nUnzip a file"; - - assert_eq!(output, expect); - } } -- cgit v1.2.3