src/debug.rs

c18143d14a04b7f29f5bbd2ccaaad01003528f82
weechat-matrix-rs/src/debug.rs history · blame · raw

27 lines · 677 bytes

 1use std::io;
 2use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
 3use weechat::Weechat;
 4
 5#[derive(Clone)]
 6pub struct Debug();
 7
 8impl Debug {
 9    pub async fn write_helper(message: Vec<u8>) {
10        let message = String::from_utf8(message).unwrap();
11        let message =
12            Weechat::execute_modifier("color_decode_ansi", "1", &message)
13                .unwrap();
14        Weechat::print(&message)
15    }
16}
17
18impl io::Write for Debug {
19    fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
20        Weechat::spawn_from_thread(Debug::write_helper(buf.to_owned()));
21        Ok(buf.len())
22    }
23
24    fn flush(&mut self) -> io::Result<()> {
25        Ok(())
26    }
27}