diff options
| author | LLLL Colonq <llll@colonq> | 2025-01-31 13:50:14 -0500 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2025-01-31 13:50:14 -0500 |
| commit | c4f96d2b3f3b3878d6e0bbca7e0c4cd3f5d8bc85 (patch) | |
| tree | 422e7075f191badb3ccee2c02bd24332e6ee5b9e /src/common/overlay/terminal.rs | |
| parent | 7e1ccc9f3e83d7b807ffaa7706085437df69fb67 (diff) | |
Terminal (it doesn't do the colors right for some reason)
Diffstat (limited to 'src/common/overlay/terminal.rs')
| -rw-r--r-- | src/common/overlay/terminal.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/common/overlay/terminal.rs b/src/common/overlay/terminal.rs index 1b8df4c..e631899 100644 --- a/src/common/overlay/terminal.rs +++ b/src/common/overlay/terminal.rs @@ -1,3 +1,6 @@ +use std::io::Write; +use colored::Colorize; + use teleia::*; pub const WIDTH: usize = 64; @@ -164,4 +167,32 @@ impl Terminal { } self.font.render_text_helper(ctx, pos, &s, &colors); } + pub fn write_tty<W>(&self, out: &mut W) + where W: Write { + let mut output: Vec<u8> = Vec::new(); + write!(output, "\x1b[2J\x1b[1;1H").expect("failed to write output"); + for row in 0..64 { + for col in 0..64 { + let pos = Pos::new(col, row); + let c = self.get_color(pos); + let new = if let Some(p) = self.set_char.get(pos) { + if c == glam::Vec3::new(0.0, 0.0, 0.0) { + String::from(" ") + } else if let Some(pat) = self.outline_pattern(pos) { + pat + } else { + format!("{}{}", p.first, if let Some(snd) = p.second { snd } else { ' ' }) + } + } else { + String::from(" ") + }; + write!( + output, "{}", + new.truecolor((c.x * 255.0) as u8, (c.y * 255.0) as u8, (c.z * 255.0) as u8) + ).unwrap(); + } + write!(output, "\r\n").unwrap(); + } + out.write(&output).expect("failed to write to terminal"); + } } |
