mirror of
https://github.com/sigoden/aichat
synced 2024-11-18 09:28:27 +00:00
chore: optimize newline again (#43)
* chore: optimize newline again command mode: should no extra newline chat mode: should have one newline * fix windows newline * fix macos newline
This commit is contained in:
parent
56483e04f0
commit
9d32837669
@ -76,9 +76,9 @@ fn start_directive(
|
||||
let output = client.send_message(input)?;
|
||||
if highlight {
|
||||
let mut markdown_render = MarkdownRender::new();
|
||||
println!("{}\n", markdown_render.render(&output).trim_end());
|
||||
println!("{}", markdown_render.render(&output).trim());
|
||||
} else {
|
||||
println!("{}\n", output.trim_end());
|
||||
println!("{}", output.trim());
|
||||
}
|
||||
output
|
||||
} else {
|
||||
|
@ -37,10 +37,10 @@ pub fn render_stream(
|
||||
}
|
||||
drop(wg);
|
||||
});
|
||||
ReplyStreamHandler::new(Some(tx), abort_clone)
|
||||
ReplyStreamHandler::new(Some(tx), repl, abort_clone)
|
||||
} else {
|
||||
drop(wg);
|
||||
ReplyStreamHandler::new(None, abort)
|
||||
ReplyStreamHandler::new(None, repl, abort)
|
||||
};
|
||||
client.send_message_streaming(input, &mut stream_handler)?;
|
||||
let buffer = stream_handler.get_buffer();
|
||||
|
@ -70,6 +70,9 @@ fn repl_render_stream_inner(
|
||||
ReplyStreamEvent::Done => {
|
||||
let output = markdown_render.render_line_stateless(&buffer);
|
||||
queue!(writer, style::Print(output.trim_end()), style::Print("\n"))?;
|
||||
if cfg!(windows) {
|
||||
queue!(writer, style::Print("\n"))?;
|
||||
}
|
||||
writer.flush()?;
|
||||
break;
|
||||
}
|
||||
|
@ -97,14 +97,20 @@ pub struct ReplyStreamHandler {
|
||||
sender: Option<Sender<ReplyStreamEvent>>,
|
||||
buffer: String,
|
||||
abort: SharedAbortSignal,
|
||||
repl: bool,
|
||||
}
|
||||
|
||||
impl ReplyStreamHandler {
|
||||
pub fn new(sender: Option<Sender<ReplyStreamEvent>>, abort: SharedAbortSignal) -> Self {
|
||||
pub fn new(
|
||||
sender: Option<Sender<ReplyStreamEvent>>,
|
||||
repl: bool,
|
||||
abort: SharedAbortSignal,
|
||||
) -> Self {
|
||||
Self {
|
||||
sender,
|
||||
abort,
|
||||
buffer: String::new(),
|
||||
repl,
|
||||
}
|
||||
}
|
||||
|
||||
@ -132,6 +138,12 @@ impl ReplyStreamHandler {
|
||||
if !self.buffer.ends_with('\n') {
|
||||
print_now!("\n")
|
||||
}
|
||||
if self.repl {
|
||||
print_now!("\n");
|
||||
if cfg!(macos) {
|
||||
print_now!("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user