use core::ops::{Index, IndexMut};
#[derive(Clone, Default, Copy, Debug, Eq, PartialEq)]
pub enum StandardCharset {
#[default]
Ascii,
#[allow(unused)]
SpecialCharacterAndLineDrawing,
}
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
pub struct Charsets([StandardCharset; 4]);
#[derive(Clone, Default, Copy, Debug, Eq, PartialEq)]
pub enum CharsetIndex {
#[default]
G0,
#[allow(dead_code)]
G1,
#[allow(dead_code)]
G2,
#[allow(dead_code)]
G3,
}
impl Index<CharsetIndex> for Charsets {
type Output = StandardCharset;
fn index(&self, index: CharsetIndex) -> &StandardCharset {
&self.0[index as usize]
}
}
impl IndexMut<CharsetIndex> for Charsets {
fn index_mut(&mut self, index: CharsetIndex) -> &mut StandardCharset {
&mut self.0[index as usize]
}
}
impl StandardCharset {
#[inline]
#[allow(dead_code)]
pub fn map(self, c: char) -> char {
match self {
StandardCharset::Ascii => c,
StandardCharset::SpecialCharacterAndLineDrawing => match c {
'_' => ' ',
'`' => '◆',
'a' => '▒',
'b' => '\u{2409}', 'c' => '\u{240c}', 'd' => '\u{240d}', 'e' => '\u{240a}', 'f' => '°',
'g' => '±',
'h' => '\u{2424}', 'i' => '\u{240b}', 'j' => '┘',
'k' => '┐',
'l' => '┌',
'm' => '└',
'n' => '┼',
'o' => '⎺',
'p' => '⎻',
'q' => '─',
'r' => '⎼',
's' => '⎽',
't' => '├',
'u' => '┤',
'v' => '┴',
'w' => '┬',
'x' => '│',
'y' => '≤',
'z' => '≥',
'{' => 'π',
'|' => '≠',
'}' => '£',
'~' => '·',
_ => c,
},
}
}
}