sakurs_cli/output/
text.rs

1//! Plain text output formatter
2
3use super::OutputFormatter;
4use anyhow::Result;
5use std::io::{self, Write};
6
7/// Plain text formatter - outputs one sentence per line
8pub struct TextFormatter<W: Write> {
9    writer: W,
10}
11
12impl<W: Write> TextFormatter<W> {
13    /// Create a new text formatter
14    pub fn new(writer: W) -> Self {
15        Self { writer }
16    }
17}
18
19impl TextFormatter<io::Stdout> {
20    /// Create a formatter that writes to stdout
21    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}