pancurses_result/
color.rs1use general::*;
2use std::marker::PhantomData;
3
4pub struct ColorContent {
6 pub red: i16,
7 pub green: i16,
8 pub blue: i16,
9}
10impl From<(i16, i16, i16)> for ColorContent {
11 fn from(p: (i16, i16, i16)) -> Self {
12 ColorContent {
13 red: p.0,
14 green: p.1,
15 blue: p.2,
16 }
17 }
18}
19impl From<ColorContent> for (i16, i16, i16) {
20 fn from(color_content: ColorContent) -> (i16, i16, i16) {
21 (color_content.red, color_content.green, color_content.blue)
22 }
23}
24
25pub struct Color {
29 marker: PhantomData<()>,
30}
31
32impl Color {
33 pub(crate) fn new() -> Self {
34 Color {
35 marker: PhantomData,
36 }
37 }
38
39 pub fn max_colors(&self) -> i32 {
43 pancurses::COLORS()
44 }
45 pub fn color_pair<T: Into<Chtype>>(&self, n: T) -> Chtype {
49 pancurses::COLOR_PAIR(n.into())
50 }
51 pub fn color_pairs(&self) -> i32 {
55 pancurses::COLOR_PAIRS()
56 }
57 pub fn color_content(&self, color: i16) -> ColorContent {
61 pancurses::color_content(color).into()
62 }
63 pub fn can_change_color(&self) -> bool {
65 pancurses::can_change_color()
66 }
67 pub fn use_default_colors(&mut self) -> Result<(), ()> {
69 check(pancurses::use_default_colors())
70 }
71 pub fn set_color(&mut self, color: i16, color_content: ColorContent) -> Result<(), ()> {
77 check(pancurses::init_color(
78 color,
79 color_content.red,
80 color_content.green,
81 color_content.blue,
82 ))
83 }
84 pub fn set_color_pair(
88 &mut self,
89 color_pair: i16,
90 foreground: i16,
91 background: i16,
92 ) -> Result<(), ()> {
93 check(pancurses::init_pair(color_pair, foreground, background))
94 }
95}