Skip to content

Commit

Permalink
utf-8: moved codepage into a constant, and encoder into pixel impl
Browse files Browse the repository at this point in the history
  • Loading branch information
cab404 committed Feb 9, 2020
1 parent 083d630 commit f606807
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/render/utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use crate::render::{Canvas as RenderCanvas, Pixel, Color};

const CODEPAGE: [&str; 4] = [" ","\u{2584}","\u{2580}","\u{2588}"];

#[derive(Copy, Clone, PartialEq)]
pub enum Unicode1x2 {
Expand All @@ -22,6 +23,10 @@ impl Unicode1x2 {
Unicode1x2::Light => {0}
}
}
#[doc(hidden)]
fn parse_2_bits(sym: &u8) -> &'static str {
CODEPAGE[*sym as usize]
}
}

pub struct Canvas {
Expand Down Expand Up @@ -66,7 +71,7 @@ impl RenderCanvas for Canvas {
}
}.iter()
// Mapping those 2-bit numbers to corresponding pixels.
.map(|sym| [" ","\u{2584}","\u{2580}","\u{2588}"][*sym as usize])
.map(Unicode1x2::parse_2_bits)
.collect::<Vec<&str>>()
.concat()
)
Expand Down

0 comments on commit f606807

Please sign in to comment.