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
use general::*;
use std::marker::PhantomData;
pub struct ColorContent {
pub red: i16,
pub green: i16,
pub blue: i16,
}
impl From<(i16, i16, i16)> for ColorContent {
fn from(p: (i16, i16, i16)) -> Self {
ColorContent {
red: p.0,
green: p.1,
blue: p.2,
}
}
}
impl From<ColorContent> for (i16, i16, i16) {
fn from(color_content: ColorContent) -> (i16, i16, i16) {
(color_content.red, color_content.green, color_content.blue)
}
}
pub struct Color {
marker: PhantomData<()>,
}
impl Color {
pub(crate) fn new() -> Self {
Color { marker: PhantomData }
}
pub fn max_colors(&self) -> i32 {
pancurses::COLORS()
}
pub fn color_pair<T: Into<Chtype>>(&self, n: T) -> Chtype {
pancurses::COLOR_PAIR(n.into())
}
pub fn color_pairs(&self) -> i32 {
pancurses::COLOR_PAIRS()
}
pub fn color_content(&self, color: i16) -> ColorContent {
pancurses::color_content(color).into()
}
pub fn can_change_color(&self) -> bool {
pancurses::can_change_color()
}
pub fn use_default_colors(&mut self) -> Result<(), ()> {
check(pancurses::use_default_colors())
}
pub fn set_color(&mut self, color: i16, color_content: ColorContent) -> Result<(), ()> {
check(pancurses::init_color(
color,
color_content.red,
color_content.green,
color_content.blue,
))
}
pub fn set_color_pair(
&mut self,
color_pair: i16,
foreground: i16,
background: i16,
) -> Result<(), ()> {
check(pancurses::init_pair(color_pair, foreground, background))
}
}