sakurs_cli/output/
text.rs1use super::OutputFormatter;
4use anyhow::Result;
5use std::io::{self, Write};
6
7pub struct TextFormatter<W: Write> {
9 writer: W,
10}
11
12impl<W: Write> TextFormatter<W> {
13 pub fn new(writer: W) -> Self {
15 Self { writer }
16 }
17}
18
19impl TextFormatter<io::Stdout> {
20 pub fn stdout() -> Self {
22 Self::new(io::stdout())
23 }
24}
25
26impl<W: Write + Send + Sync> OutputFormatter for TextFormatter<W> {
27 fn format_sentence(&mut self, sentence: &str, _offset: usize) -> Result<()> {
28 writeln!(self.writer, "{}", sentence.trim())?;
29 Ok(())
30 }
31
32 fn finish(&mut self) -> Result<()> {
33 self.writer.flush()?;
34 Ok(())
35 }
36}