1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Crossterm integration.
//!
//! Provides conversion between [`Color`](crate::Color) and [`crossterm::style::Color`].
//!
//! Forward conversion always produces [`Color::Rgb`](crossterm::style::Color::Rgb).
//! Reverse conversion uses [`TryFrom`] since only the `Rgb` variant can be converted.
//!
//! # Examples
//!
//! ```ignore
//! use prismatica::crameri::BATLOW;
//!
//! let color = BATLOW.eval(0.5);
//! let ct_color: crossterm::style::Color = color.into();
//!
//! // Reverse: only Rgb variant converts
//! let back = prismatica::Color::try_from(ct_color).unwrap();
//! assert_eq!(color, back);
//! ```
use crateimpl_into_framework_color;
use crate::;
/// Convert a prismatica [`Color`] to a [`crossterm::style::Color::Rgb`].
///
/// # Examples
///
/// ```ignore
/// let color = prismatica::Color::new(128, 64, 32);
/// let ct: crossterm::style::Color = color.into();
/// ```
/// Try to convert a [`crossterm::style::Color`] to a prismatica [`Color`].
///
/// Only the `Rgb` variant can be converted. Named colors (e.g., `Red`, `Blue`)
/// and other variants return an error.
///
/// # Errors
///
/// Returns [`ConversionError`](crate::ConversionError) if the color is not
/// a `Color::Rgb` variant.
///
/// # Examples
///
/// ```ignore
/// use prismatica::Color;
///
/// let rgb = crossterm::style::Color::Rgb { r: 128, g: 64, b: 32 };
/// assert!(Color::try_from(rgb).is_ok());
///
/// let named = crossterm::style::Color::Red;
/// assert!(Color::try_from(named).is_err());
/// ```
impl_into_framework_color!;