pub trait Media {
    fn print(&mut self, buf: &[u8]);
}

#[derive(Debug, Default)]
pub struct FakeOutputDevice {
    last_write: Vec<u8>,
}

impl FakeOutputDevice {
    pub fn last_write(&self) -> &[u8] {
        &self.last_write
    }
}

impl Media for FakeOutputDevice {
    fn print(&mut self, buf: &[u8]) {
        self.last_write = buf.into();
    }
}

pub struct StdOutput {}

impl StdOutput {
    pub fn new() -> Self {
        Self {}
    }
}

impl Media for StdOutput {
    fn print(&mut self, buf: &[u8]) {
        println!("{}", String::from_utf8_lossy(buf));
    }
}
