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:
sigoden 2023-03-08 21:34:20 +08:00 committed by GitHub
parent 56483e04f0
commit 9d32837669
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 5 deletions

View File

@ -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 {

View File

@ -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();

View File

@ -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;
}

View File

@ -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(())