#[inline]
pub const fn dec_special_graphics(c: char) -> char {
match c {
'_' => ' ',
'`' => '◆',
'a' => '▒',
'b' => '␉',
'c' => '␌',
'd' => '␍',
'e' => '␊',
'f' => '°',
'g' => '±',
'h' => '',
'i' => '␋',
'j' => '┘',
'k' => '┐',
'l' => '┌',
'm' => '└',
'n' => '┼',
'o' => '⎺',
'p' => '⎻',
'q' => '─',
'r' => '⎼',
's' => '⎽',
't' => '├',
'u' => '┤',
'v' => '┴',
'w' => '┬',
'x' => '│',
'y' => '≤',
'z' => '≥',
'{' => 'π',
'|' => '≠',
'}' => '£',
'~' => '·',
_ => c,
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[non_exhaustive]
pub enum Charset {
Ascii,
Dec,
British,
}
impl Charset {
#[inline]
pub const fn map(self, c: char) -> char {
match self {
Self::Ascii => c,
Self::Dec => match c {
'\u{5f}'..='\u{7e}' => dec_special_graphics(c),
_ => c,
},
Self::British => {
if c == '#' {
'£'
} else {
c
}
}
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Charsets([Charset; 4]);
impl Charsets {
pub const fn ascii() -> Self {
Self([Charset::Ascii; 4])
}
pub fn designate(&mut self, g: usize, charset: Charset) {
self.0[g.min(3)] = charset;
}
pub const fn get(self, g: usize) -> Charset {
self.0[g]
}
pub const fn g0(self) -> Charset {
self.0[0]
}
pub const fn g1(self) -> Charset {
self.0[1]
}
pub const fn g2(self) -> Charset {
self.0[2]
}
pub const fn g3(self) -> Charset {
self.0[3]
}
}
impl Default for Charsets {
fn default() -> Self {
Self::ascii()
}
}
impl core::ops::Index<usize> for Charsets {
type Output = Charset;
fn index(&self, g: usize) -> &Charset {
&self.0[g]
}
}
impl core::ops::IndexMut<usize> for Charsets {
fn index_mut(&mut self, g: usize) -> &mut Charset {
&mut self.0[g]
}
}