diff options
| author | sigoden <sigoden@gmail.com> | 2024-09-06 06:38:29 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-06 06:38:29 +0800 |
| commit | b16913fec38f604ab045d6f16ddba62481b09a6c (patch) | |
| tree | 4cd36b11b85c4613e9022e423a06b40f7589a49c /src/render/stream.rs | |
| parent | d92f102a85eb98ee0cb3eaa8a775b7d3528090ac (diff) | |
| download | aichat-b16913fec38f604ab045d6f16ddba62481b09a6c.tar.gz | |
fix: render stream failed due to read cursor position timeout (#835)
Diffstat (limited to 'src/render/stream.rs')
| -rw-r--r-- | src/render/stream.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/render/stream.rs b/src/render/stream.rs index 042bfe5..2264c16 100644 --- a/src/render/stream.rs +++ b/src/render/stream.rs @@ -28,6 +28,9 @@ pub async fn markdown_stream( disable_raw_mode()?; + if ret.is_err() { + println!(); + } ret } @@ -78,7 +81,14 @@ async fn markdown_stream_inner( // tab width hacking text = text.replace('\t', " "); - let (col, mut row) = cursor::position()?; + let mut attempts = 0; + let (col, mut row) = loop { + match cursor::position() { + Ok(pos) => break pos, + Err(_) if attempts < 3 => attempts += 1, + Err(e) => return Err(e.into()), + } + }; // Fix unexpected duplicate lines on kitty, see https://github.com/sigoden/aichat/issues/105 if col == 0 && row > 0 && display_width(&buffer) == columns as usize { |
