small software-rendered rust tty
truecolor
bendn 9 months ago
parent 90c58b4 · commit a9ce0c8
-rw-r--r--src/main.rs2
-rw-r--r--src/render.rs101
-rw-r--r--src/term.rs40
3 files changed, 85 insertions, 58 deletions
diff --git a/src/main.rs b/src/main.rs
index 47055e0..026dce2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -206,7 +206,7 @@ fn tpaxrse() {
println!("-------------------");
let mut x = TerminalInputParser::new();
for c in
- "\x1b[32;1mgren\x1b[33myellow\x1b[42mbggreen\x1b[0m".as_bytes()
+ " ▀▀".as_bytes()
{
use ctlfun::TerminalInput::*;
match x.parse_byte(*c) {
diff --git a/src/render.rs b/src/render.rs
index 1d7f3b9..3ee5581 100644
--- a/src/render.rs
+++ b/src/render.rs
@@ -18,62 +18,65 @@ pub fn render(
let sz = ppem * (m.max_width / m.units_per_em as f32);
let mut i = Image::build(w as _, h as _).fill(colors::BACKGROUND);
for (col, k) in x.cells.chunks_exact(x.size.0 as _).zip(0..).skip(1) {
- for (cell, j) in
- col.iter().skip(2).zip(0..).filter(_.0.letter.is_some())
- {
- let id = FONT.charmap().map(cell.letter.unwrap());
-
- let x = Render::new(&[Source::Outline])
- .format(Format::Alpha)
- .render(
- &mut ScaleContext::new()
- .builder(*FONT)
- .size(ppem)
- .build(),
- id,
- )
- .unwrap();
- unsafe {
- if x.placement.width == 0 {
- continue;
- }
- let item = Image::<_, 4>::build(
- x.placement.width,
- x.placement.height,
+ for (cell, j) in col.iter().skip(2).zip(0..) {
+ if cell.style.bg != colors::BACKGROUND {
+ let cell = Image::<_, 4>::build(
+ sz.ceil() as u32,
+ (ppem * 1.25).ceil() as u32,
)
- .buf(
- x.data
- .iter()
- .flat_map(|&x| cell.style.color.join(x))
- .collect::<Vec<u8>>(),
- );
- if cell.style.bg != colors::BACKGROUND {
- let cell = Image::<_, 4>::build(
- sz.ceil() as u32,
- (ppem * 1.25).ceil() as u32,
- )
- .fill(cell.style.bg.join(255));
+ .fill(cell.style.bg.join(255));
+ unsafe {
i.as_mut().overlay_at(
&cell,
4 + (j as f32 * sz) as u32,
(k as f32 * (ppem * 1.25)) as u32 - 20,
+ )
+ };
+ }
+ if let Some(l) = cell.letter {
+ let id = FONT.charmap().map(l);
+
+ let x = Render::new(&[Source::Outline])
+ .format(Format::Alpha)
+ .render(
+ &mut ScaleContext::new()
+ .builder(*FONT)
+ .size(ppem)
+ .build(),
+ id,
+ )
+ .unwrap();
+ unsafe {
+ if x.placement.width == 0 {
+ continue;
+ }
+ let item = Image::<_, 4>::build(
+ x.placement.width,
+ x.placement.height,
+ )
+ .buf(
+ x.data
+ .iter()
+ .flat_map(|&x| cell.style.color.join(x))
+ .collect::<Vec<u8>>(),
);
- }
- i.as_mut().overlay_blended_at(
- &item.as_ref(),
- // &Image::<Box<[u8]>, 4>::from(
- // Image::<_, 1>::build(
- // x.placement.width,
- // x.placement.height,
- // )
- // .buf(&*x.data),
- // )
- // .as_ref(),
- 4 + ((j as f32 * sz) + x.placement.left as f32) as u32,
- ((k as f32 * (ppem * 1.25)) as u32)
- .saturating_sub(x.placement.top as u32),
- );
+ i.as_mut().overlay_blended_at(
+ &item.as_ref(),
+ // &Image::<Box<[u8]>, 4>::from(
+ // Image::<_, 1>::build(
+ // x.placement.width,
+ // x.placement.height,
+ // )
+ // .buf(&*x.data),
+ // )
+ // .as_ref(),
+ 4 + ((j as f32 * sz) + x.placement.left as f32)
+ as u32,
+ ((k as f32 * (ppem * 1.25)) as u32)
+ .saturating_sub(x.placement.top as u32),
+ );
+ }
}
}
}
diff --git a/src/term.rs b/src/term.rs
index 6c0c453..b3c22f7 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -73,22 +73,46 @@ impl Terminal {
params,
end: b'm',
..
- }) => match params.get(0).map(*_).unwrap() {
- Value(0) => self.style = Style::default(),
- Value(x @ (30..=37)) => {
+ }) => match params {
+ &[Value(0)] => self.style = Style::default(),
+ &[Value(x @ (30..=37))] => {
self.style.color = colors::FOUR[x as usize - 30]
}
- Value(39) => self.style.color = colors::FOREGROUND,
- Value(x @ (40..=47)) => {
+ &[Value(39)] => self.style.color = colors::FOREGROUND,
+ &[Value(x @ (40..=47))] => {
self.style.bg = colors::FOUR[x as usize - 40]
}
- Value(49) => self.style.bg = colors::BACKGROUND,
- Value(x @ (90..=97)) => {
+ &[Value(49)] => self.style.bg = colors::BACKGROUND,
+ &[Value(x @ (90..=97))] => {
self.style.color = colors::FOUR[x as usize - 72]
}
- Value(x @ (100..=107)) => {
+ &[Value(x @ (100..=107))] => {
self.style.bg = colors::FOUR[x as usize - 92]
}
+ &[Value(38), Value(2), Value(r), Value(g), Value(b)] => {
+ self.style.color =
+ [r, g, b].map(|x| x.min(0xff) as u8);
+ }
+ &[Value(48), Value(2), Value(r), Value(g), Value(b)] => {
+ self.style.bg = [r, g, b].map(|x| x.min(0xff) as u8);
+ }
+ &[
+ Value(38),
+ Value(2),
+ Value(r),
+ Value(g),
+ Value(b),
+ Value(48),
+ Value(2),
+ Value(rb),
+ Value(gb),
+ Value(bb),
+ ] => {
+ self.style.bg =
+ [rb, gb, bb].map(|x| x.min(0xff) as u8);
+ self.style.color =
+ [r, g, b].map(|x| x.min(0xff) as u8);
+ }
_ => {}
},
Control(ControlFunction {