diff options
| author | sigoden <sigoden@gmail.com> | 2023-11-14 08:53:21 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-14 08:53:21 +0800 |
| commit | 9b0fbe35066d9ae3e3984e11deee72f80c2df35c (patch) | |
| tree | cd5ea7a1ff79552a8b59eb8aaf83d96591ad3fd2 /src | |
| parent | 542dcfe6f6a33d8066009b88ae19bb3f54f8d6a5 (diff) | |
| download | aichat-9b0fbe35066d9ae3e3984e11deee72f80c2df35c.tar.gz | |
fix: the last reply tokens was not highlighted (#243)
Diffstat (limited to 'src')
| -rw-r--r-- | src/render/stream.rs | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/src/render/stream.rs b/src/render/stream.rs index ad35dec..bc56db8 100644 --- a/src/render/stream.rs +++ b/src/render/stream.rs @@ -102,28 +102,25 @@ fn markdown_stream_inner( if text.contains('\n') { let text = format!("{buffer}{text}"); let (head, tail) = split_line_tail(&text); - buffer = tail.to_string(); let output = render.render(head); print_block(writer, &output, columns)?; - queue!(writer, style::Print(&buffer),)?; + buffer = tail.to_string(); + } else { + buffer = format!("{buffer}{text}"); + } + + let output = render.render_line(&buffer); + if output.contains('\n') { + let (head, tail) = split_line_tail(&output); + buffer_rows = print_block(writer, head, columns)?; + queue!(writer, style::Print(&tail),)?; // No guarantee the buffer width of the buffer will not exceed the number of columns. // So we calculate the number of rows needed, rather than setting it directly to 1. - buffer_rows = need_rows(&buffer, columns); + buffer_rows += need_rows(tail, columns); } else { - buffer = format!("{buffer}{text}"); - let output = render.render_line(&buffer); - if output.contains('\n') { - 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))?; - buffer_rows = need_rows(&output, columns); - } + queue!(writer, style::Print(&output))?; + buffer_rows = need_rows(&output, columns); } writer.flush()?; |
