parent
41035e40cd
commit
b27829caea
6 changed files with 78 additions and 85 deletions
|
@ -1,15 +1,15 @@
|
||||||
use catppuccin::Flavour;
|
use catppuccin::Flavour;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let (r, g, b) = Flavour::Latte.palette().teal.into();
|
let (r, g, b) = Flavour::Latte.colours().teal.into();
|
||||||
println!(
|
println!(
|
||||||
"Latte's teal is #{}, which is rgb({r}, {g}, {b})",
|
"Latte's teal is #{}, which is rgb({r}, {g}, {b})",
|
||||||
Flavour::Latte.palette().teal.hex()
|
Flavour::Latte.colours().teal.hex()
|
||||||
);
|
);
|
||||||
|
|
||||||
let (r, g, b) = Flavour::Mocha.palette().teal.into();
|
let (r, g, b) = Flavour::Mocha.colours().teal.into();
|
||||||
println!(
|
println!(
|
||||||
"Mocha's teal is #{}, which is rgb({r}, {g}, {b})",
|
"Mocha's teal is #{}, which is rgb({r}, {g}, {b})",
|
||||||
Flavour::Mocha.palette().teal.hex()
|
Flavour::Mocha.colours().teal.hex()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
use catppuccin::Flavour;
|
use catppuccin::Flavour;
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// iterate over the four Catppuccin flavours.
|
// iterate over the four Catppuccin flavours.
|
||||||
for flavour in Flavour::into_iter() {
|
for flavour in Flavour::into_iter() {
|
||||||
println!("{}", flavour.name());
|
println!("{}", flavour.name());
|
||||||
|
|
||||||
// iterate over the 26 colours in the flavour.
|
// iterate over the 26 colours in the flavour.
|
||||||
for (i, colour) in flavour.palette().into_iter().enumerate() {
|
for (i, colour) in flavour.colours().into_iter().enumerate() {
|
||||||
print!("{}", colour.ansi_paint("██"));
|
print!("{}", colour.ansi_paint("██"));
|
||||||
|
|
||||||
// the 14 analogous colours go on one line,
|
// the 14 analogous colours go on one line,
|
||||||
|
|
|
@ -13,7 +13,7 @@ impl Colour {
|
||||||
/// ```
|
/// ```
|
||||||
/// use catppuccin::Flavour;
|
/// use catppuccin::Flavour;
|
||||||
///
|
///
|
||||||
/// let hex = Flavour::Mocha.palette().teal.hex();
|
/// let hex = Flavour::Mocha.colours().teal.hex();
|
||||||
/// assert_eq!(hex, "94E2D5");
|
/// assert_eq!(hex, "94E2D5");
|
||||||
/// ```
|
/// ```
|
||||||
pub fn hex(&self) -> String {
|
pub fn hex(&self) -> String {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{Colour, Palette};
|
use crate::{Colour, FlavourColours};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||||
pub enum Flavour {
|
pub enum Flavour {
|
||||||
|
@ -18,9 +18,9 @@ impl Flavour {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn palette(self) -> Palette {
|
pub fn colours(self) -> FlavourColours {
|
||||||
match self {
|
match self {
|
||||||
Self::Latte => Palette {
|
Self::Latte => FlavourColours {
|
||||||
rosewater: Colour(220, 138, 120),
|
rosewater: Colour(220, 138, 120),
|
||||||
flamingo: Colour(221, 120, 120),
|
flamingo: Colour(221, 120, 120),
|
||||||
pink: Colour(234, 118, 203),
|
pink: Colour(234, 118, 203),
|
||||||
|
@ -48,7 +48,7 @@ impl Flavour {
|
||||||
mantle: Colour(230, 233, 239),
|
mantle: Colour(230, 233, 239),
|
||||||
crust: Colour(220, 224, 232),
|
crust: Colour(220, 224, 232),
|
||||||
},
|
},
|
||||||
Self::Frappe => Palette {
|
Self::Frappe => FlavourColours {
|
||||||
rosewater: Colour(242, 213, 207),
|
rosewater: Colour(242, 213, 207),
|
||||||
flamingo: Colour(238, 190, 190),
|
flamingo: Colour(238, 190, 190),
|
||||||
pink: Colour(244, 184, 228),
|
pink: Colour(244, 184, 228),
|
||||||
|
@ -76,7 +76,7 @@ impl Flavour {
|
||||||
mantle: Colour(41, 44, 60),
|
mantle: Colour(41, 44, 60),
|
||||||
crust: Colour(35, 38, 52),
|
crust: Colour(35, 38, 52),
|
||||||
},
|
},
|
||||||
Self::Macchiato => Palette {
|
Self::Macchiato => FlavourColours {
|
||||||
rosewater: Colour(244, 219, 214),
|
rosewater: Colour(244, 219, 214),
|
||||||
flamingo: Colour(240, 198, 198),
|
flamingo: Colour(240, 198, 198),
|
||||||
pink: Colour(245, 189, 230),
|
pink: Colour(245, 189, 230),
|
||||||
|
@ -104,7 +104,7 @@ impl Flavour {
|
||||||
mantle: Colour(30, 32, 48),
|
mantle: Colour(30, 32, 48),
|
||||||
crust: Colour(24, 25, 38),
|
crust: Colour(24, 25, 38),
|
||||||
},
|
},
|
||||||
Self::Mocha => Palette {
|
Self::Mocha => FlavourColours {
|
||||||
rosewater: Colour(245, 224, 220),
|
rosewater: Colour(245, 224, 220),
|
||||||
flamingo: Colour(242, 205, 205),
|
flamingo: Colour(242, 205, 205),
|
||||||
pink: Colour(245, 194, 231),
|
pink: Colour(245, 194, 231),
|
||||||
|
@ -136,25 +136,19 @@ impl Flavour {
|
||||||
}
|
}
|
||||||
/// Returns an iterator over the four delicious Catppuccin flavours.
|
/// Returns an iterator over the four delicious Catppuccin flavours.
|
||||||
pub fn into_iter() -> std::array::IntoIter<Flavour, 4> {
|
pub fn into_iter() -> std::array::IntoIter<Flavour, 4> {
|
||||||
[
|
[Self::Latte, Self::Frappe, Self::Macchiato, Self::Mocha].into_iter()
|
||||||
Self::Latte,
|
|
||||||
Self::Frappe,
|
|
||||||
Self::Macchiato,
|
|
||||||
Self::Mocha,
|
|
||||||
]
|
|
||||||
.into_iter()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::Flavour;
|
use super::Flavour;
|
||||||
use crate::palette::validate_colours;
|
use crate::flavour_colours::validate_colours;
|
||||||
use indoc::indoc;
|
use indoc::indoc;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn validate_latte_colours() {
|
fn validate_latte_colours() {
|
||||||
validate_colours(
|
validate_colours(
|
||||||
Flavour::Latte.palette(),
|
Flavour::Latte.colours(),
|
||||||
indoc! {"
|
indoc! {"
|
||||||
Rosewater #dc8a78 rgb(220, 138, 120) hsl(11, 59%, 67%)
|
Rosewater #dc8a78 rgb(220, 138, 120) hsl(11, 59%, 67%)
|
||||||
Flamingo #dd7878 rgb(221, 120, 120) hsl(0, 60%, 67%)
|
Flamingo #dd7878 rgb(221, 120, 120) hsl(0, 60%, 67%)
|
||||||
|
@ -189,7 +183,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn validate_frappe_colours() {
|
fn validate_frappe_colours() {
|
||||||
validate_colours(
|
validate_colours(
|
||||||
Flavour::Frappe.palette(),
|
Flavour::Frappe.colours(),
|
||||||
indoc! {"
|
indoc! {"
|
||||||
Rosewater #f2d5cf rgb(242, 213, 207) hsl(10, 57%, 88%)
|
Rosewater #f2d5cf rgb(242, 213, 207) hsl(10, 57%, 88%)
|
||||||
Flamingo #eebebe rgb(238, 190, 190) hsl(0, 59%, 84%)
|
Flamingo #eebebe rgb(238, 190, 190) hsl(0, 59%, 84%)
|
||||||
|
@ -224,7 +218,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn validate_macchiato_colours() {
|
fn validate_macchiato_colours() {
|
||||||
validate_colours(
|
validate_colours(
|
||||||
Flavour::Macchiato.palette(),
|
Flavour::Macchiato.colours(),
|
||||||
indoc! {"
|
indoc! {"
|
||||||
Rosewater #f4dbd6 rgb(244, 219, 214) hsl(10, 58%, 90%)
|
Rosewater #f4dbd6 rgb(244, 219, 214) hsl(10, 58%, 90%)
|
||||||
Flamingo #f0c6c6 rgb(240, 198, 198) hsl(0, 58%, 86%)
|
Flamingo #f0c6c6 rgb(240, 198, 198) hsl(0, 58%, 86%)
|
||||||
|
@ -259,7 +253,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn validate_mocha_colours() {
|
fn validate_mocha_colours() {
|
||||||
validate_colours(
|
validate_colours(
|
||||||
Flavour::Mocha.palette(),
|
Flavour::Mocha.colours(),
|
||||||
indoc! {"
|
indoc! {"
|
||||||
Rosewater #f5e0dc rgb(245, 224, 220) hsl(10, 56%, 91%)
|
Rosewater #f5e0dc rgb(245, 224, 220) hsl(10, 56%, 91%)
|
||||||
Flamingo #f2cdcd rgb(242, 205, 205) hsl(0, 59%, 88%)
|
Flamingo #f2cdcd rgb(242, 205, 205) hsl(0, 59%, 88%)
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::Colour;
|
||||||
|
|
||||||
/// Contains the colour options for a flavour of Catppuccin.
|
/// Contains the colour options for a flavour of Catppuccin.
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||||
pub struct Palette {
|
pub struct FlavourColours {
|
||||||
pub rosewater: Colour,
|
pub rosewater: Colour,
|
||||||
pub flamingo: Colour,
|
pub flamingo: Colour,
|
||||||
pub pink: Colour,
|
pub pink: Colour,
|
||||||
|
@ -31,7 +31,7 @@ pub struct Palette {
|
||||||
pub crust: Colour,
|
pub crust: Colour,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Palette {
|
impl FlavourColours {
|
||||||
/// Returns an iterator over the colours in the flavour.
|
/// Returns an iterator over the colours in the flavour.
|
||||||
pub fn into_iter(&self) -> std::array::IntoIter<&Colour, 26> {
|
pub fn into_iter(&self) -> std::array::IntoIter<&Colour, 26> {
|
||||||
[
|
[
|
||||||
|
@ -71,7 +71,7 @@ impl Palette {
|
||||||
/// Copy the table in question from the following URL:
|
/// Copy the table in question from the following URL:
|
||||||
/// https://github.com/catppuccin/catppuccin#-palettes
|
/// https://github.com/catppuccin/catppuccin#-palettes
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) fn validate_colours(flavour: Palette, colours: &str) {
|
pub(crate) fn validate_colours(flavour_colours: FlavourColours, colours: &str) {
|
||||||
fn from_hex(hex: &str) -> Colour {
|
fn from_hex(hex: &str) -> Colour {
|
||||||
let hex = hex.strip_prefix('#').unwrap_or(hex);
|
let hex = hex.strip_prefix('#').unwrap_or(hex);
|
||||||
let hex = i32::from_str_radix(hex, 16).expect(&format!(
|
let hex = i32::from_str_radix(hex, 16).expect(&format!(
|
||||||
|
@ -96,30 +96,30 @@ pub(crate) fn validate_colours(flavour: Palette, colours: &str) {
|
||||||
.expect("ran out of colours, check paste format")
|
.expect("ran out of colours, check paste format")
|
||||||
};
|
};
|
||||||
|
|
||||||
assert_eq!(next_colour(), flavour.rosewater);
|
assert_eq!(next_colour(), flavour_colours.rosewater);
|
||||||
assert_eq!(next_colour(), flavour.flamingo);
|
assert_eq!(next_colour(), flavour_colours.flamingo);
|
||||||
assert_eq!(next_colour(), flavour.pink);
|
assert_eq!(next_colour(), flavour_colours.pink);
|
||||||
assert_eq!(next_colour(), flavour.mauve);
|
assert_eq!(next_colour(), flavour_colours.mauve);
|
||||||
assert_eq!(next_colour(), flavour.red);
|
assert_eq!(next_colour(), flavour_colours.red);
|
||||||
assert_eq!(next_colour(), flavour.maroon);
|
assert_eq!(next_colour(), flavour_colours.maroon);
|
||||||
assert_eq!(next_colour(), flavour.peach);
|
assert_eq!(next_colour(), flavour_colours.peach);
|
||||||
assert_eq!(next_colour(), flavour.yellow);
|
assert_eq!(next_colour(), flavour_colours.yellow);
|
||||||
assert_eq!(next_colour(), flavour.green);
|
assert_eq!(next_colour(), flavour_colours.green);
|
||||||
assert_eq!(next_colour(), flavour.teal);
|
assert_eq!(next_colour(), flavour_colours.teal);
|
||||||
assert_eq!(next_colour(), flavour.sky);
|
assert_eq!(next_colour(), flavour_colours.sky);
|
||||||
assert_eq!(next_colour(), flavour.sapphire);
|
assert_eq!(next_colour(), flavour_colours.sapphire);
|
||||||
assert_eq!(next_colour(), flavour.blue);
|
assert_eq!(next_colour(), flavour_colours.blue);
|
||||||
assert_eq!(next_colour(), flavour.lavender);
|
assert_eq!(next_colour(), flavour_colours.lavender);
|
||||||
assert_eq!(next_colour(), flavour.text);
|
assert_eq!(next_colour(), flavour_colours.text);
|
||||||
assert_eq!(next_colour(), flavour.subtext1);
|
assert_eq!(next_colour(), flavour_colours.subtext1);
|
||||||
assert_eq!(next_colour(), flavour.subtext0);
|
assert_eq!(next_colour(), flavour_colours.subtext0);
|
||||||
assert_eq!(next_colour(), flavour.overlay2);
|
assert_eq!(next_colour(), flavour_colours.overlay2);
|
||||||
assert_eq!(next_colour(), flavour.overlay1);
|
assert_eq!(next_colour(), flavour_colours.overlay1);
|
||||||
assert_eq!(next_colour(), flavour.overlay0);
|
assert_eq!(next_colour(), flavour_colours.overlay0);
|
||||||
assert_eq!(next_colour(), flavour.surface2);
|
assert_eq!(next_colour(), flavour_colours.surface2);
|
||||||
assert_eq!(next_colour(), flavour.surface1);
|
assert_eq!(next_colour(), flavour_colours.surface1);
|
||||||
assert_eq!(next_colour(), flavour.surface0);
|
assert_eq!(next_colour(), flavour_colours.surface0);
|
||||||
assert_eq!(next_colour(), flavour.base);
|
assert_eq!(next_colour(), flavour_colours.base);
|
||||||
assert_eq!(next_colour(), flavour.mantle);
|
assert_eq!(next_colour(), flavour_colours.mantle);
|
||||||
assert_eq!(next_colour(), flavour.crust);
|
assert_eq!(next_colour(), flavour_colours.crust);
|
||||||
}
|
}
|
|
@ -22,7 +22,7 @@
|
||||||
//! fn confirm(text: String) -> Button {
|
//! fn confirm(text: String) -> Button {
|
||||||
//! Button {
|
//! Button {
|
||||||
//! text,
|
//! text,
|
||||||
//! background_colour: Flavour::Mocha.palette().green.hex(),
|
//! background_colour: Flavour::Mocha.colours().green.hex(),
|
||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
@ -55,8 +55,8 @@
|
||||||
mod colour;
|
mod colour;
|
||||||
pub use colour::Colour;
|
pub use colour::Colour;
|
||||||
|
|
||||||
mod palette;
|
mod flavour_colours;
|
||||||
pub use palette::Palette;
|
pub use flavour_colours::FlavourColours;
|
||||||
|
|
||||||
mod flavour;
|
mod flavour;
|
||||||
pub use flavour::Flavour;
|
pub use flavour::Flavour;
|
||||||
|
@ -80,34 +80,34 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_colours_iter() {
|
fn test_colours_iter() {
|
||||||
for flavour in Flavour::into_iter() {
|
for flavour in Flavour::into_iter() {
|
||||||
let palette = flavour.palette();
|
let colours = flavour.colours();
|
||||||
let mut colours = palette.into_iter();
|
let mut colours_iter = colours.into_iter();
|
||||||
assert_eq!(colours.next(), Some(&palette.rosewater));
|
assert_eq!(colours_iter.next(), Some(&colours.rosewater));
|
||||||
assert_eq!(colours.next(), Some(&palette.flamingo));
|
assert_eq!(colours_iter.next(), Some(&colours.flamingo));
|
||||||
assert_eq!(colours.next(), Some(&palette.pink));
|
assert_eq!(colours_iter.next(), Some(&colours.pink));
|
||||||
assert_eq!(colours.next(), Some(&palette.mauve));
|
assert_eq!(colours_iter.next(), Some(&colours.mauve));
|
||||||
assert_eq!(colours.next(), Some(&palette.red));
|
assert_eq!(colours_iter.next(), Some(&colours.red));
|
||||||
assert_eq!(colours.next(), Some(&palette.maroon));
|
assert_eq!(colours_iter.next(), Some(&colours.maroon));
|
||||||
assert_eq!(colours.next(), Some(&palette.peach));
|
assert_eq!(colours_iter.next(), Some(&colours.peach));
|
||||||
assert_eq!(colours.next(), Some(&palette.yellow));
|
assert_eq!(colours_iter.next(), Some(&colours.yellow));
|
||||||
assert_eq!(colours.next(), Some(&palette.green));
|
assert_eq!(colours_iter.next(), Some(&colours.green));
|
||||||
assert_eq!(colours.next(), Some(&palette.teal));
|
assert_eq!(colours_iter.next(), Some(&colours.teal));
|
||||||
assert_eq!(colours.next(), Some(&palette.sky));
|
assert_eq!(colours_iter.next(), Some(&colours.sky));
|
||||||
assert_eq!(colours.next(), Some(&palette.sapphire));
|
assert_eq!(colours_iter.next(), Some(&colours.sapphire));
|
||||||
assert_eq!(colours.next(), Some(&palette.blue));
|
assert_eq!(colours_iter.next(), Some(&colours.blue));
|
||||||
assert_eq!(colours.next(), Some(&palette.lavender));
|
assert_eq!(colours_iter.next(), Some(&colours.lavender));
|
||||||
assert_eq!(colours.next(), Some(&palette.text));
|
assert_eq!(colours_iter.next(), Some(&colours.text));
|
||||||
assert_eq!(colours.next(), Some(&palette.subtext1));
|
assert_eq!(colours_iter.next(), Some(&colours.subtext1));
|
||||||
assert_eq!(colours.next(), Some(&palette.subtext0));
|
assert_eq!(colours_iter.next(), Some(&colours.subtext0));
|
||||||
assert_eq!(colours.next(), Some(&palette.overlay2));
|
assert_eq!(colours_iter.next(), Some(&colours.overlay2));
|
||||||
assert_eq!(colours.next(), Some(&palette.overlay1));
|
assert_eq!(colours_iter.next(), Some(&colours.overlay1));
|
||||||
assert_eq!(colours.next(), Some(&palette.overlay0));
|
assert_eq!(colours_iter.next(), Some(&colours.overlay0));
|
||||||
assert_eq!(colours.next(), Some(&palette.surface2));
|
assert_eq!(colours_iter.next(), Some(&colours.surface2));
|
||||||
assert_eq!(colours.next(), Some(&palette.surface1));
|
assert_eq!(colours_iter.next(), Some(&colours.surface1));
|
||||||
assert_eq!(colours.next(), Some(&palette.surface0));
|
assert_eq!(colours_iter.next(), Some(&colours.surface0));
|
||||||
assert_eq!(colours.next(), Some(&palette.base));
|
assert_eq!(colours_iter.next(), Some(&colours.base));
|
||||||
assert_eq!(colours.next(), Some(&palette.mantle));
|
assert_eq!(colours_iter.next(), Some(&colours.mantle));
|
||||||
assert_eq!(colours.next(), Some(&palette.crust));
|
assert_eq!(colours_iter.next(), Some(&colours.crust));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue