use anyhow::Context;
use indicatif::TermLike;
use std::io::{Result as IoResult, Write};
#[derive(Debug)]
pub struct FileTerm {
pub file: std::fs::File,
}
impl FileTerm {
pub fn new(path: &str) -> anyhow::Result<Self> {
let file = std::fs::File::create(path).context(format!("Failed to create file: {path}"))?;
Ok(Self { file })
}
}
impl Write for FileTerm {
fn write(&mut self, buf: &[u8]) -> IoResult<usize> {
self.file.write(buf)
}
fn flush(&mut self) -> IoResult<()> {
self.file.flush()
}
}
impl TermLike for FileTerm {
fn write_line(&self, _: &str) -> IoResult<()> {
Ok(()) }
fn clear_line(&self) -> IoResult<()> {
Ok(()) }
fn move_cursor_up(&self, _: usize) -> IoResult<()> {
Ok(()) }
fn move_cursor_down(&self, _: usize) -> IoResult<()> {
Ok(()) }
fn move_cursor_left(&self, _: usize) -> std::io::Result<()> {
Ok(()) }
fn move_cursor_right(&self, _: usize) -> std::io::Result<()> {
Ok(()) }
fn width(&self) -> u16 {
2048 }
fn height(&self) -> u16 {
2048
}
fn flush(&self) -> std::io::Result<()> {
Ok(()) }
fn write_str(&self, _: &str) -> std::io::Result<()> {
Ok(()) }
}