mod constants {
pub const UPPER_HALF_BLOCK: char = '▀';
pub const LOWER_ONE_EIGHTH_BLOCK: char = '▁';
pub const LOWER_ONE_QUARTER_BLOCK: char = '▂';
pub const LOWER_THREE_EIGHTHS_BLOCK: char = '▃';
pub const LOWER_HALF_BLOCK: char = '▄';
pub const LOWER_FIVE_EIGHTHS_BLOCK: char = '▅';
pub const LOWER_THREE_QUARTERS_BLOCK: char = '▆';
pub const LOWER_SEVEN_EIGHTHS_BLOCK: char = '▇';
pub const FULL_BLOCK: char = '█';
pub const LEFT_SEVEN_EIGHTHS_BLOCK: char = '▉';
pub const LEFT_THREE_QUARTERS_BLOCK: char = '▊';
pub const LEFT_FIVE_EIGHTHS_BLOCK: char = '▋';
pub const LEFT_HALF_BLOCK: char = '▌';
pub const LEFT_THREE_EIGHTHS_BLOCK: char = '▍';
pub const LEFT_ONE_QUARTER_BLOCK: char = '▎';
pub const LEFT_ONE_EIGHTH_BLOCK: char = '▏';
pub const RIGHT_HALF_BLOCK: char = '▐';
pub const LIGHT_SHADE: char = '░';
pub const MEDIUM_SHADE: char = '▒';
pub const DARK_SHADE: char = '▓';
pub const UPPER_ONE_EIGHTH_BLOCK: char = '▔';
pub const RIGHT_ONE_EIGHTH_BLOCK: char = '▕';
pub const QUADRANT_LOWER_LEFT: char = '▖';
pub const QUADRANT_LOWER_RIGHT: char = '▗';
pub const QUADRANT_UPPER_LEFT: char = '▘';
pub const QUADRANT_UPPER_LEFT_AND_LOWER_LEFT_AND_LOWER_RIGHT: char = '▙';
pub const QUADRANT_UPPER_LEFT_AND_LOWER_RIGHT: char = '▚';
pub const QUADRANT_UPPER_LEFT_AND_UPPER_RIGHT_AND_LOWER_LEFT: char = '▛';
pub const QUADRANT_UPPER_LEFT_AND_UPPER_RIGHT_AND_LOWER_RIGHT: char = '▜';
pub const QUADRANT_UPPER_RIGHT: char = '▝';
pub const QUADRANT_UPPER_RIGHT_AND_LOWER_LEFT: char = '▞';
}
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub enum BlockElements {
UpperHalfBlock,
LowerOneEighthBlock,
LowerOneQuarterBlock,
LowerThreeEighthsBlock,
LowerHalfBlock,
LowerFiveEighthsBlock,
LowerThreeQuartersBlock,
LowerSevenEighthsBlock,
FullBlock,
LeftSevenEighthsBlock,
LeftThreeQuartersBlock,
LeftFiveEighthsBlock,
LeftHalfBlock,
LeftThreeEighthsBlock,
LeftOneQuarterBlock,
LeftOneEighthBlock,
RightHalfBlock,
LightShade,
MediumShade,
DarkShade,
UpperOneEighthBlock,
RightOneEighthBlock,
QuadrantLowerLeft,
QuadrantLowerRight,
QuadrantUpperLeft,
QuadrantUpperLeftAndLowerLeftAndLowerRight,
QuadrantUpperLeftAndLowerRight,
QuadrantUpperLeftAndUpperRightAndLowerLeft,
QuadrantUpperLeftAndUpperRightAndLowerRight,
QuadrantUpperRight,
QuadrantUpperRightAndLowerLeft,
}
impl Into<char> for BlockElements {
fn into(self) -> char {
use constants::*;
match self {
BlockElements::UpperHalfBlock => UPPER_HALF_BLOCK,
BlockElements::LowerOneEighthBlock => LOWER_ONE_EIGHTH_BLOCK,
BlockElements::LowerOneQuarterBlock => LOWER_ONE_QUARTER_BLOCK,
BlockElements::LowerThreeEighthsBlock => LOWER_THREE_EIGHTHS_BLOCK,
BlockElements::LowerHalfBlock => LOWER_HALF_BLOCK,
BlockElements::LowerFiveEighthsBlock => LOWER_FIVE_EIGHTHS_BLOCK,
BlockElements::LowerThreeQuartersBlock => LOWER_THREE_QUARTERS_BLOCK,
BlockElements::LowerSevenEighthsBlock => LOWER_SEVEN_EIGHTHS_BLOCK,
BlockElements::FullBlock => FULL_BLOCK,
BlockElements::LeftSevenEighthsBlock => LEFT_SEVEN_EIGHTHS_BLOCK,
BlockElements::LeftThreeQuartersBlock => LEFT_THREE_QUARTERS_BLOCK,
BlockElements::LeftFiveEighthsBlock => LEFT_FIVE_EIGHTHS_BLOCK,
BlockElements::LeftHalfBlock => LEFT_HALF_BLOCK,
BlockElements::LeftThreeEighthsBlock => LEFT_THREE_EIGHTHS_BLOCK,
BlockElements::LeftOneQuarterBlock => LEFT_ONE_QUARTER_BLOCK,
BlockElements::LeftOneEighthBlock => LEFT_ONE_EIGHTH_BLOCK,
BlockElements::RightHalfBlock => RIGHT_HALF_BLOCK,
BlockElements::LightShade => LIGHT_SHADE,
BlockElements::MediumShade => MEDIUM_SHADE,
BlockElements::DarkShade => DARK_SHADE,
BlockElements::UpperOneEighthBlock => UPPER_ONE_EIGHTH_BLOCK,
BlockElements::RightOneEighthBlock => RIGHT_ONE_EIGHTH_BLOCK,
BlockElements::QuadrantLowerLeft => QUADRANT_LOWER_LEFT,
BlockElements::QuadrantLowerRight => QUADRANT_LOWER_RIGHT,
BlockElements::QuadrantUpperLeft => QUADRANT_UPPER_LEFT,
BlockElements::QuadrantUpperLeftAndLowerLeftAndLowerRight => QUADRANT_UPPER_LEFT_AND_LOWER_LEFT_AND_LOWER_RIGHT,
BlockElements::QuadrantUpperLeftAndLowerRight => QUADRANT_UPPER_LEFT_AND_LOWER_RIGHT,
BlockElements::QuadrantUpperLeftAndUpperRightAndLowerLeft => QUADRANT_UPPER_LEFT_AND_UPPER_RIGHT_AND_LOWER_LEFT,
BlockElements::QuadrantUpperLeftAndUpperRightAndLowerRight => QUADRANT_UPPER_LEFT_AND_UPPER_RIGHT_AND_LOWER_RIGHT,
BlockElements::QuadrantUpperRight => QUADRANT_UPPER_RIGHT,
BlockElements::QuadrantUpperRightAndLowerLeft => QUADRANT_UPPER_RIGHT_AND_LOWER_LEFT,
}
}
}
impl std::convert::TryFrom<char> for BlockElements {
type Error = ();
fn try_from(c: char) -> Result<Self, Self::Error> {
use constants::*;
match c {
UPPER_HALF_BLOCK => Ok(BlockElements::UpperHalfBlock),
LOWER_ONE_EIGHTH_BLOCK => Ok(BlockElements::LowerOneEighthBlock),
LOWER_ONE_QUARTER_BLOCK => Ok(BlockElements::LowerOneQuarterBlock),
LOWER_THREE_EIGHTHS_BLOCK => Ok(BlockElements::LowerThreeEighthsBlock),
LOWER_HALF_BLOCK => Ok(BlockElements::LowerHalfBlock),
LOWER_FIVE_EIGHTHS_BLOCK => Ok(BlockElements::LowerFiveEighthsBlock),
LOWER_THREE_QUARTERS_BLOCK => Ok(BlockElements::LowerThreeQuartersBlock),
LOWER_SEVEN_EIGHTHS_BLOCK => Ok(BlockElements::LowerSevenEighthsBlock),
FULL_BLOCK => Ok(BlockElements::FullBlock),
LEFT_SEVEN_EIGHTHS_BLOCK => Ok(BlockElements::LeftSevenEighthsBlock),
LEFT_THREE_QUARTERS_BLOCK => Ok(BlockElements::LeftThreeQuartersBlock),
LEFT_FIVE_EIGHTHS_BLOCK => Ok(BlockElements::LeftFiveEighthsBlock),
LEFT_HALF_BLOCK => Ok(BlockElements::LeftHalfBlock),
LEFT_THREE_EIGHTHS_BLOCK => Ok(BlockElements::LeftThreeEighthsBlock),
LEFT_ONE_QUARTER_BLOCK => Ok(BlockElements::LeftOneQuarterBlock),
LEFT_ONE_EIGHTH_BLOCK => Ok(BlockElements::LeftOneEighthBlock),
RIGHT_HALF_BLOCK => Ok(BlockElements::RightHalfBlock),
LIGHT_SHADE => Ok(BlockElements::LightShade),
MEDIUM_SHADE => Ok(BlockElements::MediumShade),
DARK_SHADE => Ok(BlockElements::DarkShade),
UPPER_ONE_EIGHTH_BLOCK => Ok(BlockElements::UpperOneEighthBlock),
RIGHT_ONE_EIGHTH_BLOCK => Ok(BlockElements::RightOneEighthBlock),
QUADRANT_LOWER_LEFT => Ok(BlockElements::QuadrantLowerLeft),
QUADRANT_LOWER_RIGHT => Ok(BlockElements::QuadrantLowerRight),
QUADRANT_UPPER_LEFT => Ok(BlockElements::QuadrantUpperLeft),
QUADRANT_UPPER_LEFT_AND_LOWER_LEFT_AND_LOWER_RIGHT => Ok(BlockElements::QuadrantUpperLeftAndLowerLeftAndLowerRight),
QUADRANT_UPPER_LEFT_AND_LOWER_RIGHT => Ok(BlockElements::QuadrantUpperLeftAndLowerRight),
QUADRANT_UPPER_LEFT_AND_UPPER_RIGHT_AND_LOWER_LEFT => Ok(BlockElements::QuadrantUpperLeftAndUpperRightAndLowerLeft),
QUADRANT_UPPER_LEFT_AND_UPPER_RIGHT_AND_LOWER_RIGHT => Ok(BlockElements::QuadrantUpperLeftAndUpperRightAndLowerRight),
QUADRANT_UPPER_RIGHT => Ok(BlockElements::QuadrantUpperRight),
QUADRANT_UPPER_RIGHT_AND_LOWER_LEFT => Ok(BlockElements::QuadrantUpperRightAndLowerLeft),
_ => Err(()),
}
}
}
impl Into<u32> for BlockElements {
fn into(self) -> u32 {
let c: char = self.into();
let hex = c
.escape_unicode()
.to_string()
.replace("\\u{", "")
.replace("}", "");
u32::from_str_radix(&hex, 16).unwrap()
}
}
impl std::convert::TryFrom<u32> for BlockElements {
type Error = ();
fn try_from(u: u32) -> Result<Self, Self::Error> {
if let Ok(c) = char::try_from(u) {
Self::try_from(c)
} else {
Err(())
}
}
}
impl Iterator for BlockElements {
type Item = Self;
fn next(&mut self) -> Option<Self> {
let index: u32 = (*self).into();
use std::convert::TryFrom;
Self::try_from(index + 1).ok()
}
}
impl BlockElements {
pub fn new() -> Self {
BlockElements::UpperHalfBlock
}
pub fn name(&self) -> &str {
match self {
BlockElements::UpperHalfBlock => "upper half block",
BlockElements::LowerOneEighthBlock => "lower one eighth block",
BlockElements::LowerOneQuarterBlock => "lower one quarter block",
BlockElements::LowerThreeEighthsBlock => "lower three eighths block",
BlockElements::LowerHalfBlock => "lower half block",
BlockElements::LowerFiveEighthsBlock => "lower five eighths block",
BlockElements::LowerThreeQuartersBlock => "lower three quarters block",
BlockElements::LowerSevenEighthsBlock => "lower seven eighths block",
BlockElements::FullBlock => "full block",
BlockElements::LeftSevenEighthsBlock => "left seven eighths block",
BlockElements::LeftThreeQuartersBlock => "left three quarters block",
BlockElements::LeftFiveEighthsBlock => "left five eighths block",
BlockElements::LeftHalfBlock => "left half block",
BlockElements::LeftThreeEighthsBlock => "left three eighths block",
BlockElements::LeftOneQuarterBlock => "left one quarter block",
BlockElements::LeftOneEighthBlock => "left one eighth block",
BlockElements::RightHalfBlock => "right half block",
BlockElements::LightShade => "light shade",
BlockElements::MediumShade => "medium shade",
BlockElements::DarkShade => "dark shade",
BlockElements::UpperOneEighthBlock => "upper one eighth block",
BlockElements::RightOneEighthBlock => "right one eighth block",
BlockElements::QuadrantLowerLeft => "quadrant lower left",
BlockElements::QuadrantLowerRight => "quadrant lower right",
BlockElements::QuadrantUpperLeft => "quadrant upper left",
BlockElements::QuadrantUpperLeftAndLowerLeftAndLowerRight => "quadrant upper left and lower left and lower right",
BlockElements::QuadrantUpperLeftAndLowerRight => "quadrant upper left and lower right",
BlockElements::QuadrantUpperLeftAndUpperRightAndLowerLeft => "quadrant upper left and upper right and lower left",
BlockElements::QuadrantUpperLeftAndUpperRightAndLowerRight => "quadrant upper left and upper right and lower right",
BlockElements::QuadrantUpperRight => "quadrant upper right",
BlockElements::QuadrantUpperRightAndLowerLeft => "quadrant upper right and lower left",
}
}
}