-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathlib.rs
More file actions
721 lines (640 loc) · 20.5 KB
/
lib.rs
File metadata and controls
721 lines (640 loc) · 20.5 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
//! 🦀 Soothing pastel theme for Rust.
//!
//! # Usage
//!
//! Add Catppuccin to your project's `Cargo.toml`:
//!
//! ```console
//! $ cargo add catppuccin
//! ```
//!
//! # Example
//!
//! ```rust
//! struct Button {
//! text: String,
//! background_color: String,
//! };
//!
//! fn confirm(text: String) -> Button {
//! Button {
//! text,
//! background_color: catppuccin::PALETTE.mocha.colors.green.hex.to_string(),
//! }
//! }
//! ```
//!
//! More examples can be found
//! [here](https://github.com/catppuccin/rust/tree/main/examples).
//!
//! # Optional Features
//!
//! ## ANSI string painting
//!
//! Enable the `ansi-term` feature to add the
//! [`Color::ansi_paint`](Color::ansi_paint) method.
//! This adds [ansi-term](https://crates.io/crates/ansi_term) as a dependency.
//!
//! Example: [`examples/term_grid.rs`](https://github.com/catppuccin/rust/blob/main/examples/term_grid.rs)
//!
//! ### Bevy
//!
//! Enable the `bevy` feature to enable the conversion of Catppuccin colors to
//! [`bevy::prelude::Color`] instances.
//! This adds [bevy](https://crates.io/crates/bevy) as a dependency.
//!
//! Example: [`examples/bevy.rs`](https://github.com/catppuccin/rust/blob/main/examples/bevy.rs)
//!
//! ### CSS colors
//!
//! Enable the `css-colors` feature to enable the conversion of Catppuccin colors to
//! [`css_colors::RGB`] instances.
//! This adds [css-colors](https://crates.io/crates/css-colors) as a dependency.
//!
//! Example: [`examples/css.rs`](https://github.com/catppuccin/rust/blob/main/examples/css.rs)
//!
//! ### Iced
//!
//! Enable the `iced` feature to enable the conversion of Catppuccin colors to
//! [`iced::Color`] instances.
//! This adds [iced](https://crates.io/crates/iced) as a dependency.
//!
//! Example: [`examples/iced.rs`](https://github.com/catppuccin/rust/blob/main/examples/iced.rs)
//!
//! ### Ratatui
//!
//! Enable the `ratatui` feature to enable the conversion of Catppuccin colors to
//! [`ratatui::style::Color`] instances.
//! This adds [ratatui](https://crates.io/crates/ratatui) as a dependency.
//!
//! Example: [`examples/ratatui.rs`](https://github.com/catppuccin/rust/blob/main/examples/ratatui.rs)
//!
//! ### Serde
//!
//! Enable the `serde` feature to enable the serialization of Catppuccin's palette,
//! flavor, and color types.
//! This adds [serde](https://crates.io/crates/serde) as a dependency.
//!
//! Example: [`examples/serde.rs`](https://github.com/catppuccin/rust/blob/main/examples/serde.rs)
#![no_std]
extern crate alloc;
use core::{fmt, marker::PhantomData, ops::Index, str::FromStr};
include!(concat!(env!("OUT_DIR"), "/generated_palette.rs"));
/// The top-level type that encompasses the Catppuccin palette data structure.
/// Primarily used via the [`PALETTE`] constant.
///
/// Can be iterated over, in which case the flavors are yielded in the canonical order:
/// Latte, Frappé, Macchiato, Mocha.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Palette {
/// The light flavor.
pub latte: Flavor,
/// The lightest dark flavor.
pub frappe: Flavor,
/// The medium dark flavor.
pub macchiato: Flavor,
/// The darkest dark flavor.
pub mocha: Flavor,
}
/// Enum of all four flavors of Catppuccin. Can be used to index [`Palette`].
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum FlavorName {
/// The light flavor.
Latte,
/// The lightest dark flavor.
#[cfg_attr(feature = "serde", serde(rename = "Frappé"))]
Frappe,
/// The medium dark flavor.
Macchiato,
/// The darkest dark flavor.
Mocha,
}
/// An iterator over flavors in the palette.
/// Obtained via [`Palette::iter()`].
pub struct FlavorIterator<'a> {
current: usize,
phantom: PhantomData<&'a ()>,
}
/// Color represented as individual red, green, and blue channels.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Rgb {
/// Red channel.
pub r: u8,
/// Green channel.
pub g: u8,
/// Blue channel.
pub b: u8,
}
/// Color represented as 6-digit hexadecimal.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct Hex(Rgb);
/// Color represented as individual hue (0-359), saturation (0-1), and lightness (0-1) channels.
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Hsl {
/// Hue channel.
pub h: f64,
/// Saturation channel.
pub s: f64,
/// Lightness channel.
pub l: f64,
}
/// A single color in the Catppuccin palette.
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Color {
/// The [`ColorName`] for this color.
pub name: ColorName,
/// Order of the color in the palette spec.
pub order: u32,
/// Whether the color is considered an accent color.
/// Accent colors are the first 14 colors in the palette, also called
/// the analogous colours. The remaining 12 non-accent colors are also
/// referred to as the monochromatic colors.
pub accent: bool,
/// The color represented as a six-digit hex string with a leading hash (#).
pub hex: Hex,
/// The color represented as individual red, green, and blue channels.
pub rgb: Rgb,
/// The color represented as individual hue, saturation, and lightness channels.
pub hsl: Hsl,
}
/// A flavor is a collection of colors. Catppuccin has four flavors; Latte,
/// Frappé, Macchiato, and Mocha.
///
/// Can be iterated over, in which case the colors are yielded in order.
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Flavor {
/// The name of the flavor.
pub name: FlavorName,
/// Emoji associated with the flavor. Requires Unicode 13.0 (2020) or later to render.
pub emoji: char,
/// Order of the flavor in the palette spec.
pub order: u32,
/// Whether this flavor is dark or light oriented. Latte is light, the other
/// three flavors are dark.
pub dark: bool,
/// The colors in the flavor.
pub colors: FlavorColors,
/// The ANSI colors in the flavor.
pub ansi_colors: FlavorAnsiColors,
}
/// An iterator over colors in a flavor.
/// Obtained via [`Flavor::into_iter()`](struct.Flavor.html#method.into_iter) or [`FlavorColors::iter()`].
pub struct ColorIterator<'a> {
colors: &'a FlavorColors,
current: usize,
}
/// An iterator over the ANSI colors in a flavor.
///
/// Defaults to ascending order by ANSI code 0 -> 16.
/// Obtained via [`FlavorAnsiColors::into_iter()`](struct.FlavorAnsiColors.html#method.into_iter) or [`FlavorAnsiColors::iter()`].
pub struct AnsiColorIterator<'a> {
ansi_colors: &'a FlavorAnsiColors,
current: usize,
}
/// An iterator over the ANSI color pairs in a flavor.
/// Obtained via [`FlavorAnsiColorPairs::into_iter()`](struct.FlavorAnsiColorPairs.html#method.into_iter) or [`FlavorAnsiColorPairs::iter()`].
pub struct AnsiColorPairsIterator<'a> {
ansi_color_pairs: &'a FlavorAnsiColorPairs,
current: usize,
}
impl Palette {
/// Get an array of the flavors in the palette.
#[must_use]
pub const fn all_flavors(&self) -> [&Flavor; 4] {
[&self.latte, &self.frappe, &self.macchiato, &self.mocha]
}
/// Create an iterator over the flavors in the palette.
#[must_use]
pub const fn iter(&self) -> FlavorIterator<'_> {
FlavorIterator {
current: 0,
phantom: PhantomData,
}
}
}
impl Index<FlavorName> for Palette {
type Output = Flavor;
fn index(&self, index: FlavorName) -> &Self::Output {
match index {
FlavorName::Latte => &self.latte,
FlavorName::Frappe => &self.frappe,
FlavorName::Macchiato => &self.macchiato,
FlavorName::Mocha => &self.mocha,
}
}
}
impl Palette {
/// Get a flavor by name.
///
/// This is equivalent to using the index operator, but can also be used in
/// const contexts.
#[must_use]
pub const fn get_flavor(&self, name: FlavorName) -> &Flavor {
match name {
FlavorName::Latte => &self.latte,
FlavorName::Frappe => &self.frappe,
FlavorName::Macchiato => &self.macchiato,
FlavorName::Mocha => &self.mocha,
}
}
}
impl fmt::Display for Hex {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let Rgb { r, g, b } = self.0;
write!(f, "#{r:02x}{g:02x}{b:02x}")
}
}
#[cfg(feature = "serde")]
mod _hex {
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use crate::{Hex, Rgb};
use alloc::string::String;
use alloc::string::ToString;
impl Serialize for Hex {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(&self.to_string())
}
}
impl<'de> Deserialize<'de> for Hex {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
let hex: String = Deserialize::deserialize(deserializer)?;
let hex: u32 = u32::from_str_radix(hex.trim_start_matches('#'), 16)
.map_err(serde::de::Error::custom)?;
let r = ((hex >> 16) & 0xff) as u8;
let g = ((hex >> 8) & 0xff) as u8;
let b = (hex & 0xff) as u8;
Ok(Self(Rgb { r, g, b }))
}
}
}
impl fmt::Display for FlavorName {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::Latte => write!(f, "Latte"),
Self::Frappe => write!(f, "Frappé"),
Self::Macchiato => write!(f, "Macchiato"),
Self::Mocha => write!(f, "Mocha"),
}
}
}
/// Error type for parsing a [`FlavorName`] from a string.
#[derive(Debug, PartialEq, Eq)]
pub struct ParseFlavorNameError;
impl core::error::Error for ParseFlavorNameError {}
impl core::fmt::Display for ParseFlavorNameError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"invalid flavor identifier, expected one of: latte, frappe, frappé, macchiato, mocha"
)
}
}
impl FromStr for FlavorName {
type Err = ParseFlavorNameError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"latte" => Ok(Self::Latte),
"frappe" | "frappé" => Ok(Self::Frappe),
"macchiato" => Ok(Self::Macchiato),
"mocha" => Ok(Self::Mocha),
_ => Err(ParseFlavorNameError),
}
}
}
impl FlavorName {
/// Get the flavor's identifier; the lowercase key used to identify the flavor.
/// This differs from `to_string` in that it's intended for machine usage
/// rather than presentation.
///
/// Example:
///
/// ```rust
/// let frappe = catppuccin::PALETTE.frappe;
/// assert_eq!(frappe.name.to_string(), "Frappé");
/// assert_eq!(frappe.name.identifier(), "frappe");
/// ```
#[must_use]
pub const fn identifier(&self) -> &'static str {
match self {
Self::Latte => "latte",
Self::Frappe => "frappe",
Self::Macchiato => "macchiato",
Self::Mocha => "mocha",
}
}
}
impl FlavorColors {
/// Create an iterator over the colors in the flavor.
#[must_use]
pub const fn iter(&self) -> ColorIterator<'_> {
ColorIterator {
colors: self,
current: 0,
}
}
}
impl FlavorAnsiColors {
/// Create an iterator over the ANSI colors in the flavor.
#[must_use]
pub const fn iter(&self) -> AnsiColorIterator<'_> {
AnsiColorIterator {
ansi_colors: self,
current: 0,
}
}
/// Get the ANSI color pairs
#[must_use]
pub const fn all_pairs(&self) -> FlavorAnsiColorPairs {
self.to_ansi_color_pairs()
}
}
impl FlavorAnsiColorPairs {
/// Create an iterator over the ANSI color pairs in the flavor.
#[must_use]
pub const fn iter(&self) -> AnsiColorPairsIterator<'_> {
AnsiColorPairsIterator {
ansi_color_pairs: self,
current: 0,
}
}
}
impl<'a> Iterator for FlavorIterator<'a> {
type Item = &'a Flavor;
fn next(&mut self) -> Option<Self::Item> {
if self.current >= PALETTE.all_flavors().len() {
None
} else {
let flavor = PALETTE.all_flavors()[self.current];
self.current += 1;
Some(flavor)
}
}
}
impl<'a> Iterator for ColorIterator<'a> {
type Item = &'a Color;
fn next(&mut self) -> Option<Self::Item> {
if self.current >= self.colors.all_colors().len() {
None
} else {
let color = self.colors.all_colors()[self.current];
self.current += 1;
Some(color)
}
}
}
impl<'a> Iterator for AnsiColorIterator<'a> {
type Item = &'a AnsiColor;
fn next(&mut self) -> Option<Self::Item> {
if self.current >= self.ansi_colors.all_ansi_colors().len() {
None
} else {
let color = self.ansi_colors.all_ansi_colors()[self.current];
self.current += 1;
Some(color)
}
}
}
impl<'a> Iterator for AnsiColorPairsIterator<'a> {
type Item = &'a AnsiColorPair;
fn next(&mut self) -> Option<Self::Item> {
if self.current >= self.ansi_color_pairs.all_ansi_color_pairs().len() {
None
} else {
let color = self.ansi_color_pairs.all_ansi_color_pairs()[self.current];
self.current += 1;
Some(color)
}
}
}
impl<'a> IntoIterator for &'a Palette {
type Item = &'a Flavor;
type IntoIter = FlavorIterator<'a>;
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}
impl<'a> IntoIterator for &'a FlavorColors {
type Item = &'a Color;
type IntoIter = ColorIterator<'a>;
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}
impl<'a> IntoIterator for &'a FlavorAnsiColors {
type Item = &'a AnsiColor;
type IntoIter = AnsiColorIterator<'a>;
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}
impl<'a> IntoIterator for &'a FlavorAnsiColorPairs {
type Item = &'a AnsiColorPair;
type IntoIter = AnsiColorPairsIterator<'a>;
fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}
impl Flavor {
/// Create an iterator over the colors in the flavor.
#[must_use]
pub const fn iter(&self) -> ColorIterator<'_> {
self.colors.iter()
}
/// Equivalent to [`<flavor>.name.identifier()`](FlavorName::identifier).
#[must_use]
pub const fn identifier(&self) -> &'static str {
self.name.identifier()
}
}
impl<'a> IntoIterator for &'a Flavor {
type Item = &'a Color;
type IntoIter = ColorIterator<'a>;
fn into_iter(self) -> Self::IntoIter {
self.colors.iter()
}
}
/// Error type for parsing a [`ColorName`] from a string.
#[derive(Debug, PartialEq, Eq)]
pub struct ParseColorNameError;
impl core::error::Error for ParseColorNameError {}
impl core::fmt::Display for ParseColorNameError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "invalid color identifier")
}
}
impl Index<ColorName> for Flavor {
type Output = Color;
fn index(&self, index: ColorName) -> &Self::Output {
self.colors.index(index)
}
}
impl Flavor {
/// Get a color by name.
///
/// This is equivalent to using the index operator, but can also be used in
/// const contexts.
#[must_use]
pub const fn get_color(&self, name: ColorName) -> &Color {
self.colors.get_color(name)
}
}
impl Color {
/// Equivalent to [`<color>.name.identifier()`](ColorName::identifier).
#[must_use]
pub const fn identifier(&self) -> &'static str {
self.name.identifier()
}
}
impl From<(u8, u8, u8)> for Rgb {
fn from((r, g, b): (u8, u8, u8)) -> Self {
Self { r, g, b }
}
}
impl From<(u8, u8, u8)> for Hex {
fn from((r, g, b): (u8, u8, u8)) -> Self {
Self(Rgb { r, g, b })
}
}
impl From<(f64, f64, f64)> for Hsl {
fn from((h, s, l): (f64, f64, f64)) -> Self {
Self { h, s, l }
}
}
#[cfg(feature = "ansi-term")]
mod ansi_term {
use crate::{AnsiColor, Color};
use alloc::borrow::ToOwned;
impl Color {
/// Paints the given input with a color à la [ansi_term](https://docs.rs/ansi_term/latest/ansi_term/)
pub fn ansi_paint<'a, I, S: 'a + ToOwned + ?Sized>(
&self,
input: I,
) -> ansi_term::ANSIGenericString<'a, S>
where
I: Into<alloc::borrow::Cow<'a, S>>,
<S as ToOwned>::Owned: core::fmt::Debug,
{
ansi_term::Color::RGB(self.rgb.r, self.rgb.g, self.rgb.b).paint(input)
}
}
impl AnsiColor {
/// Paints the given input with a color à la [ansi_term](https://docs.rs/ansi_term/latest/ansi_term/)
pub fn ansi_paint<'a, I, S: 'a + ToOwned + ?Sized>(
&self,
input: I,
) -> ansi_term::ANSIGenericString<'a, S>
where
I: Into<alloc::borrow::Cow<'a, S>>,
<S as ToOwned>::Owned: core::fmt::Debug,
{
ansi_term::Color::RGB(self.rgb.r, self.rgb.g, self.rgb.b).paint(input)
}
}
}
#[cfg(feature = "bevy")]
mod bevy {
use crate::{AnsiColor, Color};
impl From<Color> for bevy::prelude::Color {
fn from(value: Color) -> Self {
#[allow(clippy::cast_possible_truncation)]
Self::hsl(value.hsl.h as f32, value.hsl.s as f32, value.hsl.l as f32)
}
}
impl From<AnsiColor> for bevy::prelude::Color {
fn from(value: AnsiColor) -> Self {
#[allow(clippy::cast_possible_truncation)]
Self::hsl(value.hsl.h as f32, value.hsl.s as f32, value.hsl.l as f32)
}
}
}
#[cfg(feature = "css-colors")]
mod css_colors {
use crate::{AnsiColor, Color};
impl From<Color> for css_colors::RGB {
fn from(value: Color) -> Self {
Self {
r: css_colors::Ratio::from_u8(value.rgb.r),
g: css_colors::Ratio::from_u8(value.rgb.g),
b: css_colors::Ratio::from_u8(value.rgb.b),
}
}
}
impl From<AnsiColor> for css_colors::RGB {
fn from(value: AnsiColor) -> Self {
Self {
r: css_colors::Ratio::from_u8(value.rgb.r),
g: css_colors::Ratio::from_u8(value.rgb.g),
b: css_colors::Ratio::from_u8(value.rgb.b),
}
}
}
impl From<Color> for css_colors::HSL {
fn from(value: Color) -> Self {
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
Self {
h: css_colors::Angle::new(value.hsl.h as u16),
s: css_colors::Ratio::from_f32(value.hsl.s as f32),
l: css_colors::Ratio::from_f32(value.hsl.l as f32),
}
}
}
impl From<AnsiColor> for css_colors::HSL {
fn from(value: AnsiColor) -> Self {
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
Self {
h: css_colors::Angle::new(value.hsl.h as u16),
s: css_colors::Ratio::from_f32(value.hsl.s as f32),
l: css_colors::Ratio::from_f32(value.hsl.l as f32),
}
}
}
}
#[cfg(feature = "iced")]
mod iced {
use crate::{AnsiColor, Color};
impl From<Color> for iced::Color {
fn from(value: Color) -> Self {
Self::from_rgb8(value.rgb.r, value.rgb.g, value.rgb.b)
}
}
impl From<Color> for iced::Background {
fn from(value: Color) -> Self {
Self::Color(value.into())
}
}
impl From<AnsiColor> for iced::Color {
fn from(value: AnsiColor) -> Self {
Self::from_rgb8(value.rgb.r, value.rgb.g, value.rgb.b)
}
}
impl From<AnsiColor> for iced::Background {
fn from(value: AnsiColor) -> Self {
Self::Color(value.into())
}
}
}
#[cfg(feature = "ratatui")]
mod ratatui {
use crate::{AnsiColor, Color};
impl From<Color> for ratatui_core::style::Color {
fn from(value: Color) -> Self {
Self::Rgb(value.rgb.r, value.rgb.g, value.rgb.b)
}
}
impl From<AnsiColor> for ratatui_core::style::Color {
fn from(value: AnsiColor) -> Self {
Self::Rgb(value.rgb.r, value.rgb.g, value.rgb.b)
}
}
}